diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/protocol/PstProtocolDecoder.java | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java index a7cb8ef5c..62cc203d2 100644 --- a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java @@ -16,11 +16,14 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BitUtil; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.model.Position; @@ -33,6 +36,7 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + public static final int MSG_ACK = 0x00; public static final int MSG_STATUS = 0x05; private Date readDate(ByteBuf buf) { @@ -53,23 +57,50 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { return sign * (BitUtil.from(value, 16) + BitUtil.to(value, 16) / 10000.0) / 60; } + private void sendResponse( + Channel channel, SocketAddress remoteAddress, long id, int version, long index, int type) { + if (channel != null) { + + ByteBuf content = Unpooled.buffer(); + content.writeInt((int) id); + content.writeByte(version); + content.writeInt((int) index); + content.writeByte(MSG_ACK); + content.writeByte(type); + + int checksum = Checksum.crc16(Checksum.CRC16_XMODEM, content.nioBuffer()); + + ByteBuf response = Unpooled.buffer(); + response.writeByte('('); + response.writeBytes(content); + content.release(); + response.writeShort(checksum); + response.writeByte(')'); + + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - 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; } - buf.readUnsignedByte(); // version - buf.readUnsignedInt(); // index + int version = buf.readUnsignedByte(); + long index = buf.readUnsignedInt(); int type = buf.readUnsignedByte(); + sendResponse(channel, remoteAddress, id, version, index, type); + if (type == MSG_STATUS) { Position position = new Position(getProtocolName()); |