diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-21 20:53:20 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-21 20:53:20 +1300 |
commit | 122a26d2822f35b27b9cb0b217916d6b821d9654 (patch) | |
tree | 3f9d9240e7e8a078b0b116bbdf33205c62ef84a9 /src/org/traccar/protocol/SkypatrolProtocolDecoder.java | |
parent | 6fc48063460a673815b182e0a8f3adf4db0fd08a (diff) | |
download | trackermap-server-122a26d2822f35b27b9cb0b217916d6b821d9654.tar.gz trackermap-server-122a26d2822f35b27b9cb0b217916d6b821d9654.tar.bz2 trackermap-server-122a26d2822f35b27b9cb0b217916d6b821d9654.zip |
Refactor TK102 and fix minor issues
Diffstat (limited to 'src/org/traccar/protocol/SkypatrolProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/SkypatrolProtocolDecoder.java | 66 |
1 files changed, 18 insertions, 48 deletions
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 0609e2094..231024731 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -17,13 +17,12 @@ package org.traccar.protocol; import java.net.SocketAddress; 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.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.helper.BitUtil; +import org.traccar.helper.DateBuilder; import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; @@ -56,11 +55,9 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; - // Read header int apiNumber = buf.readUnsignedShort(); int commandType = buf.readUnsignedByte(); - int messageType = buf.getUnsignedByte(buf.readerIndex()) >> 4; - boolean needAck = (buf.readUnsignedByte() & 0xf) == 1; + int messageType = BitUtil.from(buf.readUnsignedByte(), 4); long mask = defaultMask; if (buf.readUnsignedByte() == 4) { mask = buf.readUnsignedInt(); @@ -69,17 +66,14 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { // Binary position report if (apiNumber == 5 && commandType == 2 && messageType == 1 && BitUtil.check(mask, 0)) { - // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); - // Status code if (BitUtil.check(mask, 1)) { position.set(Event.KEY_STATUS, buf.readUnsignedInt()); } - // Device id - String id = null; + String id; if (BitUtil.check(mask, 23)) { id = buf.toString(buf.readerIndex(), 8, Charset.defaultCharset()).trim(); buf.skipBytes(8); @@ -95,116 +89,92 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(getDeviceId()); - // IO data if (BitUtil.check(mask, 3)) { - buf.readUnsignedShort(); + buf.readUnsignedShort(); // io data } - // ADC 1 if (BitUtil.check(mask, 4)) { - buf.readUnsignedShort(); + buf.readUnsignedShort(); // adc 1 } - // ADC 2 if (BitUtil.check(mask, 5)) { - buf.readUnsignedShort(); + buf.readUnsignedShort(); // adc 2 } - // Function category if (BitUtil.check(mask, 7)) { - buf.readUnsignedByte(); + buf.readUnsignedByte(); // function category } - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); + DateBuilder dateBuilder = new DateBuilder(); - // Date 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()); + dateBuilder.setDateReverse( + buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); } - // GPS status if (BitUtil.check(mask, 9)) { - position.setValid(buf.readUnsignedByte() == 1); + position.setValid(buf.readUnsignedByte() == 1); // gps status } - // Latitude if (BitUtil.check(mask, 10)) { position.setLatitude(convertCoordinate(buf.readUnsignedInt())); } - // Longitude if (BitUtil.check(mask, 11)) { position.setLongitude(convertCoordinate(buf.readUnsignedInt())); } - // Speed if (BitUtil.check(mask, 12)) { position.setSpeed(buf.readUnsignedShort() / 10.0); } - // Course if (BitUtil.check(mask, 13)) { position.setCourse(buf.readUnsignedShort() / 10.0); } - // Time 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()); + dateBuilder.setTime( + buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); } - position.setTime(time.getTime()); + position.setTime(dateBuilder.getDate()); - // Altitude if (BitUtil.check(mask, 15)) { position.setAltitude(buf.readMedium()); } - // Satellites if (BitUtil.check(mask, 16)) { position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); } - // Battery percentage if (BitUtil.check(mask, 17)) { - buf.readUnsignedShort(); + buf.readUnsignedShort(); // battery percentage } - // Trip odometer if (BitUtil.check(mask, 20)) { position.set("trip", buf.readUnsignedInt()); } - // Odometer if (BitUtil.check(mask, 21)) { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); } - // Time of message generation if (BitUtil.check(mask, 22)) { - buf.skipBytes(6); + buf.skipBytes(6); // time of message generation } - // Battery level if (BitUtil.check(mask, 24)) { position.set(Event.KEY_POWER, buf.readUnsignedShort() / 1000.0); } - // GPS overspeed if (BitUtil.check(mask, 25)) { - buf.skipBytes(18); + buf.skipBytes(18); // gps overspeed } - // Cell information if (BitUtil.check(mask, 26)) { - buf.skipBytes(54); + buf.skipBytes(54); // cell information } - // Sequence number if (BitUtil.check(mask, 28)) { position.set(Event.KEY_INDEX, buf.readUnsignedShort()); } |