diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/helper/BitUtil.java | 2 | ||||
-rw-r--r-- | src/org/traccar/helper/Checksum.java | 6 | ||||
-rw-r--r-- | src/org/traccar/protocol/IntellitracFrameDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/NavigilProtocolDecoder.java | 9 | ||||
-rw-r--r-- | src/org/traccar/protocol/NavisProtocolDecoder.java | 14 | ||||
-rw-r--r-- | src/org/traccar/protocol/SkypatrolProtocolDecoder.java | 4 | ||||
-rw-r--r-- | src/org/traccar/protocol/TytanProtocolDecoder.java | 187 | ||||
-rw-r--r-- | src/org/traccar/protocol/UlbotechProtocolDecoder.java | 4 |
8 files changed, 117 insertions, 111 deletions
diff --git a/src/org/traccar/helper/BitUtil.java b/src/org/traccar/helper/BitUtil.java index 6dceb52d7..e13df8f7e 100644 --- a/src/org/traccar/helper/BitUtil.java +++ b/src/org/traccar/helper/BitUtil.java @@ -37,7 +37,7 @@ public class BitUtil { } public static long range(long number, int index, int length) { - return (number >> index) & ((1l << length) - 1); + return (number >> index) & ((1L << length) - 1); } } diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java index 5ff87c7dd..6801e81d6 100644 --- a/src/org/traccar/helper/Checksum.java +++ b/src/org/traccar/helper/Checksum.java @@ -21,7 +21,7 @@ import java.util.zip.CRC32; public class Checksum { - private static final int CRC16_CCITT_TABLE_REVERSE[] = { + private static final int[] CRC16_CCITT_TABLE_REVERSE = { 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, @@ -56,7 +56,7 @@ public class Checksum { 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 }; - private static final int CRC16_CCITT_TABLE[] = { + private static final int[] CRC16_CCITT_TABLE = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, @@ -154,7 +154,7 @@ public class Checksum { public static String nmea(String msg) { int checksum = 0; - byte bytes[] = msg.getBytes(Charset.defaultCharset()); + byte[] bytes = msg.getBytes(Charset.defaultCharset()); for (int i = 1; i < msg.length(); i++) { checksum ^= bytes[i]; } diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java index 43a102f09..7c981a81b 100644 --- a/src/org/traccar/protocol/IntellitracFrameDecoder.java +++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java @@ -25,7 +25,7 @@ public class IntellitracFrameDecoder extends DelimiterBasedFrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 0; - private static final byte delimiter[] = {(byte) '\r', (byte) '\n'}; + private static final byte[] delimiter = {(byte) '\r', (byte) '\n'}; public IntellitracFrameDecoder(int maxFrameLength) { super(maxFrameLength, ChannelBuffers.wrappedBuffer(delimiter)); diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index b8d5910f5..5ce5d08cb 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -23,6 +23,7 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.Checksum; +import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; import org.traccar.model.Position; @@ -52,7 +53,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_ACKNOWLEDGEMENT = 255; private static Date convertTimestamp(long timestamp) { - return new Date((timestamp - LEAP_SECONDS_DELTA) * 1000l); + return new Date((timestamp - LEAP_SECONDS_DELTA) * 1000); } private int senderSequenceNumber = 1; @@ -108,7 +109,6 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setTime(convertTimestamp(buf.readUnsignedInt())); - // TODO: a lot of other stuff return position; } @@ -145,7 +145,6 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // solar voltage position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - // TODO: a lot of other stuff return position; } @@ -228,7 +227,6 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // supply voltage 2 position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - // TODO: a lot of other stuff return position; } @@ -302,6 +300,9 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { return parseSnapshot4(buf, sequenceNumber); case MSG_TRACKING_DATA: return parseTrackingData(buf, sequenceNumber, timestamp); + default: + Log.warning(new UnsupportedOperationException(String.valueOf(messageId))); + break; } return null; diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index a4b900f96..39912e420 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -34,7 +34,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private String prefix; private long deviceUniqueId, serverId; - private static final Charset charset = Charset.defaultCharset(); + private static final Charset CHARSET = Charset.defaultCharset(); public NavisProtocolDecoder(NavisProtocol protocol) { super(protocol); @@ -212,7 +212,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { ParseResult result = parsePosition(buf); ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8); - response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", charset)); + response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", CHARSET)); response.writeInt((int) result.getId()); sendReply(channel, response); @@ -236,7 +236,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { } ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8); - response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", charset)); + response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", CHARSET)); response.writeByte(count); sendReply(channel, response); @@ -251,7 +251,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private Object processHandshake(Channel channel, ChannelBuffer buf) { buf.readByte(); // semicolon symbol if (identify(buf.toString(Charset.defaultCharset()), channel)) { - sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", charset)); + sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", CHARSET)); } return null; } @@ -266,7 +266,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private void sendReply(Channel channel, ChannelBuffer data) { ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16); - header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, charset)); + header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, CHARSET)); header.writeInt((int) deviceUniqueId); header.writeInt((int) serverId); header.writeShort(data.readableBytes()); @@ -286,7 +286,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; // Read header - prefix = buf.toString(buf.readerIndex(), 4, charset); + prefix = buf.toString(buf.readerIndex(), 4, CHARSET); buf.skipBytes(prefix.length()); // prefix @NTC by default serverId = buf.readUnsignedInt(); deviceUniqueId = buf.readUnsignedInt(); @@ -298,7 +298,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { } // Read message type - String type = buf.toString(buf.readerIndex(), 3, charset); + String type = buf.toString(buf.readerIndex(), 3, CHARSET); buf.skipBytes(type.length()); switch (type) { diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 9d5b499cc..dfbdca930 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -39,9 +39,9 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { private static double convertCoordinate(long coordinate) { int sign = 1; - if (coordinate > 0x7fffffffl) { + if (coordinate > 0x7fffffffL) { sign = -1; - coordinate = 0xffffffffl - coordinate; + coordinate = 0xffffffffL - coordinate; } long degrees = coordinate / 1000000; diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index d1fdd99d0..83b165ebf 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -23,6 +23,8 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; + +import javafx.geometry.Pos; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; @@ -45,10 +47,101 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readFloat(); } + private void decodeExtraData(Position position, ChannelBuffer buf, int end) { + while (buf.readerIndex() < end) { + + int type = buf.readUnsignedByte(); + int length = buf.readUnsignedByte(); + if (length == 255) { + length += buf.readUnsignedByte(); + } + + int n; + + switch (type) { + case 2: + position.set(Event.KEY_ODOMETER, buf.readUnsignedMedium()); + break; + case 5: + position.set(Event.KEY_INPUT, buf.readUnsignedByte()); + break; + case 6: + n = buf.readUnsignedByte() >> 4; + if (n < 2) { + position.set(Event.PREFIX_ADC + n, readSwappedFloat(buf)); + } else { + position.set("di" + (n - 2), readSwappedFloat(buf)); + } + break; + case 7: + int alarm = buf.readUnsignedByte(); + buf.readUnsignedByte(); + if (BitUtil.check(alarm, 5)) { + position.set(Event.KEY_ALARM, BitUtil.range(alarm, 0, 4)); + } + break; + case 8: + position.set("antihijack", buf.readUnsignedByte()); + break; + case 9: + position.set("authorized", ChannelBufferTools.readHexString(buf, 16)); + break; + case 10: + position.set("unauthorized", ChannelBufferTools.readHexString(buf, 16)); + break; + case 24: + Set<Integer> temps = new LinkedHashSet<>(); + int temp = buf.readUnsignedByte(); + for (int i = 3; i >= 0; i--) { + n = (temp >> (2 * i)) & 0x03; + if (!temps.contains(n)) { + temps.add(n); + } + } + for (int i : temps) { + position.set(Event.PREFIX_TEMP + i, buf.readUnsignedByte()); + } + break; + case 28: + position.set("weight", buf.readUnsignedShort()); + buf.readUnsignedByte(); + break; + case 90: + position.set(Event.KEY_POWER, readSwappedFloat(buf)); + break; + case 101: + position.set(Event.KEY_OBD_SPEED, buf.readUnsignedByte()); + break; + case 102: + position.set(Event.KEY_RPM, buf.readUnsignedByte() * 50); + break; + case 107: + int fuel = buf.readUnsignedShort(); + int fuelFormat = fuel >> 14; + if (fuelFormat == 1) { + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.4 + "%"); + } else if (fuelFormat == 2) { + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.5 + " l"); + } else if (fuelFormat == 3) { + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * -0.5 + " l"); + } + break; + case 108: + position.set(Event.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); + break; + case 150: + position.set("door", buf.readUnsignedByte()); + break; + default: + buf.skipBytes(length); + break; + } + } + } + @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; @@ -105,95 +198,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(speed)); } - while (buf.readerIndex() < end) { - - int type = buf.readUnsignedByte(); - int length = buf.readUnsignedByte(); - if (length == 255) { - length += buf.readUnsignedByte(); - } - - int n = 0; - - switch (type) { - case 2: - position.set(Event.KEY_ODOMETER, buf.readUnsignedMedium()); - break; - case 5: - position.set(Event.KEY_INPUT, buf.readUnsignedByte()); - break; - case 6: - n = buf.readUnsignedByte() >> 4; - if (n < 2) { - position.set(Event.PREFIX_ADC + n, readSwappedFloat(buf)); - } else { - position.set("di" + (n - 2), readSwappedFloat(buf)); - } - break; - case 7: - int alarm = buf.readUnsignedByte(); - buf.readUnsignedByte(); - if (BitUtil.check(alarm, 5)) { - position.set(Event.KEY_ALARM, BitUtil.range(alarm, 0, 4)); - } - break; - case 8: - position.set("antihijack", buf.readUnsignedByte()); - break; - case 9: - position.set("authorized", ChannelBufferTools.readHexString(buf, 16)); - break; - case 10: - position.set("unauthorized", ChannelBufferTools.readHexString(buf, 16)); - break; - case 24: - Set<Integer> temps = new LinkedHashSet<>(); - int temp = buf.readUnsignedByte(); - for (int i = 3; i >= 0; i--) { - n = (temp >> (2 * i)) & 0x03; - if (!temps.contains(n)) { - temps.add(n); - } - } - for (int i : temps) { - position.set(Event.PREFIX_TEMP + i, buf.readUnsignedByte()); - } - break; - case 28: - position.set("weight", buf.readUnsignedShort()); - buf.readUnsignedByte(); - break; - case 90: - position.set(Event.KEY_POWER, readSwappedFloat(buf)); - break; - case 101: - position.set(Event.KEY_OBD_SPEED, buf.readUnsignedByte()); - break; - case 102: - position.set(Event.KEY_RPM, buf.readUnsignedByte() * 50); - break; - case 107: - int fuel = buf.readUnsignedShort(); - int fuelFormat = fuel >> 14; - if (fuelFormat == 1) { - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.4 + "%"); - } else if (fuelFormat == 2) { - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.5 + " l"); - } else if (fuelFormat == 3) { - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * -0.5 + " l"); - } - break; - case 108: - position.set(Event.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); - break; - case 150: - position.set("door", buf.readUnsignedByte()); - break; - default: - buf.skipBytes(length); - break; - } - } + decodeExtraData(position, buf, end); positions.add(position); } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 6c332102d..a33077e5f 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -77,8 +77,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); // Time - long seconds = buf.readUnsignedInt() & 0x7fffffffl; - seconds += 946684800l; // 2000-01-01 00:00 + long seconds = buf.readUnsignedInt() & 0x7fffffffL; + seconds += 946684800L; // 2000-01-01 00:00 seconds -= timeZone; position.setTime(new Date(seconds * 1000)); |