diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-19 12:04:22 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-19 12:04:22 +1300 |
commit | 43814126839b863ac73452d395a0ec5e0d817d46 (patch) | |
tree | cb2a0b3842734dbc421d65f3c42e872f875a3f7c | |
parent | c46e2e86536abfe36096e4d86cd3d82f0d4e64eb (diff) | |
download | trackermap-server-43814126839b863ac73452d395a0ec5e0d817d46.tar.gz trackermap-server-43814126839b863ac73452d395a0ec5e0d817d46.tar.bz2 trackermap-server-43814126839b863ac73452d395a0ec5e0d817d46.zip |
Clean up some check style issues
8 files changed, 59 insertions, 91 deletions
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java index f132e82d2..2bf10b14c 100644 --- a/src/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/org/traccar/protocol/GatorProtocolDecoder.java @@ -43,15 +43,15 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_PICTURE_FRAME = 0x54; public static final int MSG_CAMERA_RESPONSE = 0x56; public static final int MSG_PICTURE_DATA = 0x57; - + public static String decodeId(int b1, int b2, int b3, int b4) { - + int d1 = 30 + ((b1 >> 7) << 3) + ((b2 >> 7) << 2) + ((b3 >> 7) << 1) + (b4 >> 7); int d2 = b1 & 0x7f; int d3 = b2 & 0x7f; int d4 = b3 & 0x7f; int d5 = b4 & 0x7f; - + return String.format("%02d%02d%02d%02d%02d", d1, d2, d3, d4, d5); } diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java index 7c981a81b..4e6241a40 100644 --- a/src/org/traccar/protocol/IntellitracFrameDecoder.java +++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java @@ -16,19 +16,16 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -public class IntellitracFrameDecoder extends DelimiterBasedFrameDecoder { +public class IntellitracFrameDecoder extends LineBasedFrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 0; - private static final byte[] delimiter = {(byte) '\r', (byte) '\n'}; - public IntellitracFrameDecoder(int maxFrameLength) { - super(maxFrameLength, ChannelBuffers.wrappedBuffer(delimiter)); + super(maxFrameLength); } // example of sync header: 0xFA 0xF8 0x1B 0x01 0x81 0x60 0x33 0x3C diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index c059d6160..b65a16103 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -275,7 +275,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_SATELLITES, satellites); } - // TODO: process other data + // other data return position; } @@ -305,7 +305,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { short offset = buf.readUnsignedByte(); // dataOffset short packetCount = buf.readUnsignedByte(); buf.readUnsignedByte(); // reserved - buf.readUnsignedByte(); // TODO: handle timezone + buf.readUnsignedByte(); // timezone buf.skipBytes(offset - 5); // Send response diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java index 7de056f99..1e9ab620d 100644 --- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -34,6 +34,7 @@ import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.QueryStringDecoder; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.DateBuilder; import org.traccar.model.Event; import org.traccar.model.Position; @@ -102,24 +103,18 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - // Time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); - time.set(Calendar.MONTH, (buf.getByte(buf.readerIndex()) & 0x0f) - 1); - time.set(Calendar.YEAR, 2010 + (buf.readUnsignedByte() >> 4)); - time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte()); - time.set(Calendar.MINUTE, buf.readUnsignedByte()); - time.set(Calendar.SECOND, buf.readUnsignedByte()); - position.setTime(time.getTime()); - - // Latitude + DateBuilder dateBuilder = new DateBuilder() + .setDay(buf.readUnsignedByte()) + .setMonth(buf.getByte(buf.readerIndex()) & 0x0f) + .setYear(2010 + (buf.readUnsignedByte() >> 4)) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); + position.setTime(dateBuilder.getDate()); + double latitude = buf.readUnsignedByte(); latitude += buf.readUnsignedByte() / 60.0; latitude += buf.readUnsignedByte() / 6000.0; latitude += buf.readUnsignedByte() / 600000.0; - // Longitude double longitude = buf.readUnsignedByte(); longitude += buf.readUnsignedByte() / 60.0; longitude += buf.readUnsignedByte() / 6000.0; @@ -127,8 +122,12 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { // Hemisphere int flags = buf.readUnsignedByte(); - if ((flags & 0x01) != 0) latitude = -latitude; - if ((flags & 0x02) != 0) longitude = -longitude; + if ((flags & 0x01) != 0) { + latitude = -latitude; + } + if ((flags & 0x02) != 0) { + longitude = -longitude; + } position.setLatitude(latitude); position.setLongitude(longitude); diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index dfbdca930..0609e2094 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -52,8 +52,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; @@ -68,10 +67,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { } // Binary position report - if (apiNumber == 5 && - commandType == 2 && - messageType == 1 && - BitUtil.check(mask, 0)) { + if (apiNumber == 5 && commandType == 2 && messageType == 1 && BitUtil.check(mask, 0)) { // Create new position Position position = new Position(); diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index e4966aabe..d3bca57ce 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -43,7 +43,11 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { ChannelBuffer response = ChannelBuffers.directBuffer(1); - response.writeByte(result ? 1 : 0); + if (result) { + response.writeByte(1); + } else { + response.writeByte(0); + } channel.write(response); } } @@ -60,8 +64,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { int codec = buf.readUnsignedByte(); // codec if (codec == CODEC_12) { - // TODO: decode serial port data - return null; + return null; // decode serial port data } int count = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index 5ea431709..1bde4f399 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -24,6 +24,9 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; public class TopflytechProtocolDecoder extends BaseProtocolDecoder { @@ -32,75 +35,47 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern pattern = Pattern.compile( - "\\(" + - "(\\d+)" + // IMEI - ".*" + - "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) - "(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS) - "([AV])" + // Validity - "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) - "([NS])" + - "(\\d{3})(\\d{2}\\.\\d{4})" + // Longitude (DDDMM.MMMM) - "([EW])" + - "(\\d{3}\\.\\d)" + // Speed - "(\\d+\\.\\d+)"); // Course + private static final Pattern PATTERN = new PatternBuilder() + .txt("(") + .num("(d+)") // imei + .any() + .num("(dd)(dd)(dd)") // date (yymmdd) + .num("(dd)(dd)(dd)") // time + .xpr("([AV])") + .num("(dd)(dd.dddd)([NS])") // latitude + .num("(ddd)(dd.dddd)([EW])") // longitude + .num("(ddd.d)") // speed + .num("(d+.d+)") // course + .compile(); @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; - - // Parse message - Matcher parser = pattern.matcher(sentence); + Parser parser = new Parser(PATTERN, (String) msg); if (!parser.matches()) { return null; } - // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); - Integer index = 1; - // Identifier - if (!identify(parser.group(index++), channel)) { + if (!identify(parser.next(), channel)) { return null; } position.setDeviceId(getDeviceId()); - // Time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++))); - time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++))); - time.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++))); - time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++))); - position.setTime(time.getTime()); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0); - - // Latitude - Double latitude = Double.parseDouble(parser.group(index++)); - latitude += Double.parseDouble(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double longitude = Double.parseDouble(parser.group(index++)); - longitude += Double.parseDouble(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; - position.setLongitude(longitude); + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); - // Speed - position.setSpeed(Double.parseDouble(parser.group(index++))); + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); - // Course - position.setCourse(Double.parseDouble(parser.group(index++))); return position; } diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index e5096c675..6ab2f1a27 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -114,10 +114,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .num("(ddd)") // speed .num("(dd.d)") // pdop .num("(d{7})") // odometer - .num("(dd)(dd.dddd)") // latitude - .xpr("([NS])") - .num("(ddd)(dd.dddd)") // longitude - .xpr("([EW])") + .num("(dd)(dd.dddd)([NS])") // latitude + .num("(ddd)(dd.dddd)([EW])") // longitude .num("dddd") // serial number .num("xxxx") // checksum .any() |