Skip to content

Commit

Permalink
Support Continental extended precision
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jul 10, 2018
1 parent 5603d7b commit 9d26d56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/org/traccar/protocol/ContinentalProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public ContinentalProtocolDecoder(ContinentalProtocol protocol) {
public static final int MSG_ACK = 0x06;
public static final int MSG_NACK = 0x15;

private double readCoordinate(ByteBuf buf, boolean extended) {
long value = buf.readUnsignedInt();
if (extended ? (value & 0x08000000) != 0 : (value & 0x00800000) != 0) {
value |= extended ? 0xF0000000 : 0xFF000000;
}
return (int) value / (extended ? 360000.0 : 3600.0);
}

@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Expand Down Expand Up @@ -64,11 +72,9 @@ protected Object decode(

position.setFixTime(new Date(buf.readUnsignedInt() * 1000L));

buf.readUnsignedByte();
position.setLatitude(buf.readMedium() / 3600.0);

buf.readUnsignedByte();
position.setLongitude(buf.readMedium() / 3600.0);
boolean extended = buf.getUnsignedByte(buf.readerIndex()) != 0;
position.setLatitude(readCoordinate(buf, extended));
position.setLongitude(readCoordinate(buf, extended));

position.setCourse(buf.readUnsignedShort());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
Expand Down
4 changes: 4 additions & 0 deletions test/org/traccar/protocol/ContinentalProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public void testDecode() throws Exception {

ContinentalProtocolDecoder decoder = new ContinentalProtocolDecoder(new ContinentalProtocol());

verifyPosition(decoder, binary(
"5356003216001eb48505025b4001e90f7f18ce0f00522200400001015b4001e9000e820100000c24000100014e0400736a7a"),
position("2018-07-06 23:57:29.000", true, -23.46609, -46.54497));

verifyPosition(decoder, binary(
"5356002A1100003039030243A68B5700FEB5AB00FD715F012700000143A68B57000E000000000C2F00000130"),
position("2005-12-19 10:28:39.000", true, -23.49027, -46.55138));
Expand Down

0 comments on commit 9d26d56

Please sign in to comment.