From 9c99076dc2416c4e0725007af0e5f2f2f444c05c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 5 Jun 2018 23:16:21 +1200 Subject: Migrate more protocols --- src/org/traccar/protocol/At2000FrameDecoder.java | 31 ++++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/org/traccar/protocol/At2000FrameDecoder.java') diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java index af257d0fb..9d5524ec1 100644 --- a/src/org/traccar/protocol/At2000FrameDecoder.java +++ b/src/org/traccar/protocol/At2000FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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. @@ -15,38 +15,37 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; +import org.traccar.NetworkMessage; -import java.nio.ByteOrder; - -public class At2000FrameDecoder extends FrameDecoder { +public class At2000FrameDecoder extends BaseFrameDecoder { private static final int BLOCK_LENGTH = 16; private static final int ACK_LENGTH = 496; private boolean firstPacket = true; - private ChannelBuffer currentBuffer; + private ByteBuf currentBuffer; private int acknowledgedBytes; private void sendResponse(Channel channel) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH); + ByteBuf response = Unpooled.buffer(2 * BLOCK_LENGTH); response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT); - response.writeMedium(ChannelBuffers.swapMedium(1)); + response.writeMedium(1); response.writeByte(0x00); // success response.writerIndex(2 * BLOCK_LENGTH); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } } @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 5) { return null; @@ -55,9 +54,9 @@ public class At2000FrameDecoder extends FrameDecoder { int length; if (firstPacket) { firstPacket = false; - length = buf.getUnsignedMedium(buf.readerIndex() + 2); + length = buf.getUnsignedMediumLE(buf.readerIndex() + 2); } else { - length = buf.getUnsignedMedium(buf.readerIndex() + 1); + length = buf.getUnsignedMediumLE(buf.readerIndex() + 1); } length += BLOCK_LENGTH; -- cgit v1.2.3