diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-05 15:05:52 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-05 15:05:52 +1300 |
commit | 4e37ce80b615e126f82e567d06a60beff8c82fb0 (patch) | |
tree | b8446c071fc18fd53e8c4a04b38a3b36b837b6a9 /src/org | |
parent | 0f6a2399433c65b3b03c1f660e148cd1dd1436a7 (diff) | |
download | traccar-server-4e37ce80b615e126f82e567d06a60beff8c82fb0.tar.gz traccar-server-4e37ce80b615e126f82e567d06a60beff8c82fb0.tar.bz2 traccar-server-4e37ce80b615e126f82e567d06a60beff8c82fb0.zip |
Implement MXT response (fix #2847)
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/MxtProtocolDecoder.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index c03305c1a..c9eba5bed 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 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. @@ -16,10 +16,12 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -36,6 +38,21 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_NACK = 0x03; public static final int MSG_POSITION = 0x31; + private static void sendResponse(Channel channel, int device, long id, int crc) { + if (channel != null) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(0x01); // header + response.writeByte(device); + response.writeByte(MSG_ACK); + response.writeInt((int) id); + response.writeShort(crc); + response.writeShort(Checksum.crc16( + Checksum.CRC16_CCITT_FALSE, response.toByteBuffer(0, response.readableBytes()))); + response.writeByte(0x04); // ending + channel.write(response); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -43,11 +60,11 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; buf.readUnsignedByte(); // start - buf.readUnsignedByte(); // device descriptor + int device = buf.readUnsignedByte(); // device descriptor int type = buf.readUnsignedByte(); - String id = String.valueOf(buf.readUnsignedInt()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + long id = buf.readUnsignedInt(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id)); if (deviceSession == null) { return null; } @@ -134,6 +151,9 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RFID, buf.readUnsignedInt()); } + buf.readerIndex(buf.writerIndex() - 3); + sendResponse(channel, device, id, buf.readUnsignedShort()); + return position; } |