From d4dbf85d9536bfec85252a58fc552e2bad42ff17 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 4 Oct 2015 13:20:46 +1300 Subject: Remove trailing whitespaces from code --- src/org/traccar/protocol/ApelProtocolDecoder.java | 16 ++-- .../traccar/protocol/AplicomProtocolDecoder.java | 22 ++--- .../traccar/protocol/Ardi01ProtocolDecoder.java | 10 +- src/org/traccar/protocol/AtrackFrameDecoder.java | 6 +- .../traccar/protocol/AtrackProtocolDecoder.java | 10 +- .../traccar/protocol/AutoFon45FrameDecoder.java | 4 +- .../traccar/protocol/AutoFon45ProtocolDecoder.java | 2 +- src/org/traccar/protocol/AutoFonFrameDecoder.java | 4 +- .../traccar/protocol/Avl301ProtocolDecoder.java | 2 +- src/org/traccar/protocol/BceProtocolDecoder.java | 2 +- .../traccar/protocol/BlackKiteProtocolDecoder.java | 28 +++--- src/org/traccar/protocol/BoxProtocolDecoder.java | 16 ++-- .../traccar/protocol/CalAmpProtocolDecoder.java | 2 +- .../traccar/protocol/CarTrackProtocolDecoder.java | 8 +- .../traccar/protocol/CarscopProtocolDecoder.java | 4 +- .../traccar/protocol/CastelProtocolDecoder.java | 14 +-- .../traccar/protocol/CellocatorFrameDecoder.java | 6 +- .../protocol/CellocatorProtocolDecoder.java | 26 +++--- .../traccar/protocol/EasyTrackProtocolDecoder.java | 8 +- .../traccar/protocol/EelinkProtocolDecoder.java | 20 ++-- .../traccar/protocol/EnforaProtocolDecoder.java | 2 +- .../traccar/protocol/FreedomProtocolDecoder.java | 2 +- src/org/traccar/protocol/GalileoFrameDecoder.java | 6 +- .../traccar/protocol/GalileoProtocolDecoder.java | 32 +++---- src/org/traccar/protocol/GatorProtocolDecoder.java | 10 +- src/org/traccar/protocol/Gl100ProtocolDecoder.java | 2 +- .../traccar/protocol/GlobalSatProtocolDecoder.java | 14 +-- .../traccar/protocol/GoSafeProtocolDecoder.java | 2 +- src/org/traccar/protocol/GotopProtocolDecoder.java | 4 +- .../traccar/protocol/Gps103ProtocolDecoder.java | 10 +- .../traccar/protocol/Gps103ProtocolEncoder.java | 4 +- .../traccar/protocol/GpsGateProtocolDecoder.java | 6 +- src/org/traccar/protocol/Gt02ProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gt06FrameDecoder.java | 8 +- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 12 +-- src/org/traccar/protocol/Gt06ProtocolEncoder.java | 8 +- src/org/traccar/protocol/H02FrameDecoder.java | 10 +- src/org/traccar/protocol/H02ProtocolDecoder.java | 24 ++--- .../traccar/protocol/HaicomProtocolDecoder.java | 6 +- .../traccar/protocol/IntellitracFrameDecoder.java | 12 +-- .../protocol/IntellitracProtocolDecoder.java | 12 +-- src/org/traccar/protocol/Jt600FrameDecoder.java | 4 +- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 6 +- src/org/traccar/protocol/KhdProtocolDecoder.java | 18 ++-- src/org/traccar/protocol/KhdProtocolEncoder.java | 4 +- .../traccar/protocol/LaipacProtocolDecoder.java | 8 +- src/org/traccar/protocol/M2mProtocolDecoder.java | 14 +-- .../traccar/protocol/ManPowerProtocolDecoder.java | 4 +- src/org/traccar/protocol/MaxonProtocolDecoder.java | 2 +- .../traccar/protocol/MegastekProtocolDecoder.java | 10 +- src/org/traccar/protocol/MeiligaoFrameDecoder.java | 6 +- .../traccar/protocol/MeiligaoProtocolDecoder.java | 18 ++-- src/org/traccar/protocol/MeitrackFrameDecoder.java | 4 +- .../traccar/protocol/MeitrackProtocolDecoder.java | 36 +++---- .../traccar/protocol/MeitrackProtocolEncoder.java | 4 +- .../protocol/MiniFinderProtocolDecoder.java | 6 +- src/org/traccar/protocol/Mta6ProtocolDecoder.java | 42 ++++----- src/org/traccar/protocol/MtxProtocolDecoder.java | 4 +- src/org/traccar/protocol/MxtFrameDecoder.java | 2 +- src/org/traccar/protocol/MxtProtocolDecoder.java | 18 ++-- src/org/traccar/protocol/NavigilFrameDecoder.java | 8 +- .../traccar/protocol/NavigilProtocolDecoder.java | 104 ++++++++++----------- src/org/traccar/protocol/NavisProtocolDecoder.java | 6 +- src/org/traccar/protocol/NoranProtocolDecoder.java | 16 ++-- src/org/traccar/protocol/OrionFrameDecoder.java | 14 +-- src/org/traccar/protocol/OrionProtocolDecoder.java | 28 +++--- .../traccar/protocol/OsmAndProtocolDecoder.java | 6 +- .../traccar/protocol/PiligrimProtocolDecoder.java | 46 ++++----- .../traccar/protocol/ProgressProtocolDecoder.java | 2 +- .../traccar/protocol/Pt3000ProtocolDecoder.java | 6 +- src/org/traccar/protocol/Pt502FrameDecoder.java | 12 +-- src/org/traccar/protocol/RitiProtocolDecoder.java | 8 +- .../traccar/protocol/RuptelaProtocolDecoder.java | 10 +- src/org/traccar/protocol/SanavProtocolDecoder.java | 2 +- .../traccar/protocol/SkypatrolProtocolDecoder.java | 4 +- src/org/traccar/protocol/Stl060FrameDecoder.java | 10 +- .../traccar/protocol/Stl060ProtocolDecoder.java | 4 +- .../traccar/protocol/SuntechProtocolDecoder.java | 10 +- .../traccar/protocol/SuntechProtocolEncoder.java | 4 +- src/org/traccar/protocol/T55ProtocolDecoder.java | 6 +- src/org/traccar/protocol/TaipProtocolDecoder.java | 22 ++--- src/org/traccar/protocol/TelikProtocolDecoder.java | 6 +- .../traccar/protocol/TeltonikaFrameDecoder.java | 6 +- .../traccar/protocol/TeltonikaProtocolDecoder.java | 52 +++++------ src/org/traccar/protocol/Tk102ProtocolDecoder.java | 2 +- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 6 +- src/org/traccar/protocol/Tlt2hProtocolDecoder.java | 10 +- .../protocol/TopflytechProtocolDecoder.java | 2 +- src/org/traccar/protocol/TotemProtocolDecoder.java | 14 +-- src/org/traccar/protocol/TotemProtocolEncoder.java | 10 +- src/org/traccar/protocol/Tr20ProtocolDecoder.java | 2 +- .../traccar/protocol/TrackboxProtocolDecoder.java | 14 +-- src/org/traccar/protocol/TramigoFrameDecoder.java | 4 +- .../traccar/protocol/TramigoProtocolDecoder.java | 2 +- src/org/traccar/protocol/TytanProtocolDecoder.java | 28 +++--- src/org/traccar/protocol/TzoneProtocolDecoder.java | 82 ++++++++-------- src/org/traccar/protocol/UlbotechFrameDecoder.java | 2 +- .../traccar/protocol/UlbotechProtocolDecoder.java | 2 +- src/org/traccar/protocol/V680ProtocolDecoder.java | 6 +- .../traccar/protocol/VisiontekProtocolDecoder.java | 2 +- .../traccar/protocol/WialonProtocolDecoder.java | 12 +-- src/org/traccar/protocol/WondexFrameDecoder.java | 6 +- .../traccar/protocol/WondexProtocolDecoder.java | 14 +-- src/org/traccar/protocol/XexunProtocolDecoder.java | 2 +- src/org/traccar/protocol/XirgoProtocolDecoder.java | 4 +- src/org/traccar/protocol/Xt013ProtocolDecoder.java | 2 +- src/org/traccar/protocol/YwtProtocolDecoder.java | 18 ++-- 107 files changed, 623 insertions(+), 623 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 09c1a79f1..c3e16a7dc 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -103,11 +103,11 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { boolean alarm = (type & 0x8000) != 0; type = type & 0x7FFF; buf.readUnsignedShort(); // length - + if (alarm) { sendSimpleMessage(channel, MSG_TYPE_ACK_ALARM); } - + if (type == MSG_TYPE_TRACKER_ID) { Log.warning("Unsupported authentication type"); return null; @@ -120,7 +120,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { length = buf.readUnsignedShort(); identify(buf.readBytes(length).toString(Charset.defaultCharset()), channel); } - + else if (type == MSG_TYPE_LAST_LOG_INDEX) { long index = buf.readUnsignedInt(); if (index > 0) { @@ -192,7 +192,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Satellites position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); - + // Cell signal position.set(Event.KEY_GSM, buf.readUnsignedByte()); @@ -205,12 +205,12 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Input/Output position.set(Event.KEY_INPUT, buf.readUnsignedByte()); position.set(Event.KEY_OUTPUT, buf.readUnsignedByte()); - + // Analog sensors for (int i = 1; i <= 8; i++) { position.set(Event.PREFIX_ADC + i, buf.readUnsignedShort()); } - + // Counters position.set(Event.PREFIX_COUNT + 1, buf.readUnsignedInt()); position.set(Event.PREFIX_COUNT + 2, buf.readUnsignedInt()); @@ -222,7 +222,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Skip CRC buf.readUnsignedInt(); - + if (type == MSG_TYPE_LOG_RECORDS) { requestArchive(channel); } else { diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 574ff09c3..a4d177ed0 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -56,13 +56,13 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if (validateImei(imei)) { return imei; } - + // Try TC65 v2.8 imei = IMEI_BASE_TC65_V28 + ((unitId + 0xA8180) & 0xFFFFFF); if (validateImei(imei)) { return imei; } - + // Try TC65 v2.0 imei = IMEI_BASE_TC65_V20 + unitId; if (validateImei(imei)) { @@ -70,7 +70,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - + return unitId; } @@ -148,7 +148,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if ((selector & 0x0040) != 0) { position.set(Event.KEY_INPUT, buf.readUnsignedByte()); } - + // ADC if ((selector & 0x0020) != 0) { position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort()); @@ -162,13 +162,13 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_POWER, buf.readUnsignedShort() / 1000.0); position.set(Event.KEY_BATTERY, buf.readUnsignedShort()); } - + // Pulse rate 1 if ((selector & 0x10000) != 0) { buf.readUnsignedShort(); buf.readUnsignedInt(); } - + // Pulse rate 2 if ((selector & 0x20000) != 0) { buf.readUnsignedShort(); @@ -189,17 +189,17 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if ((selector & 0x0040) != 0) { position.set(Event.KEY_OUTPUT, buf.readUnsignedByte()); } - + // Button if ((selector & 0x0200) != 0) { buf.skipBytes(6); } - + // Keypad if ((selector & 0x0400) != 0) { buf.readUnsignedByte(); } - + // Altitude if ((selector & 0x0800) != 0) { position.setAltitude(buf.readShort()); @@ -325,8 +325,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { break; } } - } - + } + return position; } diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java index 723c5ddd6..c63b959cd 100644 --- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java @@ -22,7 +22,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -53,7 +53,7 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { @@ -81,19 +81,19 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Location data position.setLongitude(Double.valueOf(parser.group(index++))); position.setLatitude(Double.valueOf(parser.group(index++))); position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++)))); position.setCourse(Double.valueOf(parser.group(index++))); position.setAltitude(Double.valueOf(parser.group(index++))); - + // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); - + // Event position.set(Event.KEY_EVENT, parser.group(index++)); diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java index 35db02baf..cda1ebb2b 100644 --- a/src/org/traccar/protocol/AtrackFrameDecoder.java +++ b/src/org/traccar/protocol/AtrackFrameDecoder.java @@ -23,17 +23,17 @@ import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; public class AtrackFrameDecoder extends LengthFieldBasedFrameDecoder { private static final int KEEPALIVE_LENGTH = 12; - + public AtrackFrameDecoder() { super(1024, 4, 2); } - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Keep alive message if (buf.readableBytes() >= KEEPALIVE_LENGTH && buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) { diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 1f777b12a..792f22c07 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -45,9 +45,9 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { channel.write(response, remoteAddress); } } - + private static String readString(ChannelBuffer buf) { - + String result = null; int length = 0; while (buf.getByte(buf.readerIndex() + length) != 0) { @@ -58,10 +58,10 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(length); } buf.readByte(); - + return result; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -76,7 +76,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { } return null; } - + buf.skipBytes(2); // prefix buf.readUnsignedShort(); // checksum buf.readUnsignedShort(); // length diff --git a/src/org/traccar/protocol/AutoFon45FrameDecoder.java b/src/org/traccar/protocol/AutoFon45FrameDecoder.java index e388273cf..8a96ceb4e 100644 --- a/src/org/traccar/protocol/AutoFon45FrameDecoder.java +++ b/src/org/traccar/protocol/AutoFon45FrameDecoder.java @@ -30,7 +30,7 @@ public class AutoFon45FrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < 12) { return null; @@ -45,7 +45,7 @@ public class AutoFon45FrameDecoder extends FrameDecoder { length = 34; break; } - + // Check length and return buffer if (length != 0 && buf.readableBytes() >= length) { return buf.readBytes(length); diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java index 762cb4d8d..67438613c 100644 --- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java @@ -44,7 +44,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; int type = buf.getUnsignedByte(0); diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java index f4b5c8f0b..e8de3ea66 100644 --- a/src/org/traccar/protocol/AutoFonFrameDecoder.java +++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java @@ -31,7 +31,7 @@ public class AutoFonFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < 12) { return null; @@ -49,7 +49,7 @@ public class AutoFonFrameDecoder extends FrameDecoder { length = 257; break; } - + // Check length and return buffer if (length != 0 && buf.readableBytes() >= length) { return buf.readBytes(length); diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 8116958da..0aec2dad5 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -23,7 +23,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; public class Avl301ProtocolDecoder extends BaseProtocolDecoder { diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java index 4d4f262e8..af8e70d70 100644 --- a/src/org/traccar/protocol/BceProtocolDecoder.java +++ b/src/org/traccar/protocol/BceProtocolDecoder.java @@ -48,7 +48,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + String imei = String.format("%015d", buf.readLong()); if (!identify(imei, channel)) { return null; diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java index 4b78cf647..21c7c5b33 100644 --- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java +++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java @@ -70,16 +70,16 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + buf.readUnsignedByte(); // header int length = (buf.readUnsignedShort() & 0x7fff) + 3; - + List positions = new LinkedList<>(); Set tags = new HashSet<>(); boolean hasLocation = false; Position position = new Position(); position.setProtocol(getProtocolName()); - + while (buf.readerIndex() < length) { // Check if new message started @@ -93,7 +93,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { position = new Position(); } tags.add(tag); - + switch (tag) { case TAG_IMEI: @@ -105,30 +105,30 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { case TAG_DATE: position.setTime(new Date(buf.readUnsignedInt() * 1000)); break; - + case TAG_COORDINATES: hasLocation = true; position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00); position.setLatitude(buf.readInt() / 1000000.0); position.setLongitude(buf.readInt() / 1000000.0); break; - + case TAG_SPEED_COURSE: position.setSpeed(buf.readUnsignedShort() * 0.0539957); position.setCourse(buf.readUnsignedShort() * 0.1); break; - + case TAG_ALTITUDE: position.setAltitude(buf.readShort()); break; - + case TAG_STATUS: int status = buf.readUnsignedShort(); position.set(Event.KEY_IGNITION, BitUtil.check(status, 9)); position.set(Event.KEY_ALARM, BitUtil.check(status, 15)); position.set(Event.KEY_POWER, BitUtil.check(status, 2)); break; - + case TAG_DIGITAL_INPUTS: int input = buf.readUnsignedShort(); for (int i = 0; i < 16; i++) @@ -140,15 +140,15 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < 16; i++) position.set(Event.PREFIX_IO + (i + 17), BitUtil.check(output, i)); break; - + case TAG_INPUT_VOLTAGE1: position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0); break; - + case TAG_INPUT_VOLTAGE2: position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0); break; - + case TAG_INPUT_VOLTAGE3: position.set(Event.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0); break; @@ -165,14 +165,14 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { default: break; - + } } if (hasLocation && position.getFixTime() != null) { positions.add(position); } - + if (!hasDeviceId()) { Log.warning("Unknown device"); return null; diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index 3ec0dc9bd..2820bd826 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -53,9 +53,9 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + if (sentence.startsWith("H,")) { - + int index = sentence.indexOf(',', 2) + 1; String id = sentence.substring(index, sentence.indexOf(',', index)); identify(id, channel); @@ -68,7 +68,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { } } - + else if (sentence.startsWith("L,") && hasDeviceId()) { // Parse message @@ -100,20 +100,20 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(Double.parseDouble(parser.group(index++))); position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(parser.group(index++)))); position.setCourse(Double.parseDouble(parser.group(index++))); - + // Distance position.set(Event.KEY_ODOMETER, parser.group(index++)); - + // Event position.set(Event.KEY_EVENT, parser.group(index++)); - + // Status int status = Integer.parseInt(parser.group(index++)); position.setValid((status & 0x04) == 0); position.set(Event.KEY_STATUS, status); return position; } - + return null; } diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index f1cf6ae6f..d05acd94b 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -204,7 +204,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { int accCount = buf.readUnsignedByte(); int accType = accCount >> 6; accCount &= 0x3f; - + if (type != MSG_MINI_EVENT_REPORT) { buf.readUnsignedByte(); // reserved } diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index a5089d227..5c9e883cc 100644 --- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -60,7 +60,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { @@ -88,7 +88,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); - + // Validity position.setValid(parser.group(index++).compareTo("A") == 0); @@ -121,7 +121,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // State position.set(Event.PREFIX_IO + 1, parser.group(index++)); diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java index 41de9f130..b0be91dde 100644 --- a/src/org/traccar/protocol/CarscopProtocolDecoder.java +++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -108,7 +108,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.valueOf(parser.group(index++))); - + // State position.set(Event.KEY_STATUS, parser.group(index++)); diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 95862cc9a..bd20def8b 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -86,9 +86,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { int version = buf.readUnsignedByte(); ChannelBuffer id = buf.readBytes(20); int type = ChannelBuffers.swapShort(buf.readShort()); - + if (type == MSG_HEARTBEAT) { - + if (channel != null) { ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 31); response.writeByte(0x40); response.writeByte(0x40); @@ -107,7 +107,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { type == MSG_GPS || type == MSG_ALARM || type == MSG_CURRENT_LOCATION) { - + if (!identify(id.toString(Charset.defaultCharset()).trim(), channel, remoteAddress)) { return null; @@ -128,7 +128,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { response.writeByte(0x0D); response.writeByte(0x0A); channel.write(response, remoteAddress); } - + } if (type == MSG_GPS) { @@ -138,7 +138,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_CURRENT_LOCATION) { buf.readUnsignedShort(); } - + buf.readUnsignedInt(); // ACC ON time buf.readUnsignedInt(); // UTC time long odometer = buf.readUnsignedInt(); @@ -147,7 +147,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // current fuel consumption long status = buf.readUnsignedInt(); buf.skipBytes(8); - + int count = buf.readUnsignedByte(); List positions = new LinkedList<>(); @@ -184,7 +184,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return position; } - + return null; } diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java index eb1c748b9..7fd542c0b 100644 --- a/src/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java @@ -23,13 +23,13 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class CellocatorFrameDecoder extends FrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 15; - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length int available = buf.readableBytes(); if (available < MESSAGE_MINIMUM_LENGTH) { @@ -63,7 +63,7 @@ public class CellocatorFrameDecoder extends FrameDecoder { if (length > 0 && available >= length) { return buf.readBytes(length); } - + return null; } diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index 4aab9c207..7afe90913 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.ByteOrder; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -46,7 +46,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { } return imei.toString(); } - + static final int MSG_CLIENT_STATUS = 0; static final int MSG_CLIENT_PROGRAMMING = 3; static final int MSG_CLIENT_SERIAL_LOG = 7; @@ -54,9 +54,9 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { static final int MSG_CLIENT_MODULAR = 9; private static final int MSG_SERVER_ACKNOWLEDGE = 4; - + private byte commandCount; - + private void sendReply(Channel channel, long deviceId, byte packetNumber) { ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28); reply.writeByte('M'); @@ -81,7 +81,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { channel.write(reply); } } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -92,7 +92,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(4); // system code int type = buf.readUnsignedByte(); long deviceUniqueId = buf.readUnsignedInt(); - + if (type != MSG_CLIENT_SERIAL) { buf.readUnsignedShort(); // communication control } @@ -105,7 +105,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_CLIENT_STATUS) { Position position = new Position(); position.setProtocol(getProtocolName()); - + // Device identifier if (!identify(String.valueOf(deviceUniqueId), channel)) { return null; @@ -118,23 +118,23 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { // Status position.set(Event.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f); - + int operator = (buf.readUnsignedByte() & 0xf0) << 4; operator += buf.readUnsignedByte(); - + buf.readUnsignedByte(); // reason data buf.readUnsignedByte(); // reason buf.readUnsignedByte(); // mode buf.readUnsignedInt(); // IO - + operator <<= 8; operator += buf.readUnsignedByte(); position.set("operator", operator); - + buf.readUnsignedInt(); // ADC buf.readUnsignedMedium(); // Odometer buf.skipBytes(6); // multi-purpose data - + buf.readUnsignedShort(); // gps fix buf.readUnsignedByte(); // location status buf.readUnsignedByte(); // mode 1 @@ -148,7 +148,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(buf.readInt() * 0.01); position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01)); position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java index 5cb73bbb0..3b07380ea 100644 --- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -87,7 +87,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { // Validity position.setValid(parser.group(index++).compareTo("A") == 0); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -107,7 +107,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { hemisphere = parser.group(index++).equals("8") ? -1 : 1; position.setLongitude( hemisphere * Integer.parseInt(parser.group(index++), 16) / 600000.0); - + position.setSpeed(Integer.parseInt(parser.group(index++), 16) / 100.0); position.setCourse(Integer.parseInt(parser.group(index++), 16) / 100.0); @@ -125,7 +125,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { // Odometer position.set(Event.KEY_ODOMETER, Integer.parseInt(parser.group(index++), 16)); - + // Altitude String altitude = parser.group(index++); if (altitude != null) { diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 8bcc70c19..08612dafd 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -76,45 +76,45 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); buf.readShort(); // length int index = buf.readUnsignedShort(); - + if (type != MSG_GPS && type != MSG_DATA) { sendResponse(channel, type, index); } - + if (type == MSG_LOGIN) { identify(ChannelBufferTools.readHexString(buf, 16).substring(1), channel); } - + else if (hasDeviceId() && (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS)) { - + // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, index); - + // Location position.setTime(new Date(buf.readUnsignedInt() * 1000)); position.setLatitude(buf.readInt() / 1800000.0); position.setLongitude(buf.readInt() / 1800000.0); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedShort()); - + // Cell position.set(Event.KEY_CELL, ChannelBufferTools.readHexString(buf, 18)); - + // Validity position.setValid((buf.readUnsignedByte() & 0x01) != 0); - + if (type == MSG_ALARM) { position.set(Event.KEY_ALARM, buf.readUnsignedByte()); } - + if (type == MSG_STATE) { position.set(Event.KEY_STATUS, buf.readUnsignedByte()); } diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java index 91e18eadd..110aa050d 100644 --- a/src/org/traccar/protocol/EnforaProtocolDecoder.java +++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java index 5f2cd3f2f..d909d4426 100644 --- a/src/org/traccar/protocol/FreedomProtocolDecoder.java +++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/GalileoFrameDecoder.java b/src/org/traccar/protocol/GalileoFrameDecoder.java index 41a895553..3c4284fe0 100644 --- a/src/org/traccar/protocol/GalileoFrameDecoder.java +++ b/src/org/traccar/protocol/GalileoFrameDecoder.java @@ -23,13 +23,13 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class GalileoFrameDecoder extends FrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 5; - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; @@ -40,7 +40,7 @@ public class GalileoFrameDecoder extends FrameDecoder { if (buf.readableBytes() >= (length + MESSAGE_MINIMUM_LENGTH)) { return buf.readBytes(length + MESSAGE_MINIMUM_LENGTH); } - + return null; } diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index 37a31de6e..0b4cba259 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -50,9 +50,9 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private static final int TAG_ODOMETER = 0xd4; private static final int TAG_REFRIGERATOR = 0x5b; private static final int TAG_PRESSURE = 0x5c; - + private static final Map tagLengthMap = new HashMap<>(); - + static { int[] l1 = {0x01,0x02,0x35,0x43,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd5,0x88,0x8a,0x8b,0x8c,0xa0,0xaf,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae}; int[] l2 = {0x04,0x10,0x34,0x40,0x41,0x42,0x45,0x46,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x60,0x61,0x62,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xd6,0xd7,0xd8,0xd9,0xda}; @@ -87,16 +87,16 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + buf.readUnsignedByte(); // header int length = (buf.readUnsignedShort() & 0x7fff) + 3; - + List positions = new LinkedList<>(); Set tags = new HashSet<>(); boolean hasLocation = false; Position position = new Position(); position.setProtocol(getProtocolName()); - + while (buf.readerIndex() < length) { // Check if new message started @@ -110,7 +110,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position = new Position(); } tags.add(tag); - + switch (tag) { case TAG_IMEI: @@ -122,49 +122,49 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { case TAG_DATE: position.setTime(new Date(buf.readUnsignedInt() * 1000)); break; - + case TAG_COORDINATES: hasLocation = true; position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00); position.setLatitude(buf.readInt() / 1000000.0); position.setLongitude(buf.readInt() / 1000000.0); break; - + case TAG_SPEED_COURSE: position.setSpeed(buf.readUnsignedShort() * 0.0539957); position.setCourse(buf.readUnsignedShort() * 0.1); break; - + case TAG_ALTITUDE: position.setAltitude(buf.readShort()); break; - + case TAG_STATUS: position.set(Event.KEY_STATUS, buf.readUnsignedShort()); break; - + case TAG_POWER: position.set(Event.KEY_POWER, buf.readUnsignedShort()); break; - + case TAG_BATTERY: position.set(Event.KEY_BATTERY, buf.readUnsignedShort()); break; - + case TAG_ODOMETER: position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); break; - + default: buf.skipBytes(getTagLength(tag)); break; - + } } if (hasLocation && position.getFixTime() != null) { positions.add(position); } - + if (!hasDeviceId()) { Log.warning("Unknown device"); return null; diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java index d17e0f2f7..7bf0a2633 100644 --- a/src/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/org/traccar/protocol/GatorProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -45,12 +45,12 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { private static final int PACKET_PICTURE_FRAME = 0x54; private static final int PACKET_CAMERA_RESPONSE = 0x56; private static final int PACKET_PICTURE_DATA = 0x57; - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; buf.skipBytes(2); // header @@ -62,12 +62,12 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); id = id.replaceFirst("^0+(?!$)", ""); - + if (type == PACKET_POSITION_DATA || type == PACKET_ROLLCALL_RESPONSE || type == PACKET_ALARM_DATA || type == PACKET_BLIND_AREA) { - + // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index 26102e925..6756cc972 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 2b36d7a9e..e652d932b 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,7 +34,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { public GlobalSatProtocolDecoder(GlobalSatProtocol protocol) { super(protocol); - + format0 = Context.getConfig().getString(getProtocolName() + ".format0", "TSPRXAB27GHKLMnaicz*U!"); format1 = Context.getConfig().getString(getProtocolName() + ".format1", "SARY*U!"); } @@ -169,7 +169,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { } return position; } - + private static final Pattern pattern = Pattern.compile( "\\$" + "(\\d+)," + // IMEI @@ -186,7 +186,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { "(\\d+\\.?\\d*)," + // Course "(\\d+)," + // Satellites "(\\d+\\.?\\d*)"); // HDOP - + private Position decodeAlternative(Channel channel, String sentence) { // Parse message @@ -208,7 +208,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { // Validity position.setValid(parser.group(index++).compareTo("1") != 0); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -257,13 +257,13 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + if (sentence.startsWith("GS")) { return decodeOriginal(channel, sentence); } else if (sentence.startsWith("$")) { return decodeAlternative(channel, sentence); } - + return null; } diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index 843671440..8e2215405 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -53,7 +53,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + if (channel != null) { channel.write("1234"); } diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java index 5bd2f8038..a71dfd7eb 100644 --- a/src/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/org/traccar/protocol/GotopProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -96,7 +96,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { // Speed position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++)))); - + // Status position.set(Event.KEY_STATUS, parser.group(index++)); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index a38e4f133..4a81ceb43 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -119,10 +119,10 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - + int localHours = Integer.valueOf(parser.group(index++)); int localMinutes = Integer.valueOf(parser.group(index++)); - + String utcHours = parser.group(index++); String utcMinutes = parser.group(index++); @@ -137,7 +137,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { if (milliseconds != null) { time.set(Calendar.MILLISECOND, Integer.valueOf(milliseconds)); } - + // Timezone calculation if (utcHours != null && utcMinutes != null) { int deltaMinutes = (localHours - Integer.valueOf(utcHours)) * 60; @@ -181,11 +181,11 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(longitude); // Speed - String speed = parser.group(index++); + String speed = parser.group(index++); if (speed != null) { position.setSpeed(Double.valueOf(speed)); } - + // Course String course = parser.group(index++); if (course != null) { diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java index db4bbc832..2b17acb72 100644 --- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java @@ -39,7 +39,7 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri @Override protected Object encodeCommand(Command command) { - + switch (command.getType()) { case Command.TYPE_POSITION_STOP: return formatCommand(command, "**,imei:{%s},A", Command.KEY_UNIQUE_ID); @@ -56,7 +56,7 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri case Command.TYPE_ALARM_DISARM: return formatCommand(command, "**,imei:{%s},M", Command.KEY_UNIQUE_ID); } - + return null; } diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index d76ef6aed..9e583aebd 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,14 +51,14 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { channel.write(message + Crc.nmeaChecksum(message) + "\r\n"); } } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; - + // Process login if (sentence.startsWith("$FRLIN,")) { int beginIndex = sentence.indexOf(',', 7); diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 5d1a03c77..6ff1a48cb 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java index e0bb3b373..ed0d8d548 100644 --- a/src/org/traccar/protocol/Gt06FrameDecoder.java +++ b/src/org/traccar/protocol/Gt06FrameDecoder.java @@ -27,20 +27,20 @@ public class Gt06FrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < 5) { return null; } - + int length = 2 + 2; // head and tail - + if (buf.getByte(buf.readerIndex()) == 0x78) { length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2); } else { length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2); } - + // Check length and return buffer if (buf.readableBytes() >= length) { return buf.readBytes(length); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index e16432275..e6acc5e1b 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -35,7 +35,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public Gt06ProtocolDecoder(Gt06Protocol protocol) { super(protocol); - + if (Context.getConfig().hasKey(getProtocolName() + ".timezone")) { forceTimeZone = true; timeZone.setRawOffset(Context.getConfig().getInteger(getProtocolName() + ".timezone") * 1000); @@ -98,12 +98,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (buf.readByte() != 0x78 || buf.readByte() != 0x78) { return null; } - + int length = buf.readUnsignedByte(); // size int dataLength = length - 5; int type = buf.readUnsignedByte(); - + if (type == MSG_LOGIN) { String imei = readImei(buf); @@ -177,7 +177,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(latitude); position.setLongitude(longitude); - + if ((union & 0b0100_0000_0000_0000) != 0) { position.set(Event.KEY_IGNITION, (union & 0b1000_0000_0000_0000) != 0); } @@ -218,7 +218,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_GSM, buf.readUnsignedByte()); } } - + if (type == MSG_GPS_LBS_1 && buf.readableBytes() == 4 + 6) { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); } @@ -232,7 +232,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, type, index); return position; } - + else { buf.skipBytes(dataLength); if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) { diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index b879163d2..495e2fff5 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -44,13 +44,13 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { buf.writeByte('\r'); buf.writeByte('\n'); - + return buf; } - + @Override protected Object encodeCommand(Command command) { - + switch (command.getType()) { case Command.TYPE_ENGINE_STOP: return encodeContent("RELAY,1#"); @@ -60,5 +60,5 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { return null; } - + } diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index 1c9e9e6c1..0e3f78737 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -23,7 +23,7 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; public class H02FrameDecoder extends FrameDecoder { - + private static final int MESSAGE_LENGTH = 32; @Override @@ -31,7 +31,7 @@ public class H02FrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + String marker = buf.toString(buf.readerIndex(), 1, Charset.defaultCharset()); while (!marker.equals("*") && !marker.equals("$") && buf.readableBytes() > 0) { @@ -40,7 +40,7 @@ public class H02FrameDecoder extends FrameDecoder { marker = buf.toString(buf.readerIndex(), 1, Charset.defaultCharset()); } } - + if (marker.equals("*")) { // Return text message @@ -48,14 +48,14 @@ public class H02FrameDecoder extends FrameDecoder { if (index != null) { return buf.readBytes(index + 1 - buf.readerIndex()); } - + } else if (marker.equals("$")) { // Return binary message if (buf.readableBytes() >= MESSAGE_LENGTH) { return buf.readBytes(MESSAGE_LENGTH); } - + } return null; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 9aee1f918..c93d0c6dd 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.nio.charset.Charset; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,20 +34,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { public H02ProtocolDecoder(H02Protocol protocol) { super(protocol); } - + private static double readCoordinate(ChannelBuffer buf, boolean lon) { - + int degrees = ChannelBufferTools.readHexInteger(buf, 2); if (lon) { degrees = degrees * 10 + (buf.getUnsignedByte(buf.readerIndex()) >> 4); } - + double result = 0; if (lon) { result = buf.readUnsignedByte() & 0x0f; } result = result * 10 + ChannelBufferTools.readHexInteger(buf, lon ? 5 : 6) * 0.0001; - + result /= 60; result += degrees; @@ -61,13 +61,13 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_IGNITION, !BitUtil.check(status, 10)); position.set(Event.KEY_STATUS, status); } - + private Position decodeBinary(ChannelBuffer buf, Channel channel) { - + // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); - + buf.readByte(); // marker // Identification @@ -86,7 +86,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1); time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2)); position.setTime(time.getTime()); - + // Location double latitude = readCoordinate(buf, false); position.set(Event.KEY_POWER, buf.readByte()); @@ -122,7 +122,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { "(\\d{2})(\\d{2})(\\d{2})," + // Date (DDMMYY) "(\\p{XDigit}{8})" + // Status ".*"); - + private Position decodeText(String sentence, Channel channel) { // Parse message @@ -188,10 +188,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; String marker = buf.toString(0, 1, Charset.defaultCharset()); - + // TODO X mode? if (marker.equals("*")) { diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java index 21a517697..3062c72d5 100644 --- a/src/org/traccar/protocol/HaicomProtocolDecoder.java +++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,7 +79,7 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { // Firmware version position.set(Event.KEY_VERSION, parser.group(index++)); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -112,7 +112,7 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.valueOf(parser.group(index++)) / 10); - + // Additional data position.set(Event.KEY_STATUS, parser.group(index++)); position.set(Event.KEY_GSM, parser.group(index++)); diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java index 461186310..a2e3499c4 100644 --- a/src/org/traccar/protocol/IntellitracFrameDecoder.java +++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java @@ -24,26 +24,26 @@ import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; public class IntellitracFrameDecoder extends DelimiterBasedFrameDecoder { 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)); } - + // example of sync header: 0xFA 0xF8 0x1B 0x01 0x81 0x60 0x33 0x3C - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; } - + // Check for sync packet if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) { ChannelBuffer syncMessage = buf.readBytes(8); diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java index 6c8d5bdf9..052e7a508 100644 --- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java +++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,7 +67,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { @@ -84,7 +84,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Date and time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -95,19 +95,19 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Location data position.setLongitude(Double.valueOf(parser.group(index++))); position.setLatitude(Double.valueOf(parser.group(index++))); position.setSpeed(Double.valueOf(parser.group(index++))); position.setCourse(Double.valueOf(parser.group(index++))); position.setAltitude(Double.valueOf(parser.group(index++))); - + // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); - + // Report identifier position.set(Event.KEY_INDEX, Long.valueOf(parser.group(index++))); diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java index d2fbc4ca8..8b8f4f642 100644 --- a/src/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/org/traccar/protocol/Jt600FrameDecoder.java @@ -35,10 +35,10 @@ public class Jt600FrameDecoder extends FrameDecoder { if (available < 10) { return null; } - + // Message identifier char first = (char) buf.getByte(buf.readerIndex()); - + if (first == '$') { // Check length int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10; diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 8c1d2997b..e6c75ef9d 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -90,9 +90,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(buf.readUnsignedByte() * 2.0); - + if (version == 1) { - + position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); // Power diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java index 67afca20c..6d634e744 100644 --- a/src/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/org/traccar/protocol/KhdProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -102,33 +102,33 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { // Flags int flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) != 0); - + if (type == MSG_ALARM) { - + buf.skipBytes(2); } else { // Odometer position.set(Event.KEY_ODOMETER, buf.readUnsignedMedium()); - + // Status buf.skipBytes(4); - + // Other buf.skipBytes(8); } - + // TODO: parse extra data return position; } else if (type == MSG_LOGIN && channel != null) { - + buf.skipBytes(4); // serial number buf.readByte(); // reserved - + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); response.writeByte(0x29); response.writeByte(0x29); // header response.writeByte(MSG_CONFIRMATION); @@ -141,7 +141,7 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { channel.write(response); } - + return null; } diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java index 20d8eb40a..68196d65c 100644 --- a/src/org/traccar/protocol/KhdProtocolEncoder.java +++ b/src/org/traccar/protocol/KhdProtocolEncoder.java @@ -43,7 +43,7 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder { return buf; } - + @Override protected Object encodeCommand(Command command) { @@ -56,5 +56,5 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder { return null; } - + } diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 1696041fc..f3884650d 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -48,7 +48,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { "(.)," + // Type "[^\\*]+\\*" + "(\\p{XDigit}{2})"); // Checksum - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -61,7 +61,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { channel.write(sentence + "\r\n"); return null; } - + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { @@ -129,7 +129,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } else if (type.equals("X") || type.equals("4")) { response = "$AVCFG,00000000,x*2D"; } - + if (response != null && channel != null) { channel.write(response + "\r\n"); } diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java index 4f50c0411..6e57b5766 100644 --- a/src/org/traccar/protocol/M2mProtocolDecoder.java +++ b/src/org/traccar/protocol/M2mProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -31,7 +31,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { public M2mProtocolDecoder(M2mProtocol protocol) { super(protocol); } - + private boolean firstPacket = true; @Override @@ -50,7 +50,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { } if (firstPacket) { - + firstPacket = false; // Read IMEI @@ -67,7 +67,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { identify(imei.toString(), channel); } else if (hasDeviceId()) { - + // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); @@ -83,7 +83,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte() & 0x7f); time.set(Calendar.SECOND, buf.readUnsignedByte() & 0x7f); position.setTime(time.getTime()); - + // Location int degrees = buf.readUnsignedByte(); double latitude = buf.readUnsignedByte(); @@ -100,14 +100,14 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { longitude += buf.readUnsignedByte() / 10000.0; longitude /= 60; longitude += degrees; - + if ((b & 0x80) != 0) { longitude = -longitude; } if ((b & 0x40) != 0) { latitude = -latitude; } - + position.setLatitude(latitude); position.setLongitude(longitude); position.setSpeed(buf.readUnsignedByte()); diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java index d62c24a68..dc5775581 100644 --- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java +++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -76,7 +76,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { // Alarm message position.set(Event.KEY_STATUS, parser.group(index++)); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java index 8deb61abf..2308e9388 100644 --- a/src/org/traccar/protocol/MaxonProtocolDecoder.java +++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index fa6c7495f..c07ce38ff 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,7 +73,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { ".*"); // Checksum private boolean parseGPRMC(String gprmc, Position position) { - + // Parse message Matcher parser = patternGPRMC.matcher(gprmc); if (!parser.matches()) { @@ -120,7 +120,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); + position.setTime(time.getTime()); return true; } @@ -220,7 +220,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + } } else { @@ -377,7 +377,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { return position; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java index e54a44286..6dcc6fd9c 100644 --- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java +++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java @@ -21,7 +21,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; public class MeiligaoFrameDecoder extends FrameDecoder { - + private static final int MESSAGE_HEADER = 4; @Override @@ -29,12 +29,12 @@ public class MeiligaoFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Strip not '$' (0x24) bytes from the beginning while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) { buf.readByte(); } - + // Check length and return buffer if (buf.readableBytes() >= MESSAGE_HEADER) { int length = buf.getUnsignedShort(buf.readerIndex() + 2); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index faf3a5baf..e50b4f60b 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.charset.Charset; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,13 +73,13 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { private static final int MSG_SERVER = 0x0002; private static final int MSG_LOGIN = 0x5000; private static final int MSG_LOGIN_RESPONSE = 0x4000; - + private static final int MSG_POSITION = 0x9955; private static final int MSG_POSITION_LOGGED = 0x9016; private static final int MSG_ALARM = 0x9999; private static final int MSG_RFID = 0x9966; - + private boolean identify(ChannelBuffer buf, Channel channel) { String id = ""; @@ -107,14 +107,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return identify(id, channel); } - + private static void sendResponse( Channel channel, ChannelBuffer id, int type, ChannelBuffer msg) { - + if (channel != null) { ChannelBuffer buf = ChannelBuffers.buffer( 2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2); - + buf.writeByte('@'); buf.writeByte('@'); buf.writeShort(buf.capacity()); @@ -128,7 +128,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { channel.write(buf); } } - + private String getMeiligaoServer(Channel channel) { String server = Context.getConfig().getString(getProtocolName() + ".server"); if (server == null) { @@ -142,14 +142,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; buf.skipBytes(2); // header buf.readShort(); // length ChannelBuffer id = buf.readBytes(7); int command = buf.readUnsignedShort(); ChannelBuffer response; - + switch (command) { case MSG_LOGIN: if (channel != null) { diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java index 40be60358..509e24da2 100644 --- a/src/org/traccar/protocol/MeitrackFrameDecoder.java +++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java @@ -23,7 +23,7 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; public class MeitrackFrameDecoder extends FrameDecoder { - + @Override protected Object decode( ChannelHandlerContext ctx, @@ -33,7 +33,7 @@ public class MeitrackFrameDecoder extends FrameDecoder { if (buf.readableBytes() < 10) { return null; } - + Integer index = ChannelBufferTools.find(buf, buf.readerIndex(), buf.writerIndex(), ","); if (index != null) { diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index ba7841a8b..8eabcce42 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -139,7 +139,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set("runtime", parser.group(index++)); position.set(Event.KEY_CELL, parser.group(index++)); position.set(Event.KEY_STATUS, parser.group(index++)); - + // ADC String adc1 = parser.group(index++); if (adc1 != null) { @@ -178,10 +178,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { private List decodeBinaryMessage(Channel channel, ChannelBuffer buf) { List positions = new LinkedList<>(); - + String flag = buf.toString(2, 1, Charset.defaultCharset()); int index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ","); - + // Identification String imei = buf.toString(index + 1, 15, Charset.defaultCharset()); if (!identify(imei, channel)) { @@ -189,20 +189,20 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4); - + while (buf.readableBytes() >= 0x34) { - + Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - + // Event position.set(Event.KEY_EVENT, buf.readUnsignedByte()); - + // Location position.setLatitude(buf.readInt() * 0.000001); position.setLongitude(buf.readInt() * 0.000001); - + // Time (946684800 - timestamp for 2000-01-01) position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); @@ -211,7 +211,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { // Satellites position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); - + // GSM Signal position.set(Event.KEY_GSM, buf.readUnsignedByte()); @@ -234,16 +234,16 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort() + "|" + buf.readUnsignedShort() + "|" + buf.readUnsignedShort() + "|" + buf.readUnsignedShort()); position.set(Event.KEY_STATUS, buf.readUnsignedShort()); - + // ADC position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort()); position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.01); position.set(Event.KEY_POWER, buf.readUnsignedShort()); - + buf.readUnsignedInt(); // geo-fence positions.add(position); } - + // Delete recorded data if (channel != null) { StringBuilder command = new StringBuilder("@@"); @@ -254,21 +254,21 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { command.append(String.format("%02x\r\n", checksum & 0xff).toUpperCase()); channel.write(command.toString()); } - + return positions; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; - + // Find type Integer index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ","); index = ChannelBufferTools.find(buf, index + 1, buf.readableBytes(), ","); - + String type = buf.toString(index + 1, 3, Charset.defaultCharset()); if (type.equals("CCC")) { return decodeBinaryMessage(channel, buf); diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java index 73f3d01e4..06fad3b69 100644 --- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java @@ -22,7 +22,7 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - + switch (command.getType()) { case Command.TYPE_ENGINE_STOP: return formatCommand(command, "@@M33,{%s},C01,0,12222*18\r\n", Command.KEY_UNIQUE_ID); @@ -33,7 +33,7 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ALARM_DISARM: return formatCommand(command, "@@M33,{%s},C01,0,22022*18\r\n", Command.KEY_UNIQUE_ID); } - + return null; } diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index ae7731025..12d77e4cc 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -47,7 +47,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { "(\\d+)," + // Satellites in use "(\\d+)," + // Satellites in view "0"); - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -92,7 +92,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(Double.valueOf(parser.group(index++))); position.setSpeed(Double.valueOf(parser.group(index++))); position.setCourse(Double.valueOf(parser.group(index++))); - + // Flags String flags = parser.group(index++); position.set(Event.KEY_FLAGS, flags); diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 86b191b0b..4fb7d0ecd 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -38,7 +38,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class Mta6ProtocolDecoder extends BaseProtocolDecoder { - + private final boolean simple; public Mta6ProtocolDecoder(Protocol protocol, boolean simple) { @@ -51,7 +51,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE); channel.write(response); } - + private void sendResponse(Channel channel, short packetId, short packetCount) { HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.OK); @@ -61,15 +61,15 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { end.writeByte(packetId); end.writeByte(packetCount); end.writeByte(0); - + response.setContent(ChannelBuffers.wrappedBuffer(begin, end)); channel.write(response); } - + private static class FloatReader { - + private int previousFloat; - + public float readFloat(ChannelBuffer buf) { switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) { @@ -88,13 +88,13 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } return Float.intBitsToFloat(previousFloat); } - + } - + private static class TimeReader extends FloatReader { - + private long weekNumber; - + public Date readTime(ChannelBuffer buf) { long weekTime = (long) (readFloat(buf) * 1000); if (weekNumber == 0) { @@ -110,16 +110,16 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { return new Date(offset + weekNumber * 7 * 24 * 60 * 60 * 1000 + weekTime); } - + } private List parseFormatA(ChannelBuffer buf) { List positions = new LinkedList<>(); - + FloatReader latitudeReader = new FloatReader(); FloatReader longitudeReader = new FloatReader(); TimeReader timeReader = new TimeReader(); - + try { while (buf.readable()) { Position position = new Position(); @@ -196,7 +196,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } } catch (IndexOutOfBoundsException error) { } - + return positions; } @@ -270,17 +270,17 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); } - + // TODO: process other data return position; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + HttpRequest request = (HttpRequest) msg; ChannelBuffer buf = request.getContent(); @@ -295,7 +295,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } buf.skipBytes(uniqueId.length()); buf.skipBytes("&bin=".length()); - + // Read header short packetId = buf.readUnsignedByte(); short offset = buf.readUnsignedByte(); // dataOffset @@ -303,13 +303,13 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // reserved short parameters = buf.readUnsignedByte(); // TODO: handle timezone buf.skipBytes(offset - 5); - + // Send response if (channel != null) { sendContinue(channel); sendResponse(channel, packetId, packetCount); } - + // Parse data if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) { if (simple) { diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java index 5fdb657e9..edb10aacf 100644 --- a/src/org/traccar/protocol/MtxProtocolDecoder.java +++ b/src/org/traccar/protocol/MtxProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -80,7 +80,7 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/MxtFrameDecoder.java b/src/org/traccar/protocol/MxtFrameDecoder.java index 56a90c765..23dc64d01 100644 --- a/src/org/traccar/protocol/MxtFrameDecoder.java +++ b/src/org/traccar/protocol/MxtFrameDecoder.java @@ -30,7 +30,7 @@ public class MxtFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + if (buf.readableBytes() < 2) { return null; } diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index 194e0fb71..9f7207bc4 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -101,15 +101,15 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); int inputMask = buf.readUnsignedByte(); - + if (BitUtil.check(infoGroups, 0)) { buf.skipBytes(8); // waypoints } - + if (BitUtil.check(infoGroups, 1)) { buf.skipBytes(8); // wireless accessory } - + if (BitUtil.check(infoGroups, 2)) { position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Event.KEY_HDOP, buf.readUnsignedByte()); @@ -119,24 +119,24 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // input voltage position.set(Event.PREFIX_TEMP + 1, buf.readByte()); } - + if (BitUtil.check(infoGroups, 3)) { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); } - + if (BitUtil.check(infoGroups, 4)) { position.set("hours", buf.readUnsignedInt()); } - + if (BitUtil.check(infoGroups, 5)) { buf.readUnsignedInt(); // reason } - + if (BitUtil.check(infoGroups, 6)) { position.set(Event.KEY_POWER, buf.readUnsignedShort() * 0.001); position.set(Event.KEY_BATTERY, buf.readUnsignedShort()); } - + if (BitUtil.check(infoGroups, 7)) { position.set(Event.KEY_RFID, buf.readUnsignedInt()); } diff --git a/src/org/traccar/protocol/NavigilFrameDecoder.java b/src/org/traccar/protocol/NavigilFrameDecoder.java index 48328b2e5..7a8989115 100644 --- a/src/org/traccar/protocol/NavigilFrameDecoder.java +++ b/src/org/traccar/protocol/NavigilFrameDecoder.java @@ -24,24 +24,24 @@ public class NavigilFrameDecoder extends FrameDecoder { private static final int MESSAGE_HEADER = 20; private static final long PREAMBLE = 0x2477F5F6; - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < MESSAGE_HEADER) { return null; } - + // Check for preamble boolean hasPreamble = false; if (buf.getUnsignedInt(buf.readerIndex()) == PREAMBLE) { hasPreamble = true; } - + // Check length and return buffer int length = buf.getUnsignedShort(buf.readerIndex() + 6); if (buf.readableBytes() >= length) { diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index 7938fd7cc..3e38890d4 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -32,7 +32,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { public NavigilProtocolDecoder(NavigilProtocol protocol) { super(protocol); } - + private static final int LEAP_SECONDS_DELTA = 25; private static final int MESSAGE_ERROR = 2; @@ -50,18 +50,18 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private static final int MESSAGE_TRACKING_DATA = 18; private static final int MESSAGE_MOTION_ALARM = 19; private static final int MESSAGE_ACKNOWLEDGEMENT = 255; - + private static Date convertTimestamp(long timestamp) { return new Date((timestamp - LEAP_SECONDS_DELTA) * 1000l); } - + private int senderSequenceNumber = 1; - + private void sendAcknowledgment(Channel channel, int sequenceNumber) { ChannelBuffer data = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 4); data.writeShort(sequenceNumber); data.writeShort(0); // OK - + ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 20); header.writeByte(1); header.writeByte(0); header.writeShort(senderSequenceNumber++); @@ -71,12 +71,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { header.writeShort(Crc.crc16X25Ccitt(data.toByteBuffer())); header.writeInt(0); header.writeInt((int) (System.currentTimeMillis() / 1000) + LEAP_SECONDS_DELTA); - + if (channel != null) { channel.write(ChannelBuffers.copiedBuffer(header, data)); } } - + private Position parseUnitReport(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -84,34 +84,34 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); - + buf.readUnsignedShort(); // report trigger buf.readUnsignedShort(); // flags - + position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude( buf.readUnsignedShort()); - + buf.readUnsignedShort(); // satellites in fix buf.readUnsignedShort(); // satellites in track buf.readUnsignedShort(); // GPS antenna state - + position.setSpeed(buf.readUnsignedShort() * 0.194384); position.setCourse(buf.readUnsignedShort()); - + buf.readUnsignedInt(); // distance buf.readUnsignedInt(); // delta distance position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - + buf.readUnsignedShort(); // battery charger status - + position.setTime(convertTimestamp(buf.readUnsignedInt())); - + // TODO: a lot of other stuff return position; } - + private Position parseTg2Report(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -119,23 +119,23 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); - + buf.readUnsignedShort(); // report trigger buf.readUnsignedByte(); // reserved buf.readUnsignedByte(); // assisted GPS age - + position.setTime(convertTimestamp(buf.readUnsignedInt())); - + position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude(buf.readUnsignedShort()); - + buf.readUnsignedByte(); // satellites in fix buf.readUnsignedByte(); // satellites in track - + position.setSpeed(buf.readUnsignedShort() * 0.194384); position.setCourse(buf.readUnsignedShort()); - + buf.readUnsignedInt(); // distance buf.readUnsignedShort(); // maximum speed buf.readUnsignedShort(); // minimum speed @@ -144,11 +144,11 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // VSAUT2 voltage buf.readUnsignedShort(); // solar voltage position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - + // TODO: a lot of other stuff return position; } - + private Position parsePositionReport(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -156,20 +156,20 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); position.setTime(convertTimestamp(timestamp)); - + position.setLatitude(buf.readMedium() * 0.00002); position.setLongitude(buf.readMedium() * 0.00002); - + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedByte() * 2); - + short flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40); - + buf.readUnsignedByte(); // reserved return position; } - + private Position parsePositionReport2(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -177,22 +177,22 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); position.setTime(convertTimestamp(timestamp)); - + position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); - + buf.readUnsignedByte(); // report trigger position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - + short flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40); - + int x = buf.readUnsignedByte(); // satellites in fix buf.readUnsignedInt(); // distance return position; } - + private Position parseSnapshot4(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -204,22 +204,22 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // position fix source buf.readUnsignedByte(); // GNSS fix quality buf.readUnsignedByte(); // GNSS assistance age - + long flags = buf.readUnsignedInt(); position.setValid((flags & 0x0400) == 0x0400); - + position.setTime(convertTimestamp(buf.readUnsignedInt())); - + position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude(buf.readUnsignedShort()); - + buf.readUnsignedByte(); // satellites in fix buf.readUnsignedByte(); // satellites in track - + position.setSpeed(buf.readUnsignedShort() * 0.194384); position.setCourse(buf.readUnsignedShort() * 0.1); - + buf.readUnsignedByte(); // maximum speed buf.readUnsignedByte(); // minimum speed buf.readUnsignedInt(); // distance @@ -231,7 +231,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { // TODO: a lot of other stuff return position; } - + private Position parseTrackingData(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -241,33 +241,33 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setTime(convertTimestamp(timestamp)); buf.readUnsignedByte(); // tracking mode - + short flags = buf.readUnsignedByte(); position.setValid((flags & 0x01) == 0x01); - + buf.readUnsignedShort(); // duration position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); - + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedByte() * 2.0); buf.readUnsignedByte(); // satellites in fix - + position.set(Event.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - + buf.readUnsignedInt(); // distance return position; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; - + buf.readUnsignedByte(); // protocol version buf.readUnsignedByte(); // version id int sequenceNumber = buf.readUnsignedShort(); @@ -275,7 +275,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // length int flags = buf.readUnsignedShort(); buf.readUnsignedShort(); // checksum - + // Get device identifier if (!identify(String.valueOf(buf.readUnsignedInt()), channel)) { return null; @@ -287,7 +287,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { if ((flags & 0x1) == 0x0) { sendAcknowledgment(channel, sequenceNumber); } - + // Parse messages switch (messageId) { case MESSAGE_UNIT_REPORT: @@ -303,7 +303,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { case MESSAGE_TRACKING_DATA: return parseTrackingData(buf, sequenceNumber, timestamp); } - + return null; } diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 4f3e6a1a4..8d00ce9e0 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.nio.ByteOrder; import java.nio.charset.Charset; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -57,7 +57,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { } return false; } - + private class ParseResult { private final long id; private final Position position; @@ -300,7 +300,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { // Read message type String type = buf.toString(buf.readerIndex(), 3, charset); buf.skipBytes(type.length()); - + switch (type) { case "*>T": return processSingle(channel, buf); diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index cf9cc75f7..8556ddc69 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -45,20 +45,20 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { private static final int MSG_SHAKE_HAND_RESPONSE = 0x8000; private static final int MSG_IMAGE_SIZE = 0x0200; private static final int MSG_IMAGE_PACKET = 0x0201; - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; - + buf.readUnsignedShort(); // length int type = buf.readUnsignedShort(); - + if (type == MSG_SHAKE_HAND && channel != null) { - + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13); response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", Charset.defaultCharset())); response.writeByte(0); @@ -66,10 +66,10 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { response.writeShort(MSG_SHAKE_HAND_RESPONSE); response.writeByte(1); // status response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset())); - + channel.write(response, remoteAddress); } - + else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW || type == MSG_CONTROL_RESPONSE || @@ -89,7 +89,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); - + if (type == MSG_CONTROL_RESPONSE) { buf.readUnsignedInt(); // GIS ip buf.readUnsignedInt(); // GIS port diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java index cc3efa6a5..63bf84494 100644 --- a/src/org/traccar/protocol/OrionFrameDecoder.java +++ b/src/org/traccar/protocol/OrionFrameDecoder.java @@ -21,7 +21,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; public class OrionFrameDecoder extends FrameDecoder { - + private static final int TYPE_USERLOG = 0; private static final int TYPE_SYSLOG = 3; @@ -30,16 +30,16 @@ public class OrionFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + int length = 6; - + if (buf.readableBytes() >= length) { - + int type = buf.getUnsignedByte(buf.readerIndex() + 2) & 0x0f; - + if (type == TYPE_USERLOG) { if (buf.readableBytes() >= length + 5) { - + int index = buf.readerIndex() + 3; int count = buf.getUnsignedByte(index) & 0x0f; index += 5; @@ -53,7 +53,7 @@ public class OrionFrameDecoder extends FrameDecoder { index += logLength; length += logLength; } - + if (buf.readableBytes() >= length) { return buf.readBytes(length); } diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java index 63cc23878..647dc2aa7 100644 --- a/src/org/traccar/protocol/OrionProtocolDecoder.java +++ b/src/org/traccar/protocol/OrionProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -34,7 +34,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { public OrionProtocolDecoder(OrionProtocol protocol) { super(protocol); } - + private static final int TYPE_USERLOG = 0; private static final int TYPE_SYSLOG = 3; @@ -47,27 +47,27 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { channel.write(response); } } - + private static double convertCoordinate(int value) { double degrees = value / 1000000; double minutes = (value % 1000000) / 10000.0; return degrees + minutes / 60; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + buf.skipBytes(2); // header int type = buf.readUnsignedByte() & 0x0f; - + if (type == TYPE_USERLOG) { - + int header = buf.readUnsignedByte(); - + if ((header & 0x40) != 0) { sendResponse(channel, buf); } @@ -77,14 +77,14 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { } List positions = new LinkedList<>(); - + for (int i = 0; i < (header & 0x0f); i++) { - + // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); position.setProtocol(getProtocolName()); - + position.set(Event.KEY_EVENT, buf.readUnsignedByte()); buf.readUnsignedByte(); // length position.set(Event.KEY_FLAGS, buf.readUnsignedShort()); @@ -95,7 +95,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(buf.readShort()/ 10.0); position.setCourse(buf.readUnsignedShort()); position.setSpeed(buf.readUnsignedShort() * 0.0539957); - + // Date and time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -106,14 +106,14 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); - + // Accuracy int satellites = buf.readUnsignedByte(); position.set(Event.KEY_SATELLITES, satellites); position.setValid(satellites >= 3); positions.add(position); } - + return positions; } diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index cf447c579..47f96b32a 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -35,16 +35,16 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class OsmAndProtocolDecoder extends BaseProtocolDecoder { - + public OsmAndProtocolDecoder(OsmAndProtocol protocol) { super(protocol); } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + HttpRequest request = (HttpRequest) msg; QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); Map> params = decoder.getParameters(); diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java index 9e26594f2..b05e51c68 100644 --- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -38,7 +38,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class PiligrimProtocolDecoder extends BaseProtocolDecoder { - + public PiligrimProtocolDecoder(PiligrimProtocol protocol) { super(protocol); } @@ -61,26 +61,26 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + HttpRequest request = (HttpRequest) msg; String uri = request.getUri(); - + if (uri.startsWith("/config")) { sendResponse(channel, "CONFIG: OK"); - + } else if (uri.startsWith("/addlog")) { sendResponse(channel, "ADDLOG: OK"); - + } else if (uri.startsWith("/inform")) { sendResponse(channel, "INFORM: OK"); - + } else if (uri.startsWith("/bingps")) { sendResponse(channel, "BINGPS: OK"); - + // Identification QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); if (!identify(decoder.getParameters().get("imei").get(0), channel)) { @@ -89,19 +89,19 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { List positions = new LinkedList<>(); ChannelBuffer buf = request.getContent(); - + while (buf.readableBytes() > 2) { buf.readUnsignedByte(); // header int type = buf.readUnsignedByte(); buf.readUnsignedByte(); // length - + if (type == MSG_GPS || type == MSG_GPS_SENSORS) { - + Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -112,34 +112,34 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); - + // Latitude 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; longitude += buf.readUnsignedByte() / 600000.0; - + // Hemisphere int flags = buf.readUnsignedByte(); if ((flags & 0x01) != 0) latitude = -latitude; if ((flags & 0x02) != 0) longitude = -longitude; position.setLatitude(latitude); position.setLongitude(longitude); - + // Satellites int satellites = buf.readUnsignedByte(); position.set(Event.KEY_SATELLITES, satellites); position.setValid(satellites >= 3); - + // Speed position.setSpeed(buf.readUnsignedByte()); - + // Course double course = buf.readUnsignedByte() << 1; course += (flags >> 2) & 1; @@ -158,18 +158,18 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { double battery = buf.readUnsignedByte(); battery += buf.readUnsignedByte() << 8; position.set(Event.KEY_BATTERY, battery / 100); - + buf.skipBytes(6); - + } positions.add(position); - + } else if (type == MSG_EVENTS) { - + buf.skipBytes(13); } } - + return positions; } diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 328facdea..b8f3e48ca 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java index 9fef4a605..6a037ade0 100644 --- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,7 +45,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder { "(\\d+\\.?\\d*)?," + // Course "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) ".+"); - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -70,7 +70,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java index 58409ecbf..891265c84 100644 --- a/src/org/traccar/protocol/Pt502FrameDecoder.java +++ b/src/org/traccar/protocol/Pt502FrameDecoder.java @@ -22,9 +22,9 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; public class Pt502FrameDecoder extends FrameDecoder { - + private static final int BINARY_HEADER = 5; - + @Override protected Object decode( ChannelHandlerContext ctx, @@ -36,7 +36,7 @@ public class Pt502FrameDecoder extends FrameDecoder { } if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf && buf.getUnsignedByte(buf.readerIndex() + 1) == 0xfb) { - + int length = buf.getShort(buf.readerIndex() + 3); if (buf.readableBytes() >= length) { buf.skipBytes(BINARY_HEADER); @@ -44,16 +44,16 @@ public class Pt502FrameDecoder extends FrameDecoder { buf.skipBytes(2); return result; } - + } else { - + Integer index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), "\n"); if (index != null) { ChannelBuffer result = buf.readBytes(index - 1); buf.skipBytes(2); return result; } - + } return null; diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java index d1736302d..b46f9df6b 100644 --- a/src/org/traccar/protocol/RitiProtocolDecoder.java +++ b/src/org/traccar/protocol/RitiProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -71,14 +71,14 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder { position.set("mode", buf.readUnsignedByte()); position.set("command", buf.readUnsignedByte()); position.set(Event.KEY_POWER, buf.readUnsignedShort()); - + buf.skipBytes(5); buf.readUnsignedShort(); buf.readUnsignedShort(); - + position.set("distance", buf.readUnsignedInt()); position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); - + // Parse GPRMC Integer end = ChannelBufferTools.find(buf, buf.readerIndex(), buf.readerIndex() + 80, "*"); String gprmc = buf.toString( diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 0064798f3..ebb88faf4 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -28,13 +28,13 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class RuptelaProtocolDecoder extends BaseProtocolDecoder { - + public RuptelaProtocolDecoder(RuptelaProtocol protocol) { super(protocol); } private static final int COMMAND_RECORDS = 0x01; - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -51,7 +51,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { } int type = buf.readUnsignedByte(); - + if (type == COMMAND_RECORDS) { List positions = new LinkedList<>(); @@ -68,7 +68,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // timestamp extension buf.readUnsignedByte(); // priority (reserved) - + // Location position.setLongitude(buf.readInt() / 10000000.0); position.setLatitude(buf.readInt() / 10000000.0); @@ -120,7 +120,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { return positions; } - + return null; } diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java index 630fcb16c..5434a983e 100644 --- a/src/org/traccar/protocol/SanavProtocolDecoder.java +++ b/src/org/traccar/protocol/SanavProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 2f505154b..0879d86be 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.nio.charset.Charset; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; @@ -29,7 +29,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { - + private final long defaultMask; public SkypatrolProtocolDecoder(SkypatrolProtocol protocol) { diff --git a/src/org/traccar/protocol/Stl060FrameDecoder.java b/src/org/traccar/protocol/Stl060FrameDecoder.java index eb0894fb7..9eee11a02 100644 --- a/src/org/traccar/protocol/Stl060FrameDecoder.java +++ b/src/org/traccar/protocol/Stl060FrameDecoder.java @@ -25,21 +25,21 @@ import org.traccar.helper.ChannelBufferTools; public class Stl060FrameDecoder extends DelimiterBasedFrameDecoder { private static final byte delimiter[] = { (byte) '#' }; - + public Stl060FrameDecoder(int maxFrameLength) { super(maxFrameLength, ChannelBuffers.wrappedBuffer(delimiter)); } - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + ChannelBuffer result = (ChannelBuffer) super.decode(ctx, channel, buf); - + if (result != null) { - + Integer beginIndex = ChannelBufferTools.find( result, 0, result.readableBytes(), "$"); if (beginIndex == null) { diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index df67c17d4..86e96dfbc 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -91,7 +91,7 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 3de785f9d..84f84cdfa 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -66,7 +66,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); int index = 1; - + String type = parser.group(index++); if (type != null && (type.equals("Alert") || type.equals("Emergency"))) { position.set(Event.KEY_ALARM, true); @@ -77,7 +77,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Version position.set(Event.KEY_VERSION, parser.group(index++)); @@ -91,7 +91,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Cell position.set(Event.KEY_CELL, parser.group(index++)); @@ -105,7 +105,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.valueOf(parser.group(index++))); - + // Battery position.set(Event.KEY_BATTERY, parser.group(index++)); diff --git a/src/org/traccar/protocol/SuntechProtocolEncoder.java b/src/org/traccar/protocol/SuntechProtocolEncoder.java index 2b5165995..271718643 100644 --- a/src/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/org/traccar/protocol/SuntechProtocolEncoder.java @@ -29,8 +29,8 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "SA200CMD;{%s};02;Disable1\r", Command.KEY_UNIQUE_ID); } - + return null; } - + } diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index 2771d1d8e..b67fac903 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,7 +63,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { "(\\d+\\.?\\d*)?," + // Speed "(\\d+\\.?\\d*)?," + // Course ".+"); - + private static final Pattern patternTRCCR = Pattern.compile( "\\$TRCCR," + "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) @@ -83,7 +83,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { throws Exception { String sentence = (String) msg; - + if (!sentence.startsWith("$") && sentence.contains("$")) { int index = sentence.indexOf("$"); String id = sentence.substring(0, index); diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 252f4e712..180be3268 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import java.util.regex.Matcher; @@ -29,7 +29,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; public class TaipProtocolDecoder extends BaseProtocolDecoder { - + private final boolean sendResponse; public TaipProtocolDecoder(TaipProtocol protocol, boolean sendResponse) { @@ -65,18 +65,18 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { return new Date(millis); } - + private Date getTime(long seconds) { Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.set(Calendar.HOUR_OF_DAY, 0); time.set(Calendar.MINUTE, 0); time.set(Calendar.SECOND, 0); time.set(Calendar.MILLISECOND, 0); - + long millis = time.getTimeInMillis() + seconds * 1000; - + long diff = System.currentTimeMillis() - millis; - + if (diff > 12 * 60 * 60 * 1000) { millis += 24 * 60 * 60 * 1000; } else if (diff < -12 * 60 * 60 * 1000) { @@ -85,14 +85,14 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { return new Date(millis); } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; - + // Find message start int beginIndex = sentence.indexOf('>'); if (beginIndex != -1) { @@ -134,7 +134,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); Integer index = 1; - + // Time String week = parser.group(index++); String day = parser.group(index++); @@ -167,11 +167,11 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { String longitude = parser.group(index) + '.' + parser.group(index + 1); index += 2; position.setLongitude(Double.valueOf(longitude)); - + // Speed and Course position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(parser.group(index++)))); position.setCourse(Double.valueOf(parser.group(index++))); - + // Validity position.setValid(Integer.valueOf(parser.group(index++)) != 0); return position; diff --git a/src/org/traccar/protocol/TelikProtocolDecoder.java b/src/org/traccar/protocol/TelikProtocolDecoder.java index e70b4e569..37edf6d1f 100644 --- a/src/org/traccar/protocol/TelikProtocolDecoder.java +++ b/src/org/traccar/protocol/TelikProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -74,7 +74,7 @@ public class TelikProtocolDecoder extends BaseProtocolDecoder { // Message type position.set(Event.KEY_TYPE, parser.group(index++)); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -85,7 +85,7 @@ public class TelikProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Location position.setLongitude(Double.valueOf(parser.group(index++)) / 10000); position.setLatitude(Double.valueOf(parser.group(index++)) / 10000); diff --git a/src/org/traccar/protocol/TeltonikaFrameDecoder.java b/src/org/traccar/protocol/TeltonikaFrameDecoder.java index 7407d9fdb..f8add090b 100644 --- a/src/org/traccar/protocol/TeltonikaFrameDecoder.java +++ b/src/org/traccar/protocol/TeltonikaFrameDecoder.java @@ -23,13 +23,13 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class TeltonikaFrameDecoder extends FrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 12; - + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + // Check minimum length if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; @@ -47,7 +47,7 @@ public class TeltonikaFrameDecoder extends FrameDecoder { return buf.readBytes(dataLength + 12); } } - + return null; } diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index e052b10d5..e4966aabe 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { - + public TeltonikaProtocolDecoder(TeltonikaProtocol protocol) { super(protocol); } @@ -51,74 +51,74 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { private static final int CODEC_GH3000 = 0x07; private static final int CODEC_FM4X00 = 0x08; private static final int CODEC_12 = 0x0C; - + private List parseLocation(Channel channel, ChannelBuffer buf) { List positions = new LinkedList<>(); - + buf.skipBytes(4); // marker buf.readUnsignedInt(); // data length int codec = buf.readUnsignedByte(); // codec - + if (codec == CODEC_12) { // TODO: decode serial port data return null; } - + int count = buf.readUnsignedByte(); - + for (int i = 0; i < count; i++) { Position position = new Position(); position.setProtocol(getProtocolName()); - + position.setDeviceId(getDeviceId()); - + int globalMask = 0x0f; - + if (codec == CODEC_GH3000) { long time = buf.readUnsignedInt() & 0x3fffffff; time += 1167609600; // 2007-01-01 00:00:00 position.setTime(new Date(time * 1000)); - + globalMask = buf.readUnsignedByte(); if (!BitUtil.check(globalMask, 0)) { return null; } - + int locationMask = buf.readUnsignedByte(); - + if (BitUtil.check(locationMask, 0)) { position.setLatitude(buf.readFloat()); position.setLongitude(buf.readFloat()); } - + if (BitUtil.check(locationMask, 1)) { position.setAltitude(buf.readUnsignedShort()); } - + if (BitUtil.check(locationMask, 2)) { position.setCourse(buf.readUnsignedByte() * 360.0 / 256); } - + if (BitUtil.check(locationMask, 3)) { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); } - + if (BitUtil.check(locationMask, 4)) { int satellites = buf.readUnsignedByte(); position.set(Event.KEY_SATELLITES, satellites); position.setValid(satellites >= 3); } - + if (BitUtil.check(locationMask, 5)) { position.set("area", buf.readUnsignedShort()); position.set(Event.KEY_CELL, buf.readUnsignedShort()); } - + if (BitUtil.check(locationMask, 6)) { position.set(Event.KEY_GSM, buf.readUnsignedByte()); } - + if (BitUtil.check(locationMask, 7)) { position.set("operator", buf.readUnsignedInt()); } @@ -146,7 +146,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // total IO data records } - + // Read 1 byte data if (BitUtil.check(globalMask, 1)) { int cnt = buf.readUnsignedByte(); @@ -185,29 +185,29 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } positions.add(position); } - + if (channel != null) { ChannelBuffer response = ChannelBuffers.directBuffer(4); response.writeInt(count); channel.write(response); } - + return positions; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; - + if (buf.getUnsignedShort(0) > 0) { parseIdentification(channel, buf); } else { return parseLocation(channel, buf); } - + return null; } diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index 47cd396cd..7e2dcb6a4 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 72fdc10b7..f2a561050 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,7 +62,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { if (beginIndex != -1) { sentence = sentence.substring(beginIndex + 1); } - + // Send response if (channel != null) { String id = sentence.substring(0, 12); @@ -135,7 +135,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.parseDouble(parser.group(index++))); - + // State String status = parser.group(index++); // binary status if (status != null) { diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index a81782deb..5d8ca654e 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -78,10 +78,10 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { // Get status String status = parser.group(2); - + String[] messages = sentence.substring(sentence.indexOf('\n') + 1).split("\r\n"); List positions = new LinkedList<>(); - + for (String message : messages) { parser = patternPosition.matcher(message); if (parser.matches()) { @@ -90,7 +90,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); Integer index = 1; - + // Cell position.set(Event.KEY_CELL, parser.group(index++)); @@ -134,7 +134,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Status position.set(Event.KEY_STATUS, status); positions.add(position); diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index d2f028ad5..bd8175a56 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index b6bb0f3e3..b87198481 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -156,10 +156,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Alarm type position.set(Event.KEY_ALARM, parser.group(index++)); - + if (pattern == pattern1 || pattern == pattern2) { // Time @@ -236,7 +236,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { // Odometer position.set(Event.KEY_ODOMETER, parser.group(index++)); - + } else if (pattern == pattern3) { // Time @@ -249,7 +249,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // IO Status position.set(Event.PREFIX_IO + 1, parser.group(index++)); @@ -297,9 +297,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { longitude += Double.valueOf(parser.group(index++)) / 60; if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; position.setLongitude(longitude); - + } - + if (channel != null) { channel.write("ACK OK\r\n"); } diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java index 935ab1b64..56d6bfa92 100644 --- a/src/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/org/traccar/protocol/TotemProtocolEncoder.java @@ -15,18 +15,18 @@ * limitations under the License. */ package org.traccar.protocol; - -import org.traccar.StringProtocolEncoder; + +import org.traccar.StringProtocolEncoder; import org.traccar.model.Command; public class TotemProtocolEncoder extends StringProtocolEncoder{ - + @Override protected Object encodeCommand(Command command) { // Temporary put default password command.set(Command.KEY_DEVICE_PASSWORD, "000000"); - + switch (command.getType()) { //Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8 case Command.TYPE_ENGINE_STOP: @@ -34,7 +34,7 @@ public class TotemProtocolEncoder extends StringProtocolEncoder{ case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "*{%s},025,C,0#", Command.KEY_DEVICE_PASSWORD); } - + return null; } } diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index cdfb07549..7afd905e4 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java index a6c24599b..79abdc5b1 100644 --- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java +++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -28,7 +28,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class TrackboxProtocolDecoder extends BaseProtocolDecoder { - + public TrackboxProtocolDecoder(TrackboxProtocol protocol) { super(protocol); } @@ -51,7 +51,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { channel.write("=OK=\r\n"); } } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) @@ -65,7 +65,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel); } } - + else { // Parse message Matcher parser = pattern.matcher(sentence); @@ -100,13 +100,13 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { longitude += Double.valueOf(parser.group(index++)) / 60; if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; position.setLongitude(longitude); - + // HDOP position.set(Event.KEY_HDOP, parser.group(index++)); // Altitude position.setAltitude(Double.valueOf(parser.group(index++))); - + // Validity int fix = Integer.valueOf(parser.group(index++)); position.set(Event.KEY_GPS, fix); @@ -130,7 +130,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { return position; } - + return null; } diff --git a/src/org/traccar/protocol/TramigoFrameDecoder.java b/src/org/traccar/protocol/TramigoFrameDecoder.java index 4055d2255..ff2109136 100644 --- a/src/org/traccar/protocol/TramigoFrameDecoder.java +++ b/src/org/traccar/protocol/TramigoFrameDecoder.java @@ -33,7 +33,7 @@ public class TramigoFrameDecoder extends LengthFieldBasedFrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + if (buf.readableBytes() < 20) { return null; } @@ -43,7 +43,7 @@ public class TramigoFrameDecoder extends LengthFieldBasedFrameDecoder { int length = buf.readableBytes(); byte bytes[] = new byte[length]; buf.getBytes(buf.readerIndex(), bytes); - + ChannelBuffer result = (ChannelBuffer) super.decode( ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes)); if (result != null) { diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java index 8a1e9046d..893e32a92 100644 --- a/src/org/traccar/protocol/TramigoProtocolDecoder.java +++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java @@ -27,7 +27,7 @@ import java.nio.charset.Charset; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.regex.Matcher; diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index 0936732c5..a16bd4e4b 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -51,60 +51,60 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + buf.readUnsignedByte(); // protocol buf.readUnsignedShort(); // length int index = buf.readUnsignedByte() >> 3; - + if (channel != null) { ChannelBuffer response = ChannelBuffers.copiedBuffer( "^" + index, Charset.defaultCharset()); channel.write(response, remoteAddress); } - + String id = String.valueOf(buf.readUnsignedInt()); if (!identify(id, channel, remoteAddress)) { return null; } List positions = new LinkedList<>(); - + while (buf.readableBytes() > 2) { - + Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - + int end = buf.readerIndex() + buf.readUnsignedByte(); - + position.setTime(new Date(buf.readUnsignedInt() * 1000)); - + int flags = buf.readUnsignedByte(); position.set(Event.KEY_SATELLITES, BitUtil.range(flags, 2)); position.setValid(BitUtil.range(flags, 0, 2) > 0); - + // Latitude double lat = buf.readUnsignedMedium(); lat = lat * -180 / 16777216 + 90; position.setLatitude(lat); - + // Longitude double lon = buf.readUnsignedMedium(); lon = lon * 360 / 16777216 - 180; position.setLongitude(lon); - + // Status flags = buf.readUnsignedByte(); position.set(Event.KEY_IGNITION, BitUtil.check(flags, 0)); position.set(Event.KEY_GSM, BitUtil.range(flags, 2, 3)); position.setCourse((BitUtil.range(flags, 5) * 45 + 180) % 360); - + // Speed int speed = buf.readUnsignedByte(); if (speed < 250) { position.setSpeed(UnitsConverter.knotsFromKph(speed)); } - + while (buf.readerIndex() < end) { int type = buf.readUnsignedByte(); @@ -193,7 +193,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } - + return positions; } diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index ed463c109..1fe32af7a 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -46,32 +46,32 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { } buf.readUnsignedShort(); // model buf.readUnsignedInt(); // firmware - + String imei = ChannelBufferTools.readHexString(buf, 16).substring(1); if (!identify(imei, channel)) { return null; } - + buf.skipBytes(6); // device time Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - + // GPS info int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; - + if (blockLength == 0) { return null; } - + position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); - + double lat = buf.readUnsignedInt() / 600000.0; double lon = buf.readUnsignedInt() / 600000.0; - + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); @@ -81,40 +81,40 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); - + position.setSpeed(buf.readUnsignedShort() * 0.01); - + position.set(Event.KEY_ODOMETER, buf.readUnsignedMedium()); - + int flags = buf.readUnsignedShort(); position.setCourse(BitUtil.range(flags, 0, 9)); position.setLatitude(BitUtil.check(flags, 10) ? lat : -lat); position.setLongitude(BitUtil.check(flags, 9) ? -lon : lon); position.setValid(BitUtil.check(flags, 11)); - + buf.readerIndex(blockEnd); - + // LBS info - + blockLength = buf.readUnsignedShort(); blockEnd = buf.readerIndex() + blockLength; - + if (blockLength > 0) { - + position.set(Event.KEY_LAC, buf.readUnsignedShort()); position.set(Event.KEY_CELL, buf.readUnsignedShort()); - + } - + buf.readerIndex(blockEnd); - + // Status info - + blockLength = buf.readUnsignedShort(); blockEnd = buf.readerIndex() + blockLength; - + if (blockLength > 0) { - + position.set(Event.KEY_ALARM, buf.readUnsignedByte()); buf.readUnsignedByte(); // terminal info position.set(Event.PREFIX_IO + 1, buf.readUnsignedShort()); @@ -125,26 +125,26 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort()); position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort()); position.set(Event.PREFIX_TEMP + 1, buf.readUnsignedShort()); - + } - + buf.readerIndex(blockEnd); - + // Cards - + int index = 1; for (int i = 0; i < 4; i++) { - + blockLength = buf.readUnsignedShort(); blockEnd = buf.readerIndex() + blockLength; - + if (blockLength > 0) { - + int count = buf.readUnsignedByte(); for (int j = 0; j < count; j++) { int length = buf.readUnsignedByte(); - + boolean odd = length % 2 != 0; String num = ChannelBufferTools.readHexString(buf, odd ? length + 1 : length); @@ -154,34 +154,34 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { } position.set("card" + index, num); - + } } - + buf.readerIndex(blockEnd); - + } - + // Temperature - + buf.skipBytes(buf.readUnsignedShort()); - + // Lock - + buf.skipBytes(buf.readUnsignedShort()); // Passengers - + blockLength = buf.readUnsignedShort(); blockEnd = buf.readerIndex() + blockLength; - + if (blockLength > 0) { - + position.set("passengers-on", buf.readUnsignedMedium()); position.set("passengers-off", buf.readUnsignedMedium()); - + } - + buf.readerIndex(blockEnd); return position; diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java index 6eff29a08..f0671c717 100644 --- a/src/org/traccar/protocol/UlbotechFrameDecoder.java +++ b/src/org/traccar/protocol/UlbotechFrameDecoder.java @@ -28,7 +28,7 @@ public class UlbotechFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + if (buf.readableBytes() < 2) { return null; } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index b44e1d850..6c332102d 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -81,7 +81,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { seconds += 946684800l; // 2000-01-01 00:00 seconds -= timeZone; position.setTime(new Date(seconds * 1000)); - + boolean hasLocation = false; while (buf.readableBytes() > 3) { diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index 5036817a5..f24076c9b 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -59,7 +59,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; sentence = sentence.trim(); - + // Detect device ID if (sentence.length() == 16) { String imei = sentence.substring(1, sentence.length()); @@ -145,7 +145,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); return position; } - + return null; } diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 9a62f4e5c..d09673f00 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 7d8382ad6..ef6ebeab8 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -66,9 +66,9 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { channel.write(response.toString()); } } - + private Position decodePosition(String substring) { - + // Parse message Matcher parser = pattern.matcher(substring); if (!hasDeviceId() || !parser.matches()) { @@ -183,7 +183,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { else if (sentence.startsWith("#P#")) { sendResponse(channel, "#AP#", null); } - + // Parse message else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) { @@ -195,9 +195,9 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { return position; } } - + else if (sentence.startsWith("#B#")) { - + String[] messages = sentence.substring(sentence.indexOf('#', 1) + 1).split("\\|"); List positions = new LinkedList<>(); diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java index 09971c0d9..1a66c9373 100644 --- a/src/org/traccar/protocol/WondexFrameDecoder.java +++ b/src/org/traccar/protocol/WondexFrameDecoder.java @@ -22,7 +22,7 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; public class WondexFrameDecoder extends FrameDecoder { - + private static final int KEEP_ALIVE_LENGTH = 8; @Override @@ -30,7 +30,7 @@ public class WondexFrameDecoder extends FrameDecoder { ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - + if (buf.readableBytes() < KEEP_ALIVE_LENGTH) { return null; } @@ -51,7 +51,7 @@ public class WondexFrameDecoder extends FrameDecoder { buf.skipBytes(2); return frame; } - + } return null; diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 4c35321cc..2a3d43b5b 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -97,23 +97,23 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); - + // Event position.set(Event.KEY_EVENT, parser.group(index++)); - + // Battery position.set(Event.KEY_BATTERY, parser.group(index++)); - + // Odometer position.set(Event.KEY_ODOMETER, parser.group(index++)); - + // Input position.set(Event.KEY_INPUT, parser.group(index++)); - + // ADC position.set(Event.PREFIX_ADC + 1, parser.group(index++)); position.set(Event.PREFIX_ADC + 2, parser.group(index++)); - + // Output position.set(Event.KEY_OUTPUT, parser.group(index++)); return position; diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 95676d2e2..b248e083e 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 81a3ac4c5..8e070694f 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -77,7 +77,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDeviceId()); position.set(Event.KEY_EVENT, parser.group(index++)); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -102,7 +102,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_BATTERY, parser.group(index++)); position.set(Event.KEY_GSM, parser.group(index++)); position.set(Event.KEY_ODOMETER, parser.group(index++)); - + // Validity position.setValid(Integer.valueOf(parser.group(index++)) == 1); diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java index b2056ea14..a35318532 100644 --- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java @@ -23,7 +23,7 @@ import org.traccar.model.Position; import java.text.ParseException; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index 7e3001f86..c2d3058aa 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -16,7 +16,7 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,17 +68,17 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { if (end == -1) { end = sentence.length(); } - + channel.write("%AT+SN=" + sentence.substring(start, end)); return null; } - + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { return null; } - + // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); @@ -90,7 +90,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { return null; } position.setDeviceId(getDeviceId()); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -113,7 +113,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { Double latitude = Double.valueOf(parser.group(index++)); if (hemisphere.compareTo("S") == 0) latitude = -latitude; position.setLatitude(latitude); - + // Altitude String altitude = parser.group(index++); if (altitude != null) { @@ -125,15 +125,15 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { // Course position.setCourse(Double.valueOf(parser.group(index++))); - + // Satellites int satellites = Integer.valueOf(parser.group(index++)); position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); - + // Report identifier String reportId = parser.group(index++); - + // Status position.set(Event.KEY_STATUS, parser.group(index++)); -- cgit v1.2.3