diff options
Diffstat (limited to 'src/org')
21 files changed, 185 insertions, 293 deletions
diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java index 954f3deac..d32fec61a 100644 --- a/src/org/traccar/model/Extensible.java +++ b/src/org/traccar/model/Extensible.java @@ -19,7 +19,7 @@ import java.util.LinkedHashMap; import java.util.Map; public abstract class Extensible { - + private Map<String, Object> attributes = new LinkedHashMap<>(); public Map<String, Object> getAttributes() { diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 865a34e99..a04aa01af 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -15,9 +15,9 @@ */ package org.traccar.protocol; +import java.net.SocketAddress; import java.nio.ByteOrder; import java.nio.charset.Charset; -import java.net.SocketAddress; import java.util.Calendar; import java.util.LinkedList; import java.util.List; @@ -109,23 +109,24 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { } if (type == MSG_TRACKER_ID_EXT) { + buf.readUnsignedInt(); // id int length = buf.readUnsignedShort(); buf.skipBytes(length); length = buf.readUnsignedShort(); identify(buf.readBytes(length).toString(Charset.defaultCharset()), channel); - } - else if (type == MSG_LAST_LOG_INDEX) { + } else if (type == MSG_LAST_LOG_INDEX) { + long index = buf.readUnsignedInt(); if (index > 0) { newIndex = index; requestArchive(channel); } - } - // Position - else if (hasDeviceId() && (type == MSG_CURRENT_GPS_DATA || type == MSG_STATE_FULL_INFO_T104 || type == MSG_LOG_RECORDS)) { + } else if (hasDeviceId() + && (type == MSG_CURRENT_GPS_DATA || type == MSG_STATE_FULL_INFO_T104 || type == MSG_LOG_RECORDS)) { + List<Position> positions = new LinkedList<>(); int recordCount = 1; diff --git a/src/org/traccar/protocol/AplicomFrameDecoder.java b/src/org/traccar/protocol/AplicomFrameDecoder.java index 85fb5404c..8a896535c 100644 --- a/src/org/traccar/protocol/AplicomFrameDecoder.java +++ b/src/org/traccar/protocol/AplicomFrameDecoder.java @@ -21,13 +21,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder;
public class AplicomFrameDecoder extends FrameDecoder {
-
+
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
// Check minimum length
if (buf.readableBytes() < 11) {
return null;
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index 2b122dfa2..056677c53 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -58,17 +58,14 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { int index = sentence.indexOf(',', 2) + 1; String id = sentence.substring(index, sentence.indexOf(',', index)); identify(id, channel); - } - else if (sentence.startsWith("E,")) { + } else if (sentence.startsWith("E,")) { if (channel != null) { channel.write("A," + sentence.substring(2) + "\r"); } - } - - else if (sentence.startsWith("L,") && hasDeviceId()) { + } else if (sentence.startsWith("L,") && hasDeviceId()) { // Parse message Matcher parser = PATTERN.matcher(sentence); diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index 0648dd29f..daa8d093b 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -61,6 +61,92 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { channel.write(response, remoteAddress); } } + + private Position decodePosition(int type, ChannelBuffer buf) { + + Position position = new Position(); + position.setDeviceId(getDeviceId()); + position.setProtocol(getProtocolName()); + + // Location data + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + if (type != MSG_MINI_EVENT_REPORT) { + buf.readUnsignedInt(); // fix time + } + position.setLatitude(buf.readInt() * 0.0000001); + position.setLongitude(buf.readInt() * 0.0000001); + if (type != MSG_MINI_EVENT_REPORT) { + position.setAltitude(buf.readInt() * 0.01); + position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt())); + } + position.setCourse(buf.readShort()); + if (type == MSG_MINI_EVENT_REPORT) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + + // Fix status + if (type == MSG_MINI_EVENT_REPORT) { + position.set(Event.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf); + position.setValid((buf.readUnsignedByte() & 0x20) == 0); + } else { + position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); + position.setValid((buf.readUnsignedByte() & 0x08) == 0); + } + + if (type != MSG_MINI_EVENT_REPORT) { + + // Carrier + position.set("carrier", buf.readUnsignedShort()); + + // Cell signal + position.set(Event.KEY_GSM, buf.readShort()); + + } + + // Modem state + position.set("modem", buf.readUnsignedByte()); + + // HDOP + if (type != MSG_MINI_EVENT_REPORT) { + position.set(Event.KEY_HDOP, buf.readUnsignedByte()); + } + + // Inputs + position.set(Event.KEY_INPUT, buf.readUnsignedByte()); + + // Unit status + if (type != MSG_MINI_EVENT_REPORT) { + position.set(Event.KEY_STATUS, buf.readUnsignedByte()); + } + + // Event code + if (type == MSG_EVENT_REPORT || type == MSG_MINI_EVENT_REPORT) { + if (type != MSG_MINI_EVENT_REPORT) { + buf.readUnsignedByte(); // event index + } + position.set(Event.KEY_EVENT, buf.readUnsignedByte()); + } + + // Accumulators + int accCount = buf.readUnsignedByte(); + int accType = accCount >> 6; + accCount &= 0x3f; + + if (type != MSG_MINI_EVENT_REPORT) { + buf.readUnsignedByte(); // reserved + } + + if (accType == 1) { + buf.readUnsignedInt(); // threshold + buf.readUnsignedInt(); // mask + } + + for (int i = 0; i < accCount; i++) { + position.set("acc" + i, buf.readUnsignedInt()); + } + + return position; + } @Override protected Object decode( @@ -132,93 +218,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, remoteAddress, type, index, 0); } - if (type == MSG_EVENT_REPORT || - type == MSG_LOCATE_REPORT || - type == MSG_MINI_EVENT_REPORT) { - - // Create new position - Position position = new Position(); - position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocolName()); - - // Location data - position.setTime(new Date(buf.readUnsignedInt() * 1000)); - if (type != MSG_MINI_EVENT_REPORT) { - buf.readUnsignedInt(); // fix time - } - position.setLatitude(buf.readInt() * 0.0000001); - position.setLongitude(buf.readInt() * 0.0000001); - if (type != MSG_MINI_EVENT_REPORT) { - position.setAltitude(buf.readInt() * 0.01); - position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt())); - } - position.setCourse(buf.readShort()); - if (type == MSG_MINI_EVENT_REPORT) { - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - } - - // Fix status - if (type == MSG_MINI_EVENT_REPORT) { - position.set(Event.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf); - position.setValid((buf.readUnsignedByte() & 0x20) == 0); - } else { - position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); - position.setValid((buf.readUnsignedByte() & 0x08) == 0); - } - - if (type != MSG_MINI_EVENT_REPORT) { - - // Carrier - position.set("carrier", buf.readUnsignedShort()); - - // Cell signal - position.set(Event.KEY_GSM, buf.readShort()); - - } - - // Modem state - position.set("modem", buf.readUnsignedByte()); - - // HDOP - if (type != MSG_MINI_EVENT_REPORT) { - position.set(Event.KEY_HDOP, buf.readUnsignedByte()); - } - - // Inputs - position.set(Event.KEY_INPUT, buf.readUnsignedByte()); - - // Unit status - if (type != MSG_MINI_EVENT_REPORT) { - position.set(Event.KEY_STATUS, buf.readUnsignedByte()); - } - - // Event code - if (type == MSG_EVENT_REPORT || type == MSG_MINI_EVENT_REPORT) { - if (type != MSG_MINI_EVENT_REPORT) { - buf.readUnsignedByte(); // event index - } - position.set(Event.KEY_EVENT, buf.readUnsignedByte()); - } - - // Accumulators - int accCount = buf.readUnsignedByte(); - int accType = accCount >> 6; - accCount &= 0x3f; - - if (type != MSG_MINI_EVENT_REPORT) { - buf.readUnsignedByte(); // reserved - } - - if (accType == 1) { - buf.readUnsignedInt(); // threshold - buf.readUnsignedInt(); // mask - } - - for (int i = 0; i < accCount; i++) { - position.set("acc" + i, buf.readUnsignedInt()); - } - return position; - + if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) { + return decodePosition(type, buf); } return null; diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 41c415c78..9183dadbd 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -70,14 +70,11 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } 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)) { + } else if (hasDeviceId() + && (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS)) { // Create new position Position position = new Position(); @@ -109,64 +106,6 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { return position; } - /* - if (type == MSG_HEARTBEAT) { - if (channel != null) { - byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A}; - channel.write(ChannelBuffers.wrappedBuffer(response)); - } - } - - else if (type == MSG_DATA) { - - // Create new position - Position position = new Position(); - ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gt02"); - position.set(Event.KEY_INDEX, index); - - // Get device id - try { - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - } catch(Exception error) { - Log.warning("Unknown device - " + imei); - } - - // Date and time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); - time.set(Calendar.MONTH, buf.readUnsignedByte() - 1); - time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); - time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte()); - time.set(Calendar.MINUTE, buf.readUnsignedByte()); - time.set(Calendar.SECOND, buf.readUnsignedByte()); - position.setTime(time.getTime()); - - // Latitude - double latitude = buf.readUnsignedInt() / (60.0 * 30000.0); - - // Longitude - double longitude = buf.readUnsignedInt() / (60.0 * 30000.0); - - // Speed - position.setSpeed(buf.readUnsignedByte()); - - // Course - position.setCourse(buf.readUnsignedShort()); - - buf.skipBytes(3); // reserved - - // Flags - long flags = buf.readUnsignedInt(); - position.setValid((flags & 0x1) == 0x1); - if ((flags & 0x2) == 0) latitude = -latitude; - if ((flags & 0x4) == 0) longitude = -longitude; - - position.setLatitude(latitude); - position.setLongitude(longitude); - return position; - }*/ - return null; } diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index 5926e8963..451aff7f2 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.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;
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index de7cc25e5..ad6a5a574 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -130,10 +130,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_HDOP, parser.group(index++)); position.set(Event.KEY_ODOMETER, parser.group(index++)); - + position.set(Event.KEY_POWER, parser.group(index++)); position.set(Event.KEY_BATTERY, parser.group(index++)); - + String status = parser.group(index++); if (status != null) { position.set(Event.KEY_IGNITION, BitUtil.check(Integer.parseInt(status, 16), 13)); @@ -145,11 +145,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; - + if (channel != null) { channel.write("1234"); } diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 97344673c..cdd3f5bb6 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -57,8 +57,9 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - // Process login if (sentence.startsWith("$FRLIN,")) { + + // Login int beginIndex = sentence.indexOf(',', 7); if (beginIndex != -1) { beginIndex += 1; @@ -78,15 +79,13 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { } else { send(channel, "$FRERR,AuthError,Parse error"); } - } - // Protocol version check - else if (sentence.startsWith("$FRVER,")) { + } else if (sentence.startsWith("$FRVER,")) { + + // Version check send(channel, "$FRVER,1,0,GpsGate Server 1.0"); - } - // Process data - else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) { + } else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) { // Parse message Matcher parser = PATTERN.matcher(sentence); diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 5d082e381..76756f41d 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -18,11 +18,9 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.util.Calendar; import java.util.TimeZone; - import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; - import org.traccar.BaseProtocolDecoder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; @@ -68,13 +66,13 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); if (type == MSG_HEARTBEAT) { + if (channel != null) { byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A}; channel.write(ChannelBuffers.wrappedBuffer(response)); } - } - else if (type == MSG_DATA) { + } else if (type == MSG_DATA) { // Create new position Position position = new Position(); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 5738b5eda..2a5cae6c4 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -231,9 +231,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_INDEX, index); sendResponse(channel, type, index); return position; - } - else { + } else { + buf.skipBytes(dataLength); if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) { sendResponse(channel, type, buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java index e74b87cec..da41daa0e 100644 --- a/src/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/org/traccar/protocol/KhdProtocolDecoder.java @@ -18,11 +18,9 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.util.Calendar; import java.util.TimeZone; - import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; - import org.traccar.BaseProtocolDecoder; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Checksum; @@ -122,9 +120,8 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { // TODO: parse extra data return position; - } - else if (type == MSG_LOGIN && channel != null) { + } else if (type == MSG_LOGIN && channel != null) { buf.skipBytes(4); // serial number buf.readByte(); // reserved diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 9a3ac836d..0bb9aee60 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -53,15 +53,14 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - // Identification if (sentence.startsWith("!1")) { + + // Identification identify(sentence.substring(3, sentence.length()), channel); - } - // Location - else if (sentence.startsWith("!D") && hasDeviceId()) { + } else if (sentence.startsWith("!D") && hasDeviceId()) { - // Parse message + // Location Matcher parser = PATTERN.matcher(sentence); if (!parser.matches()) { return null; @@ -104,6 +103,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { // Satellites position.set(Event.KEY_SATELLITES, parser.group(index++)); + return position; } diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index a5a7d75a4..bca741c9f 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -66,9 +66,8 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset())); channel.write(response, remoteAddress); - } - else if (type == MSG_UPLOAD_POSITION || + } else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) { diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 08d2b12bc..bf7c649ce 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -70,8 +70,8 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedShort(); buf.readUnsignedShort(); // length - // Authentication if (type == MSG_IDENT || type == MSG_IDENT_FULL) { + buf.readUnsignedInt(); // id int length = buf.readUnsignedShort(); buf.skipBytes(length); @@ -80,10 +80,9 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { length = buf.readUnsignedShort(); String imei = buf.readBytes(length).toString(Charset.defaultCharset()); identify(imei, channel); - } - // Position - else if (hasDeviceId() && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) { + } else if (hasDeviceId() && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) { + List<Position> positions = new LinkedList<>(); int recordCount = 1; diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 4027a54b2..41336dc05 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.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;
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index da379ef58..fcb7d34ab 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -94,33 +94,17 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { sentence = sentence.substring(index); } - // Identification if (sentence.startsWith("$PGID")) { identify(sentence.substring(6, sentence.length() - 3), channel); - } - - // Identification - else if (sentence.startsWith("$PCPTI")) { + } else if (sentence.startsWith("$PCPTI")) { identify(sentence.substring(7, sentence.indexOf(",", 7)), channel); - } - - // Identification - else if (sentence.startsWith("IMEI")) { + } else if (sentence.startsWith("IMEI")) { identify(sentence.substring(5, sentence.length()), channel); - } - - // Identification - else if (sentence.startsWith("$GPFID")) { + } else if (sentence.startsWith("$GPFID")) { identify(sentence.substring(6, sentence.length()), channel); - } - - // Identification - else if (Character.isDigit(sentence.charAt(0)) && sentence.length() == 15) { + } else if (Character.isDigit(sentence.charAt(0)) && sentence.length() == 15) { identify(sentence, channel); - } - - // Location - else if (sentence.startsWith("$GPRMC") && hasDeviceId()) { + } else if (sentence.startsWith("$GPRMC") && hasDeviceId()) { // Send response if (channel != null) { @@ -180,10 +164,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++))); position.setTime(time.getTime()); return position; - } - // Location - else if (sentence.startsWith("$GPGGA") && hasDeviceId()) { + } else if (sentence.startsWith("$GPGGA") && hasDeviceId()) { // Parse message Matcher parser = PATTERN_GPGGA.matcher(sentence); @@ -221,10 +203,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; position.setLongitude(longitude); return position; - } - // Location - else if (sentence.startsWith("$GPRMA") && hasDeviceId()) { + } else if (sentence.startsWith("$GPRMA") && hasDeviceId()) { // Parse message Matcher parser = PATTERN_GPRMA.matcher(sentence); @@ -269,10 +249,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(Double.parseDouble(course)); } return position; - } - // Location - else if (sentence.startsWith("$TRCCR") && hasDeviceId()) { + } else if (sentence.startsWith("$TRCCR") && hasDeviceId()) { // Parse message Matcher parser = PATTERN_TRCCR.matcher(sentence); diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index f9db1a9e7..c052f09ed 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -49,26 +49,22 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - // Login if (sentence.startsWith("[!")) { + + // Login if (!identify(sentence.substring(14, 14 + 15), channel)) { return null; } - if (channel != null) { channel.write("[”0000000001" + sentence.substring(13) + "]"); } - } - // Quit - else if (sentence.startsWith("[#")) { - // TODO: Send response - } + } else if (sentence.startsWith("[#")) { - // Parse message - else if (hasDeviceId()) { + // TODO: EXIT Send response + + } else if (hasDeviceId()) { - // Parse message Matcher parser = PATTERN.matcher(sentence); if (!parser.matches()) { return null; diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java index 30b327df6..58795d4d3 100644 --- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java +++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java @@ -58,21 +58,20 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; if (sentence.startsWith("a=connect")) { + String id = sentence.substring(sentence.indexOf("i=") + 2); if (identify(id, channel)) { sendResponse(channel); } - } + + } else { - else { - // Parse message Matcher parser = PATTERN.matcher(sentence); if (!parser.matches()) { return null; } sendResponse(channel); - // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); position.setProtocol(getProtocolName()); diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index 3cc0d0568..f31e8aead 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -112,6 +112,8 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { if (length == 255) { length += buf.readUnsignedByte(); } + + int n = 0; switch (type) { case 2: @@ -121,22 +123,18 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_INPUT, buf.readUnsignedByte()); break; case 6: - { - int n = buf.readUnsignedByte() >> 4; - if (n < 2) { - position.set(Event.PREFIX_ADC + n, readSwappedFloat(buf)); - } else { - position.set("di" + (n - 2), readSwappedFloat(buf)); - } + n = buf.readUnsignedByte() >> 4; + if (n < 2) { + position.set(Event.PREFIX_ADC + n, readSwappedFloat(buf)); + } else { + position.set("di" + (n - 2), readSwappedFloat(buf)); } break; case 7: - { - int alarm = buf.readUnsignedByte(); - buf.readUnsignedByte(); - if (BitUtil.check(alarm, 5)) { - position.set(Event.KEY_ALARM, BitUtil.range(alarm, 0, 4)); - } + int alarm = buf.readUnsignedByte(); + buf.readUnsignedByte(); + if (BitUtil.check(alarm, 5)) { + position.set(Event.KEY_ALARM, BitUtil.range(alarm, 0, 4)); } break; case 8: @@ -149,19 +147,17 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.set("unauthorized", ChannelBufferTools.readHexString(buf, 16)); break; case 24: - { - Set<Integer> temps = new LinkedHashSet<>(); - int temp = buf.readUnsignedByte(); - for (int i = 3; i >= 0; i--) { - int n = (temp >> (2 * i)) & 0x03; - if (!temps.contains(n)) { - temps.add(n); - } - } - for (int n : temps) { - position.set(Event.PREFIX_TEMP + n, buf.readUnsignedByte()); + Set<Integer> temps = new LinkedHashSet<>(); + int temp = buf.readUnsignedByte(); + for (int i = 3; i >= 0; i--) { + n = (temp >> (2 * i)) & 0x03; + if (!temps.contains(n)) { + temps.add(n); } } + for (int i : temps) { + position.set(Event.PREFIX_TEMP + n, buf.readUnsignedByte()); + } break; case 28: position.set("weight", buf.readUnsignedShort()); @@ -177,19 +173,17 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_RPM, buf.readUnsignedByte() * 50); break; case 107: - { - int fuel = buf.readUnsignedShort(); - switch (fuel >> 14) { - case 1: - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.4 + "%"); - break; - case 2: - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.5 + " l"); - break; - case 3: - position.set(Event.KEY_FUEL, (fuel & 0x3fff) * -0.5 + " l"); - break; - } + int fuel = buf.readUnsignedShort(); + switch (fuel >> 14) { + case 1: + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.4 + "%"); + break; + case 2: + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * 0.5 + " l"); + break; + case 3: + position.set(Event.KEY_FUEL, (fuel & 0x3fff) * -0.5 + " l"); + break; } break; case 108: diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 09e766e56..47158808c 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -169,21 +169,20 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - // Detect device ID if (sentence.startsWith("#L#")) { + + // Detect device ID String imei = sentence.substring(3, sentence.indexOf(';')); if (identify(imei, channel)) { sendResponse(channel, "#AL#", 1); } - } - // Heartbeat - else if (sentence.startsWith("#P#")) { + } else if (sentence.startsWith("#P#")) { + + // Heartbeat sendResponse(channel, "#AP#", null); - } - // Parse message - else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) { + } else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) { Position position = decodePosition( sentence.substring(sentence.indexOf('#', 1) + 1)); @@ -192,9 +191,8 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, "#AD#", 1); return position; } - } - else if (sentence.startsWith("#B#")) { + } else if (sentence.startsWith("#B#")) { String[] messages = sentence.substring(sentence.indexOf('#', 1) + 1).split("\\|"); List<Position> positions = new LinkedList<>(); |