Skip to content

Commit

Permalink
Support T880X protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed May 3, 2018
1 parent 651f03b commit 2c8f3ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/org/traccar/protocol/T800xProtocolDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
* Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -116,7 +116,7 @@ protected Object decode(
buf.readUnsignedShort(); // distance compensation
buf.readUnsignedShort(); // speed alarm

int locationStatus = buf.readUnsignedByte();
int status = buf.readUnsignedByte();

buf.readUnsignedByte(); // gsensor manager status
buf.readUnsignedByte(); // other flags
Expand Down Expand Up @@ -151,9 +151,9 @@ protected Object decode(
.setMinute(BcdUtil.readInteger(buf, 2))
.setSecond(BcdUtil.readInteger(buf, 2));

if (BitUtil.check(locationStatus, 6)) {
if (BitUtil.check(status, 6)) {

position.setValid(!BitUtil.check(locationStatus, 7));
position.setValid(!BitUtil.check(status, 7));
position.setTime(dateBuilder.getDate());
position.setAltitude(readSwappedFloat(buf));
position.setLongitude(readSwappedFloat(buf));
Expand All @@ -170,14 +170,24 @@ protected Object decode(
buf.readBytes(array);
ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array);

position.setNetwork(new Network(CellTower.from(
swapped.readUnsignedShort(), swapped.readUnsignedShort(),
swapped.readUnsignedShort(), swapped.readUnsignedShort())));
int mcc = swapped.readUnsignedShort();
int mnc = swapped.readUnsignedShort();

// two more cell towers
if (mcc != 0xffff && mnc != 0xffff) {
Network network = new Network();
for (int i = 0; i < 3; i++) {
network.addCellTower(CellTower.from(
mcc, mnc, swapped.readUnsignedShort(), swapped.readUnsignedShort()));
}
position.setNetwork(network);
}

}

if (buf.readableBytes() >= 2) {
position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
}

return position;

}
Expand Down
6 changes: 6 additions & 0 deletions test/org/traccar/protocol/T800xProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public void testDecode() throws Exception {

T800xProtocolDecoder decoder = new T800xProtocolDecoder(new T800xProtocol());

verifyNull(decoder, binary(
"252501001504050880061689888888111111250350"));

verifyPosition(decoder, binary(
"252502004400010880616898888888000A00FF2001000020409600989910101010055501550000101005050005051010050558866B4276D6E342912AB441111500051010"));

verifyNull(decoder, binary(
"232301001500000880316890202968140197625020"));

Expand Down

0 comments on commit 2c8f3ec

Please sign in to comment.