diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-06 16:51:47 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-06 16:51:47 +1200 |
commit | 562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e (patch) | |
tree | 44fa438ebc6be56ede7307b18a2116fff14d8cc8 /src/org/traccar/protocol/CellocatorProtocolDecoder.java | |
parent | 9c99076dc2416c4e0725007af0e5f2f2f444c05c (diff) | |
download | trackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.tar.gz trackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.tar.bz2 trackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.zip |
Migrate more protocols
Diffstat (limited to 'src/org/traccar/protocol/CellocatorProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/CellocatorProtocolDecoder.java | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index 67db9aa7d..426b6bf3b 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 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,17 +15,17 @@ */ 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.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; public class CellocatorProtocolDecoder extends BaseProtocolDecoder { @@ -44,15 +44,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { private byte commandCount; private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) { - ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28); + ByteBuf reply = Unpooled.buffer(28); reply.writeByte('M'); reply.writeByte('C'); reply.writeByte('G'); reply.writeByte('P'); reply.writeByte(MSG_SERVER_ACKNOWLEDGE); - reply.writeInt((int) deviceId); + reply.writeIntLE((int) deviceId); reply.writeByte(commandCount++); - reply.writeInt(0); // authentication code + reply.writeIntLE(0); // authentication code reply.writeByte(0); reply.writeByte(packetNumber); reply.writeZero(11); @@ -64,7 +64,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { reply.writeByte(checksum); if (channel != null) { - channel.write(reply, remoteAddress); + channel.write(new NetworkMessage(reply, remoteAddress)); } } @@ -85,14 +85,14 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(4); // system code int type = buf.readUnsignedByte(); - long deviceUniqueId = buf.readUnsignedInt(); + long deviceUniqueId = buf.readUnsignedIntLE(); if (type != MSG_CLIENT_SERIAL) { - buf.readUnsignedShort(); // communication control + buf.readUnsignedShortLE(); // communication control } byte packetNumber = buf.readByte(); @@ -121,17 +121,17 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); position.set("mode", buf.readUnsignedByte()); - position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt()); + position.set(Position.PREFIX_IO + 1, buf.readUnsignedIntLE()); operator <<= 8; operator += buf.readUnsignedByte(); position.set(Position.KEY_OPERATOR, operator); - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedIntLE()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedMediumLE()); buf.skipBytes(6); // multi-purpose data - position.set(Position.KEY_GPS, buf.readUnsignedShort()); + position.set(Position.KEY_GPS, buf.readUnsignedShortLE()); position.set("locationStatus", buf.readUnsignedByte()); position.set("mode1", buf.readUnsignedByte()); position.set("mode2", buf.readUnsignedByte()); @@ -139,15 +139,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setValid(true); - position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000); - position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0); - position.setAltitude(buf.readInt() * 0.01); - position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01)); - position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0); + position.setLongitude(buf.readIntLE() / Math.PI * 180 / 100000000); + position.setLatitude(buf.readIntLE() / Math.PI * 180 / 100000000.0); + position.setAltitude(buf.readIntLE() * 0.01); + position.setSpeed(UnitsConverter.knotsFromMps(buf.readIntLE() * 0.01)); + position.setCourse(buf.readUnsignedShortLE() / Math.PI * 180.0 / 1000.0); DateBuilder dateBuilder = new DateBuilder() .setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) - .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort()); + .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShortLE()); position.setTime(dateBuilder.getDate()); return position; |