diff options
Diffstat (limited to 'src/org/traccar/protocol')
4 files changed, 25 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java index 418619cb4..35aa0b469 100644 --- a/src/org/traccar/protocol/At2000Protocol.java +++ b/src/org/traccar/protocol/At2000Protocol.java @@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; import org.traccar.TrackerServer; +import java.nio.ByteOrder; import java.util.List; public class At2000Protocol extends BaseProtocol { @@ -30,13 +31,15 @@ public class At2000Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new At2000FrameDecoder()); pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this)); } - }); + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); } } diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index 17da0eef7..e9c26d406 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -50,11 +50,11 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { private static void sendResponse(Channel channel) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(BLOCK_LENGTH); + ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH); response.writeByte(MSG_ACKNOWLEDGEMENT); - response.writeMedium(1); + response.writeMedium(ChannelBuffers.swapMedium(1)); response.writeByte(0x00); // success - response.writerIndex(BLOCK_LENGTH); + response.writerIndex(2 * BLOCK_LENGTH); channel.write(response); } } diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index 5fa786e4d..6e8bc24bf 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.java @@ -61,7 +61,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { private static void sendResponseCurrent(Channel channel, int deviceId, long time) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); response.writeBytes("BB+UGRC~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(6); //binary length + response.writeShort(6); // length response.writeInt((int) time); response.writeShort(deviceId); appendChecksum(response, 16); @@ -71,7 +71,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { private static void sendResponseArchive(Channel channel, int deviceId, int packNum) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); response.writeBytes("BB+ARCF~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(4); //binary length + response.writeShort(4); // length response.writeShort(packNum); response.writeShort(deviceId); appendChecksum(response, 14); @@ -95,14 +95,19 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { int latDegrees = buf.readUnsignedByte(); int lonMinutes = buf.readUnsignedShort(); int latMinutes = buf.readUnsignedShort(); + double latitude = latDegrees + latMinutes / 60000.0; double longitude = lonDegrees + lonMinutes / 60000.0; - if (!BitUtil.check(flags, 4)) { - latitude = -latitude; - } - if (!BitUtil.check(flags, 5)) { - longitude = -longitude; + + if (position.getValid()) { + if (!BitUtil.check(flags, 4)) { + latitude = -latitude; + } + if (!BitUtil.check(flags, 5)) { + longitude = -longitude; + } } + position.setLongitude(longitude); position.setLatitude(latitude); @@ -135,11 +140,11 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(buf.readUnsignedByte() * 10); - short diOut = buf.readUnsignedByte(); + int output = buf.readUnsignedByte(); for (int i = 0; i < 8; i++) { - position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(diOut, i)); + position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(output, i)); } - buf.skipBytes(1); //StatMess + buf.readUnsignedByte(); // status message buffer } @Override diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java index 90588a628..9e6a9a82e 100644 --- a/src/org/traccar/protocol/OigoProtocolDecoder.java +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -155,7 +155,8 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { boolean negative = value < 0; value = Math.abs(value); double minutes = (value % 100000) * 0.001; - double degrees = value / 100000 + minutes / 60; + value /= 100000; + double degrees = value + minutes / 60; return negative ? -degrees : degrees; } |