diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-27 11:21:27 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-27 11:21:27 +1200 |
commit | 44f026f881efa6207ab79fb5bada20ab67f018a0 (patch) | |
tree | 62cab9dc7d35c12bf75217eecf85b335ecebbe5a /src/org | |
parent | aa0cbaa6e849d01a5bb02e2e999b80c178270014 (diff) | |
download | traccar-server-44f026f881efa6207ab79fb5bada20ab67f018a0.tar.gz traccar-server-44f026f881efa6207ab79fb5bada20ab67f018a0.tar.bz2 traccar-server-44f026f881efa6207ab79fb5bada20ab67f018a0.zip |
Rename ChannelBufferTools to BcdUtil
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/helper/BcdUtil.java (renamed from src/org/traccar/helper/ChannelBufferTools.java) | 19 | ||||
-rw-r--r-- | src/org/traccar/protocol/GatorProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/HuabaoProtocolDecoder.java | 14 | ||||
-rw-r--r-- | src/org/traccar/protocol/Jt600ProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/KhdProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/T800xProtocolDecoder.java | 18 |
7 files changed, 66 insertions, 73 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/BcdUtil.java index ad2369bed..a248daf22 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/BcdUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 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. @@ -17,19 +17,15 @@ package org.traccar.helper; import org.jboss.netty.buffer.ChannelBuffer; -public final class ChannelBufferTools { +public final class BcdUtil { - private ChannelBufferTools() { + private BcdUtil() { } - /** - * Convert hex to integer (length in hex digits) - */ - public static int readHexInteger(ChannelBuffer buf, int length) { - + public static int readInteger(ChannelBuffer buf, int digits) { int result = 0; - for (int i = 0; i < length / 2; i++) { + for (int i = 0; i < digits / 2; i++) { int b = buf.readUnsignedByte(); result *= 10; result += b >>> 4; @@ -37,7 +33,7 @@ public final class ChannelBufferTools { result += b & 0x0f; } - if (length % 2 != 0) { + if (digits % 2 != 0) { int b = buf.getUnsignedByte(buf.readerIndex()); result *= 10; result += b >>> 4; @@ -46,9 +42,6 @@ public final class ChannelBufferTools { return result; } - /** - * Read BCD coded coordinate (first byte has sign bit) - */ public static double readCoordinate(ChannelBuffer buf) { int b1 = buf.readUnsignedByte(); int b2 = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java index 22b3ebc3a..e28da82ba 100644 --- a/src/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/org/traccar/protocol/GatorProtocolDecoder.java @@ -19,7 +19,7 @@ import java.net.SocketAddress; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.BcdUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; @@ -80,18 +80,18 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setYear(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); - position.setLatitude(ChannelBufferTools.readCoordinate(buf)); - position.setLongitude(ChannelBufferTools.readCoordinate(buf)); - position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4))); - position.setCourse(ChannelBufferTools.readHexInteger(buf, 4)); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); int flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) != 0); diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index c4ba6ffa3..b316d8016 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -22,8 +22,8 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BcdUtil; import org.traccar.helper.BitUtil; -import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -38,7 +38,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private static double readCoordinate(ChannelBuffer buf, boolean lon) { - int degrees = ChannelBufferTools.readHexInteger(buf, 2); + int degrees = BcdUtil.readInteger(buf, 2); if (lon) { degrees = degrees * 10 + (buf.getUnsignedByte(buf.readerIndex()) >> 4); } @@ -53,7 +53,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { length = 5; } - result = result * 10 + ChannelBufferTools.readHexInteger(buf, length) * 0.0001; + result = result * 10 + BcdUtil.readInteger(buf, length) * 0.0001; result /= 60; result += degrees; @@ -83,12 +83,12 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)) - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setYear(ChannelBufferTools.readHexInteger(buf, 2)); + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setYear(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); double latitude = readCoordinate(buf, false); @@ -107,8 +107,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(latitude); position.setLongitude(longitude); - position.setSpeed(ChannelBufferTools.readHexInteger(buf, 3)); - position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + ChannelBufferTools.readHexInteger(buf, 2)); + position.setSpeed(BcdUtil.readInteger(buf, 3)); + position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + BcdUtil.readInteger(buf, 2)); processStatus(position, buf.readUnsignedInt()); return position; diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index a9a4741fc..6ed490c1a 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -19,8 +19,8 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BcdUtil; import org.traccar.helper.BitUtil; -import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; @@ -132,12 +132,12 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.setCourse(buf.readUnsignedShort()); DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8")) - .setYear(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); // additional information diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 7c6ab8a4d..3cd6aedb7 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -22,7 +22,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.BcdUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -55,21 +55,21 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(getDeviceId()); - int version = ChannelBufferTools.readHexInteger(buf, 1); + int version = BcdUtil.readInteger(buf, 1); buf.readUnsignedByte(); // type buf.readBytes(2); // length DateBuilder dateBuilder = new DateBuilder() - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setYear(ChannelBufferTools.readHexInteger(buf, 2)) - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + .setDay(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setYear(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); - double latitude = convertCoordinate(ChannelBufferTools.readHexInteger(buf, 8)); - double longitude = convertCoordinate(ChannelBufferTools.readHexInteger(buf, 9)); + double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8)); + double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9)); byte flags = buf.readByte(); position.setValid((flags & 0x1) == 0x1); @@ -82,7 +82,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { } position.setLongitude(longitude); - position.setSpeed(ChannelBufferTools.readHexInteger(buf, 2)); + position.setSpeed(BcdUtil.readInteger(buf, 2)); position.setCourse(buf.readUnsignedByte() * 2.0); if (version == 1) { diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java index c1ebb1bf4..07db78c94 100644 --- a/src/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/org/traccar/protocol/KhdProtocolDecoder.java @@ -20,7 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.BcdUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; @@ -79,18 +79,18 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setYear(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); - position.setLatitude(ChannelBufferTools.readCoordinate(buf)); - position.setLongitude(ChannelBufferTools.readCoordinate(buf)); - position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4))); - position.setCourse(ChannelBufferTools.readHexInteger(buf, 4)); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); int flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) != 0); diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java index 83d815e0f..c5dc103b1 100644 --- a/src/org/traccar/protocol/T800xProtocolDecoder.java +++ b/src/org/traccar/protocol/T800xProtocolDecoder.java @@ -19,8 +19,8 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BcdUtil; import org.traccar.helper.BitUtil; -import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; @@ -114,19 +114,19 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); - int battery = ChannelBufferTools.readHexInteger(buf, 2); + int battery = BcdUtil.readInteger(buf, 2); if (battery == 0) { battery = 100; } position.set(Event.KEY_BATTERY, battery); DateBuilder dateBuilder = new DateBuilder() - .setYear(ChannelBufferTools.readHexInteger(buf, 2)) - .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) - .setDay(ChannelBufferTools.readHexInteger(buf, 2)) - .setHour(ChannelBufferTools.readHexInteger(buf, 2)) - .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) - .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); if (BitUtil.check(locationStatus, 6)) { @@ -136,7 +136,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(readSwappedFloat(buf)); position.setLatitude(readSwappedFloat(buf)); position.setSpeed(UnitsConverter.knotsFromKph( - ChannelBufferTools.readHexInteger(buf, 4) * 0.1)); + BcdUtil.readInteger(buf, 4) * 0.1)); position.setCourse(buf.readUnsignedShort()); } else { |