Skip to content

Commit

Permalink
Decode general information message
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jun 12, 2021
1 parent 83c6684 commit 4f90b2f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
57 changes: 53 additions & 4 deletions src/main/java/org/traccar/protocol/UuxProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public UuxProtocolDecoder(Protocol protocol) {
super(protocol);
}

public static final int MSG_GENERAL = 0x90;
public static final int MSG_IMMOBILIZER = 0x9E;
public static final int MSG_ACK = 0xD0;
public static final int MSG_NACK = 0xF0;
Expand All @@ -51,6 +52,14 @@ private void sendResponse(Channel channel, int productCode, int protocolVersion,
}
}

private int readInt(ByteBuf buf, int length) {
return Integer.parseInt(buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
}

private double readDouble(ByteBuf buf, int length) {
return Double.parseDouble(buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
}

@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Expand All @@ -69,14 +78,54 @@ protected Object decode(
return null;
}

if (type == MSG_IMMOBILIZER) {
DateBuilder dateBuilder = new DateBuilder()
.setDate(Calendar.getInstance().get(Calendar.YEAR), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());

if (type == MSG_GENERAL) {

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

DateBuilder dateBuilder = new DateBuilder()
.setDate(Calendar.getInstance().get(Calendar.YEAR), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());

buf.skipBytes(10); // reason
buf.readUnsignedShort(); // flags

buf.readUnsignedByte(); // position status
position.setValid(true);

position.set(Position.KEY_SATELLITES, readInt(buf, 2));

double latitude = readInt(buf, 2);
latitude += readDouble(buf, 7);
position.setLatitude(buf.readUnsignedByte() == 'S' ? -latitude : latitude);

double longitude = readInt(buf, 3);
longitude += readDouble(buf, 7);
position.setLongitude(buf.readUnsignedByte() == 'W' ? -longitude : longitude);

position.setSpeed(readInt(buf, 3));
position.setCourse(readInt(buf, 3));
readInt(buf, 3); // alternative speed

position.set(Position.KEY_ODOMETER, buf.readUnsignedByte() * 10000 + buf.readUnsignedByte() * 256
+ buf.readUnsignedByte() + buf.readUnsignedByte() * 0.1);
position.set(Position.KEY_HOURS, buf.readUnsignedInt());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());

position.set("companyId", buf.readCharSequence(6, StandardCharsets.US_ASCII).toString());

buf.skipBytes(10); // reason data

position.set("tripId", buf.readUnsignedShort());

return position;

} else if (type == MSG_IMMOBILIZER) {

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

getLastLocation(position, dateBuilder.getDate());

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 = new UuxProtocolDecoder(null);

verifyAttributes(decoder, binary(
"81910c5a9031395533443630363631051e061a1e07397079712a000000000000413133333135332e333939304e30333531322e393837324530303031303030303000000200000000001f303036323236303030303030303030300000ffff"));

verifyAttributes(decoder, binary(
"81918c2d9e31395533443630363631041c0c16043030313030300007000000000000000000000000000000000000000000"));

Expand Down

0 comments on commit 4f90b2f

Please sign in to comment.