diff options
author | Ivan Muratov <binakot@gmail.com> | 2017-07-17 14:00:46 +0300 |
---|---|---|
committer | Ivan Muratov <binakot@gmail.com> | 2017-07-17 14:00:46 +0300 |
commit | 31e972e169acf4a517ff10f8a64f0e0cf0b8df0e (patch) | |
tree | 45361febcec29fe6c08a4c3907b35f705cad26d6 /src | |
parent | 79147b8a6fc8a3bfe863c2e8d3c47db06af90bc8 (diff) | |
download | trackermap-server-31e972e169acf4a517ff10f8a64f0e0cf0b8df0e.tar.gz trackermap-server-31e972e169acf4a517ff10f8a64f0e0cf0b8df0e.tar.bz2 trackermap-server-31e972e169acf4a517ff10f8a64f0e0cf0b8df0e.zip |
Refactoring of the ARNAVI4 protocol decoder.
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/Arnavi4ProtocolDecoder.java | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java index a1a9d2ea1..4ab929cf7 100644 --- a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java +++ b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java @@ -50,34 +50,31 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private void sendHeaderResponse(Channel channel, byte version) { + private void sendResponse(Channel channel, byte version, int index) { if (channel != null) { final ChannelBuffer response; if (version == HEADER_VERSION_1) { response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 4); - response.writeBytes(new byte[]{0x7B, 0x00, 0x00, 0x7D}); + response.writeByte(0x7b); + response.writeByte(0x00); + response.writeByte((byte) index); + response.writeByte(0x7d); } else if (version == HEADER_VERSION_2) { response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 9); - response.writeBytes(new byte[]{0x7B, 0x04, 0x00}); + response.writeByte(0x7b); + response.writeByte(0x04); + response.writeByte(0x00); byte[] timeBytes = ByteBuffer.allocate(4).putInt((int) (System.currentTimeMillis() / 1000)).array(); response.writeByte(Checksum.modulo256(timeBytes)); response.writeBytes(timeBytes); - response.writeByte(0x7D); + response.writeByte(0x7d); } else { - return; // Ignore unsupported versions of header + return; // Ignore unsupported header's versions } channel.write(response); } } - - private void sendPackageResponse(Channel channel, int index) { - if (channel != null) { - final ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 4); - response.writeBytes(new byte[]{0x7B, 0x00, (byte) index, 0x7D}); - channel.write(response); - } - } - + private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, int length, Date time) { final Position position = new Position(); @@ -135,7 +132,7 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null) { - sendHeaderResponse(channel, version); + sendResponse(channel, version, 0); } return null; @@ -164,20 +161,20 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder { if (recordType == RECORD_DATA) { positions.add(decodePosition(deviceSession, buf, length, time)); } else { - buf.readBytes(length); // Skip other records + buf.readBytes(length); // Skip other types of record } buf.readUnsignedByte(); // crc break; default: - return null; // Ignore unsupported types of package + return null; // Ignore unsupported types of record } - recordType = buf.readByte(); // The last byte in package is end sign + recordType = buf.readByte(); } - sendPackageResponse(channel, index); + sendResponse(channel, HEADER_VERSION_1, index); return positions; } |