diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-19 23:12:50 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-19 23:12:50 +1300 |
commit | 57a7b6beaade9a51690d0cc89149eca0dea8294a (patch) | |
tree | 341d468c1c0ec30fc6206cc382f67f2cf6a185c9 /src/org/traccar | |
parent | 289609b483d0b6188f8536f692363eb91e38288c (diff) | |
download | traccar-server-57a7b6beaade9a51690d0cc89149eca0dea8294a.tar.gz traccar-server-57a7b6beaade9a51690d0cc89149eca0dea8294a.tar.bz2 traccar-server-57a7b6beaade9a51690d0cc89149eca0dea8294a.zip |
Fix Noran decoder (fix #610)
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/ServerManager.java | 6 | ||||
-rw-r--r-- | src/org/traccar/TrackerServer.java | 11 | ||||
-rw-r--r-- | src/org/traccar/protocol/NoranProtocolDecoder.java | 31 |
3 files changed, 26 insertions, 22 deletions
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index 7505561e9..4e5b283d4 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -974,12 +974,14 @@ public class ServerManager { private void initNoranServer(String protocol) throws SQLException { if (isProtocolEnabled(properties, protocol)) { - serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) { + TrackerServer server = new TrackerServer(this, new ConnectionlessBootstrap(), protocol) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new NoranProtocolDecoder(ServerManager.this)); } - }); + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); } } diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index 1b3677836..9fcc2f5b6 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,9 @@ import org.jboss.netty.channel.group.DefaultChannelGroup; */ public abstract class TrackerServer { - private ServerManager serverManager; - private Bootstrap bootstrap; - private String protocol; + private final ServerManager serverManager; + private final Bootstrap bootstrap; + private final String protocol; public String getProtocol() { return protocol; @@ -97,13 +97,14 @@ public abstract class TrackerServer { * Set endianness */ void setEndianness(ByteOrder byteOrder) { + bootstrap.setOption("bufferFactory", new HeapChannelBufferFactory(byteOrder)); bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder)); } /** * Opened channels */ - private ChannelGroup allChannels = new DefaultChannelGroup(); + private final ChannelGroup allChannels = new DefaultChannelGroup(); public ChannelGroup getChannelGroup() { return allChannels; diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 372312610..7fecf18e1 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,12 @@ */ package org.traccar.protocol; +import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.Calendar; import java.util.TimeZone; 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.traccar.BaseProtocolDecoder; @@ -33,22 +35,11 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - private String readImei(ChannelBuffer buf) { - int b = buf.readUnsignedByte(); - StringBuilder imei = new StringBuilder(); - imei.append(b & 0x0F); - for (int i = 0; i < 7; i++) { - b = buf.readUnsignedByte(); - imei.append((b & 0xF0) >> 4); - imei.append(b & 0x0F); - } - return imei.toString(); - } - private static final int MSG_UPLOAD_POSITION = 0x0008; private static final int MSG_CONTROL_RESPONSE = 0x8009; private static final int MSG_ALARM = 0x0003; private static final int MSG_SHAKE_HAND = 0x0000; + private static final int MSG_SHAKE_HAND_RESPONSE = 0x8000; private static final int MSG_IMAGE_SIZE = 0x0200; private static final int MSG_IMAGE_PACKET = 0x0201; @@ -62,8 +53,17 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // length int type = buf.readUnsignedShort(); - if (type == MSG_SHAKE_HAND) { - // TODO send response + if (type == MSG_SHAKE_HAND && channel != null) { + + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13); + response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", Charset.defaultCharset())); + response.writeByte(0); + response.writeShort(response.capacity()); + response.writeShort(MSG_SHAKE_HAND_RESPONSE); + response.writeByte(1); // status + response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset())); + + channel.write(response); } else if (type == MSG_UPLOAD_POSITION || @@ -91,6 +91,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { position.setCourse((double) buf.readUnsignedShort()); position.setLongitude((double) buf.readFloat()); position.setLatitude((double) buf.readFloat()); + position.setAltitude(0.0); // Time long timeValue = buf.readUnsignedInt(); |