diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-19 12:22:04 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-19 12:22:04 +1300 |
commit | 66f6f48f00f01600afb13395c8b8c1fe95254201 (patch) | |
tree | 3228c552d5bf52b77251929d95ad66b5fb6601be | |
parent | 43814126839b863ac73452d395a0ec5e0d817d46 (diff) | |
download | trackermap-server-66f6f48f00f01600afb13395c8b8c1fe95254201.tar.gz trackermap-server-66f6f48f00f01600afb13395c8b8c1fe95254201.tar.bz2 trackermap-server-66f6f48f00f01600afb13395c8b8c1fe95254201.zip |
Fix more check style issues
-rw-r--r-- | src/org/traccar/helper/Parser.java | 12 | ||||
-rw-r--r-- | src/org/traccar/protocol/AutoFon45ProtocolDecoder.java | 6 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 14 | ||||
-rw-r--r-- | src/org/traccar/protocol/PiligrimProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Stl060ProtocolDecoder.java | 95 | ||||
-rw-r--r-- | src/org/traccar/protocol/TopflytechProtocolDecoder.java | 3 |
6 files changed, 54 insertions, 78 deletions
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index ef972600b..7c15c0323 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -38,10 +38,14 @@ public class Parser { } public boolean hasNext() { + return hasNext(1); + } + + public boolean hasNext(int number) { if (matcher.group(position) != null) { return true; } else { - position++; + position += number; return false; } } @@ -80,6 +84,7 @@ public class Parser { public enum CoordinateFormat { DEG_MIN_HEM, + DEG_MIN_MIN_HEM, HEM_DEG, HEM_DEG_MIN, HEM_DEG_MIN_HEM @@ -90,6 +95,11 @@ public class Parser { String hemisphere; switch (format) { + case DEG_MIN_MIN_HEM: + coordinate = nextInt(); + coordinate += (nextInt() + nextInt() / 1000.0) / 60; + hemisphere = next(); + break; case HEM_DEG: hemisphere = next(); coordinate = nextDouble(); diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java index 8df23f27f..53361c4ed 100644 --- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java @@ -107,8 +107,10 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Location - position.setLatitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte())); - position.setLongitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte())); + position.setLatitude(convertCoordinate(buf.readUnsignedByte(), + buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte())); + position.setLongitude(convertCoordinate(buf.readUnsignedByte(), + buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte())); position.setSpeed(buf.readUnsignedByte()); position.setCourse(buf.readUnsignedByte() << 8 | buf.readUnsignedByte()); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 5b19db43b..e319d9e81 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -78,7 +78,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_COMMAND_1 = 0x81; public static final int MSG_COMMAND_2 = 0x82; - private final static Set<Integer> MESSAGES_SUPPORTED = new HashSet<>(Arrays.asList( + private static final Set<Integer> MESSAGES_SUPPORTED = new HashSet<>(Arrays.asList( MSG_GPS, MSG_GPS_LBS_1, MSG_GPS_LBS_2, @@ -88,14 +88,14 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { MSG_GPS_PHONE, MSG_GPS_LBS_EXTEND)); - private final static Set<Integer> MESSAGES_LBS = new HashSet<>(Arrays.asList( + private static final Set<Integer> MESSAGES_LBS = new HashSet<>(Arrays.asList( MSG_GPS_LBS_1, MSG_GPS_LBS_2, MSG_GPS_LBS_STATUS_1, MSG_GPS_LBS_STATUS_2, MSG_GPS_LBS_STATUS_3)); - private final static Set<Integer> MESSAGES_STATUS = new HashSet<>(Arrays.asList( + private static final Set<Integer> MESSAGES_STATUS = new HashSet<>(Arrays.asList( MSG_GPS_LBS_STATUS_1, MSG_GPS_LBS_STATUS_2, MSG_GPS_LBS_STATUS_3)); @@ -184,8 +184,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { int union = buf.readUnsignedShort(); position.setCourse(union & 0b0000_0011_1111_1111); position.setValid((union & 0b0001_0000_0000_0000) != 0); - if ((union & 0b0000_0100_0000_0000) == 0) latitude = -latitude; - if ((union & 0b0000_1000_0000_0000) != 0) longitude = -longitude; + if ((union & 0b0000_0100_0000_0000) == 0) { + latitude = -latitude; + } + if ((union & 0b0000_1000_0000_0000) != 0) { + longitude = -longitude; + } position.setLatitude(latitude); position.setLongitude(longitude); diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java index 1e9ab620d..a1808a3d8 100644 --- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -18,10 +18,8 @@ package org.traccar.protocol; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; import java.util.LinkedList; import java.util.List; -import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index f27f36ab7..b5b972982 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -16,12 +16,11 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; -import java.util.TimeZone; -import java.util.regex.Matcher; 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.model.Event; import org.traccar.model.Position; @@ -66,87 +65,53 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { @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; - - // Device identification - if (!identify(parser.group(index++), channel)) { + if (!identify(parser.next(), channel)) { return null; } position.setDeviceId(getDeviceId()); - // Date - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++))); - time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++))); - - // Time - 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()); - - // Latitude - Double latitude = Double.parseDouble(parser.group(index++)); - latitude += Double.parseDouble(parser.group(index++) + parser.group(index++)) / 600000; - 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++) + parser.group(index++)) / 600000; - if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; - position.setLongitude(longitude); - - // Speed - position.setSpeed(Double.parseDouble(parser.group(index++))); - - // Course - position.setCourse(Double.parseDouble(parser.group(index++))); + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); // Old format - if (parser.group(index) != null) { - position.set(Event.KEY_ODOMETER, Integer.parseInt(parser.group(index++))); - position.set(Event.KEY_IGNITION, Integer.parseInt(parser.group(index++))); - position.set(Event.KEY_INPUT, Integer.parseInt(parser.group(index++)) + Integer.parseInt(parser.group(index++)) << 1); - position.set(Event.KEY_FUEL, Integer.parseInt(parser.group(index++))); - } else { - index += 5; + if (parser.hasNext(5)) { + position.set(Event.KEY_ODOMETER, parser.nextInt()); + position.set(Event.KEY_IGNITION, parser.nextInt()); + position.set(Event.KEY_INPUT, parser.nextInt() + parser.nextInt() << 1); + position.set(Event.KEY_FUEL, parser.nextInt()); } // New format - if (parser.group(index) != null) { - position.set(Event.KEY_CHARGE, Integer.parseInt(parser.group(index++)) == 1); - position.set(Event.KEY_IGNITION, Integer.parseInt(parser.group(index++))); - position.set(Event.KEY_INPUT, Integer.parseInt(parser.group(index++))); - position.set(Event.KEY_RFID, parser.group(index++)); - position.set(Event.KEY_ODOMETER, Integer.parseInt(parser.group(index++))); - position.set(Event.PREFIX_TEMP + 1, Integer.parseInt(parser.group(index++))); - position.set(Event.KEY_FUEL, Integer.parseInt(parser.group(index++))); - position.set("accel", Integer.parseInt(parser.group(index++)) == 1); - position.set(Event.KEY_OUTPUT, Integer.parseInt(parser.group(index++)) + Integer.parseInt(parser.group(index++)) << 1); - } else { - index += 10; + if (parser.hasNext(10)) { + position.set(Event.KEY_CHARGE, parser.nextInt() == 1); + position.set(Event.KEY_IGNITION, parser.nextInt()); + position.set(Event.KEY_INPUT, parser.nextInt()); + position.set(Event.KEY_RFID, parser.next()); + position.set(Event.KEY_ODOMETER, parser.nextInt()); + position.set(Event.PREFIX_TEMP + 1, parser.nextInt()); + position.set(Event.KEY_FUEL, parser.nextInt()); + position.set("accel", parser.nextInt() == 1); + position.set(Event.KEY_OUTPUT, parser.nextInt() + parser.nextInt() << 1); } - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0); + position.setValid(parser.next().equals("A")); return position; } diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index 1bde4f399..5fa4b3456 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -16,9 +16,6 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; -import java.util.TimeZone; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; |