aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Pt502ProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/Pt502ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index 76e7ee1bf..e0aea693a 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -16,12 +16,13 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -35,7 +36,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
private static final int MAX_CHUNK_SIZE = 960;
- private ChannelBuffer photo;
+ private ByteBuf photo;
public Pt502ProtocolDecoder(Pt502Protocol protocol) {
super(protocol);
@@ -144,7 +145,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
int offset = photo.writerIndex();
int size = Math.min(photo.writableBytes(), MAX_CHUNK_SIZE);
- channel.write("#PHD" + offset + "," + size + "\r\n");
+ channel.writeAndFlush(new NetworkMessage("#PHD" + offset + "," + size + "\r\n", channel.remoteAddress()));
}
}
@@ -152,7 +153,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
int typeEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
String type = buf.toString(buf.readerIndex(), typeEndIndex - buf.readerIndex(), StandardCharsets.US_ASCII);
@@ -164,7 +165,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
if (photo != null) {
- photo.writeBytes(buf.readBytes(buf.readableBytes()));
+ photo.writeBytes(buf.readSlice(buf.readableBytes()));
if (photo.writableBytes() > 0) {
@@ -181,7 +182,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(uniqueId, photo, "jpg"));
-
+ photo.release();
photo = null;
return position;
@@ -195,7 +196,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
if (type.startsWith("$PHO")) {
int size = Integer.parseInt(type.split("-")[0].substring(4));
if (size > 0) {
- photo = ChannelBuffers.buffer(size);
+ photo = Unpooled.buffer(size);
requestPhotoFragment(channel);
}
}