diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-28 10:28:58 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-28 10:28:58 +1200 |
commit | 8ee694af98493830380e5faf96d43752002ca634 (patch) | |
tree | 0fd6be2954a2b9ad1976f7bba2461a86ca7c81b1 /src/org/traccar/protocol/SkypatrolProtocolDecoder.java | |
parent | ea0a523ef676310526055b1ae381387868afd738 (diff) | |
download | trackermap-server-8ee694af98493830380e5faf96d43752002ca634.tar.gz trackermap-server-8ee694af98493830380e5faf96d43752002ca634.tar.bz2 trackermap-server-8ee694af98493830380e5faf96d43752002ca634.zip |
Implement bit utility class
Diffstat (limited to 'src/org/traccar/protocol/SkypatrolProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/SkypatrolProtocolDecoder.java | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index acb4fa5ec..5521502f6 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -18,12 +18,11 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.util.Calendar; import java.util.TimeZone; - import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; - import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BitUtil; import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; @@ -34,11 +33,6 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static boolean checkBit(long mask, int bit) { - long checkMask = 1 << bit; - return (mask & checkMask) == checkMask; - } - private static double convertCoordinate(long coordinate) { int sign = 1; if (coordinate > 0x7fffffffl) { @@ -73,23 +67,23 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { if (apiNumber == 5 && commandType == 2 && messageType == 1 && - checkBit(mask, 0)) { + BitUtil.check(mask, 0)) { // Create new position Position position = new Position(); position.setProtocol(getProtocol()); // Status code - if (checkBit(mask, 1)) { + if (BitUtil.check(mask, 1)) { position.set(Event.KEY_STATUS, buf.readUnsignedInt()); } // Device id String id = null; - if (checkBit(mask, 23)) { + if (BitUtil.check(mask, 23)) { id = buf.toString(buf.readerIndex(), 8, Charset.defaultCharset()).trim(); buf.skipBytes(8); - } else if (checkBit(mask, 2)) { + } else if (BitUtil.check(mask, 2)) { id = buf.toString(buf.readerIndex(), 22, Charset.defaultCharset()).trim(); buf.skipBytes(22); } else { @@ -102,22 +96,22 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); // IO data - if (checkBit(mask, 3)) { + if (BitUtil.check(mask, 3)) { buf.readUnsignedShort(); } // ADC 1 - if (checkBit(mask, 4)) { + if (BitUtil.check(mask, 4)) { buf.readUnsignedShort(); } // ADC 2 - if (checkBit(mask, 5)) { + if (BitUtil.check(mask, 5)) { buf.readUnsignedShort(); } // Function category - if (checkBit(mask, 7)) { + if (BitUtil.check(mask, 7)) { buf.readUnsignedByte(); } @@ -125,39 +119,39 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { time.clear(); // Date - if (checkBit(mask, 8)) { + if (BitUtil.check(mask, 8)) { time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); time.set(Calendar.MONTH, buf.readUnsignedByte() - 1); time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); } // GPS status - if (checkBit(mask, 9)) { + if (BitUtil.check(mask, 9)) { position.setValid(buf.readUnsignedByte() == 1); } // Latitude - if (checkBit(mask, 10)) { + if (BitUtil.check(mask, 10)) { position.setLatitude(convertCoordinate(buf.readUnsignedInt())); } // Longitude - if (checkBit(mask, 11)) { + if (BitUtil.check(mask, 11)) { position.setLongitude(convertCoordinate(buf.readUnsignedInt())); } // Speed - if (checkBit(mask, 12)) { + if (BitUtil.check(mask, 12)) { position.setSpeed(buf.readUnsignedShort() / 10.0); } // Course - if (checkBit(mask, 13)) { + if (BitUtil.check(mask, 13)) { position.setCourse(buf.readUnsignedShort() / 10.0); } // Time - if (checkBit(mask, 14)) { + if (BitUtil.check(mask, 14)) { time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte()); time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); @@ -166,52 +160,52 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Altitude - if (checkBit(mask, 15)) { + if (BitUtil.check(mask, 15)) { position.setAltitude(buf.readMedium()); } // Satellites - if (checkBit(mask, 16)) { + if (BitUtil.check(mask, 16)) { position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); } // Battery percentage - if (checkBit(mask, 17)) { + if (BitUtil.check(mask, 17)) { buf.readUnsignedShort(); } // Trip odometer - if (checkBit(mask, 20)) { + if (BitUtil.check(mask, 20)) { position.set("trip", buf.readUnsignedInt()); } // Odometer - if (checkBit(mask, 21)) { + if (BitUtil.check(mask, 21)) { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); } // Time of message generation - if (checkBit(mask, 22)) { + if (BitUtil.check(mask, 22)) { buf.skipBytes(6); } // Battery level - if (checkBit(mask, 24)) { + if (BitUtil.check(mask, 24)) { position.set(Event.KEY_POWER, buf.readUnsignedShort() / 1000.0); } // GPS overspeed - if (checkBit(mask, 25)) { + if (BitUtil.check(mask, 25)) { buf.skipBytes(18); } // Cell information - if (checkBit(mask, 26)) { + if (BitUtil.check(mask, 26)) { buf.skipBytes(54); } // Sequence number - if (checkBit(mask, 28)) { + if (BitUtil.check(mask, 28)) { position.set(Event.KEY_INDEX, buf.readUnsignedShort()); } |