aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java9
-rw-r--r--src/org/traccar/Context.java32
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java5
-rw-r--r--src/org/traccar/geocoder/GeocodeFarmGeocoder.java13
-rw-r--r--src/org/traccar/geocoder/GoogleGeocoder.java19
-rw-r--r--src/org/traccar/geocoder/NominatimGeocoder.java16
-rw-r--r--src/org/traccar/model/Position.java2
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CellocatorProtocol.java7
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolEncoder.java72
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java20
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java9
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/TaipProtocolDecoder.java33
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/TmgProtocolDecoder.java31
18 files changed, 247 insertions, 79 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 8748a9be6..e5fa76a47 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -46,7 +46,16 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
try {
Context.getDeviceManager().addDevice(device);
+
Log.info("Automatically registered device " + uniqueId);
+
+ if (defaultGroupId != 0) {
+ Context.getPermissionsManager().refreshPermissions();
+ if (Context.getGeofenceManager() != null) {
+ Context.getGeofenceManager().refresh();
+ }
+ }
+
return device.getId();
} catch (SQLException e) {
Log.warning(e);
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index cd6820778..27e61d32d 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.ning.http.client.AsyncHttpClient;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Properties;
import org.apache.velocity.app.VelocityEngine;
@@ -208,15 +209,12 @@ public final class Context {
String type = config.getString("geocoder.type", "google");
String url = config.getString("geocoder.url");
String key = config.getString("geocoder.key");
+ String language = config.getString("geocoder.language");
int cacheSize = config.getInteger("geocoder.cacheSize");
switch (type) {
case "nominatim":
- if (key != null) {
- geocoder = new NominatimGeocoder(url, key, cacheSize);
- } else {
- geocoder = new NominatimGeocoder(url, cacheSize);
- }
+ geocoder = new NominatimGeocoder(url, key, cacheSize);
break;
case "gisgraphy":
geocoder = new GisgraphyGeocoder(url, cacheSize);
@@ -234,17 +232,10 @@ public final class Context {
geocoder = new FactualGeocoder(url, key, cacheSize);
break;
case "geocodefarm":
- if (key != null) {
- geocoder = new GeocodeFarmGeocoder(key, cacheSize);
- } else {
- geocoder = new GeocodeFarmGeocoder(cacheSize);
- }
+ geocoder = new GeocodeFarmGeocoder(key, cacheSize);
+ break;
default:
- if (key != null) {
- geocoder = new GoogleGeocoder(key, cacheSize);
- } else {
- geocoder = new GoogleGeocoder(cacheSize);
- }
+ geocoder = new GoogleGeocoder(key, language, cacheSize);
break;
}
}
@@ -291,9 +282,14 @@ public final class Context {
velocityProperties.setProperty("runtime.log.logsystem.class",
"org.apache.velocity.runtime.log.NullLogChute");
- String address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
- int port = config.getInteger("web.port", 8082);
- String webUrl = URIUtil.newURI("http", address, port, "", "");
+ String address;
+ try {
+ address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
+ } catch (UnknownHostException e) {
+ address = "localhost";
+ }
+
+ String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", "");
webUrl = Context.getConfig().getString("web.url", webUrl);
velocityProperties.setProperty("web.url", webUrl);
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index 187b7ce73..c628cc107 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -30,10 +30,7 @@ public class IgnitionEventHandler extends BaseEventHandler {
@Override
protected Collection<Event> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
- if (device == null) {
- return null;
- }
- if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
+ if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
diff --git a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
index 585095606..db23aab79 100644
--- a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
+++ b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
@@ -19,14 +19,15 @@ import javax.json.JsonObject;
public class GeocodeFarmGeocoder extends JsonGeocoder {
- private static final String URL = "https://www.geocode.farm/v3/json/reverse/";
-
- public GeocodeFarmGeocoder(int cacheSize) {
- super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1", cacheSize);
+ private static String formatUrl(String key) {
+ String url = "https://www.geocode.farm/v3/json/reverse/";
+ if (key != null) {
+ url += "&key=" + key;
+ }
+ return url;
}
-
public GeocodeFarmGeocoder(String key, int cacheSize) {
- super(URL + "?lat=%f&lon=%f&country=us&lang=en&count=1&key=" + key, cacheSize);
+ super(formatUrl(key), cacheSize);
}
@Override
diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java
index 0506e701a..b38870c8f 100644
--- a/src/org/traccar/geocoder/GoogleGeocoder.java
+++ b/src/org/traccar/geocoder/GoogleGeocoder.java
@@ -21,16 +21,19 @@ import javax.json.JsonString;
public class GoogleGeocoder extends JsonGeocoder {
- public GoogleGeocoder() {
- this(0);
- }
-
- public GoogleGeocoder(int cacheSize) {
- super("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f", cacheSize);
+ private static String formatUrl(String key, String language) {
+ String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f";
+ if (key != null) {
+ url += "&key=" + key;
+ }
+ if (language != null) {
+ url += "&language=" + language;
+ }
+ return url;
}
- public GoogleGeocoder(String key, int cacheSize) {
- super("https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=" + key, cacheSize);
+ public GoogleGeocoder(String key, String language, int cacheSize) {
+ super(formatUrl(key, language), cacheSize);
}
@Override
diff --git a/src/org/traccar/geocoder/NominatimGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java
index b0ee39c6a..c10a1414e 100644
--- a/src/org/traccar/geocoder/NominatimGeocoder.java
+++ b/src/org/traccar/geocoder/NominatimGeocoder.java
@@ -19,16 +19,18 @@ import javax.json.JsonObject;
public class NominatimGeocoder extends JsonGeocoder {
- public NominatimGeocoder() {
- this("http://nominatim.openstreetmap.org/reverse", 0);
- }
-
- public NominatimGeocoder(String url, int cacheSize) {
- super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1", cacheSize);
+ private static String formatUrl(String url, String key) {
+ if (url == null) {
+ url = "http://nominatim.openstreetmap.org/reverse";
+ }
+ if (key != null) {
+ url += "&key=" + key;
+ }
+ return url;
}
public NominatimGeocoder(String url, String key, int cacheSize) {
- super(url + "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1&key=" + key, cacheSize);
+ super(formatUrl(url, key), cacheSize);
}
@Override
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 288901430..350524f32 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -76,6 +76,7 @@ public class Position extends Message {
public static final String ALARM_LOW_SPEED = "lowspeed";
public static final String ALARM_OVERSPEED = "overspeed";
public static final String ALARM_FALL_DOWN = "fallDown";
+ public static final String ALARM_LOW_POWER = "lowPower";
public static final String ALARM_LOW_BATTERY = "lowBattery";
public static final String ALARM_FAULT = "fault";
public static final String ALARM_POWER_OFF = "powerOff";
@@ -98,6 +99,7 @@ public class Position extends Message {
public static final String ALARM_BONNET = "bonnet";
public static final String ALARM_FOOT_BRAKE = "footBrake";
public static final String ALARM_OIL_LEAK = "oilLeak";
+ public static final String ALARM_TAMPERING = "tampering";
private String protocol;
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
index dc799054d..182066629 100644
--- a/src/org/traccar/protocol/At2000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java
@@ -102,6 +102,10 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ if (buf.capacity() <= BLOCK_LENGTH) {
+ return null; // empty message
+ }
+
byte[] data = new byte[buf.capacity() - BLOCK_LENGTH];
buf.readBytes(data);
buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data));
diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java
index bfaf03692..7c8510204 100644
--- a/src/org/traccar/protocol/CellocatorProtocol.java
+++ b/src/org/traccar/protocol/CellocatorProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
import java.nio.ByteOrder;
import java.util.List;
@@ -28,6 +29,8 @@ public class CellocatorProtocol extends BaseProtocol {
public CellocatorProtocol() {
super("cellocator");
+ setSupportedCommands(
+ Command.TYPE_OUTPUT_CONTROL);
}
@Override
@@ -36,6 +39,7 @@ public class CellocatorProtocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CellocatorFrameDecoder());
+ pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
}
};
@@ -45,6 +49,7 @@ public class CellocatorProtocol extends BaseProtocol {
server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
}
};
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 14325e619..7df8cad8a 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,6 +68,19 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private String decodeAlarm(short reason) {
+ switch (reason) {
+ case 70:
+ return Position.ALARM_SOS;
+ case 80:
+ return Position.ALARM_POWER_CUT;
+ case 81:
+ return Position.ALARM_LOW_POWER;
+ default:
+ return null;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -106,7 +119,8 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
operator += buf.readUnsignedByte();
buf.readUnsignedByte(); // reason data
- buf.readUnsignedByte(); // reason
+ position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
+
buf.readUnsignedByte(); // mode
buf.readUnsignedInt(); // IO
diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java
new file mode 100644
index 000000000..bb143d349
--- /dev/null
+++ b/src/org/traccar/protocol/CellocatorProtocolEncoder.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.Log;
+import org.traccar.model.Command;
+
+import java.nio.ByteOrder;
+
+public class CellocatorProtocolEncoder extends BaseProtocolEncoder {
+
+ private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) {
+
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ buf.writeByte('M');
+ buf.writeByte('C');
+ buf.writeByte('G');
+ buf.writeByte('P');
+ buf.writeByte(0);
+ buf.writeInt(Integer.parseInt(getUniqueId(deviceId)));
+ buf.writeByte(0); // command numerator
+ buf.writeInt(0); // authentication code
+ buf.writeByte(command);
+ buf.writeByte(command);
+ buf.writeByte(data1);
+ buf.writeByte(data1);
+ buf.writeByte(data2);
+ buf.writeByte(data2);
+ buf.writeInt(0); // command specific data
+
+ byte checksum = 0;
+ for (int i = 4; i < buf.writerIndex(); i++) {
+ checksum += buf.getByte(i);
+ }
+ buf.writeByte(checksum);
+
+ return buf;
+ }
+
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_OUTPUT_CONTROL:
+ int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4
+ + command.getInteger(Command.KEY_INDEX);
+ return encodeContent(command.getDeviceId(), 0x03, data, 0);
+ default:
+ Log.warning(new UnsupportedOperationException(command.getType()));
+ break;
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 68063c5c3..c9aae8e96 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -55,6 +55,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
private static final int TAG_ADC1 = 0x51;
private static final int TAG_ADC2 = 0x52;
private static final int TAG_ADC3 = 0x53;
+ private static final int TAG_ARRAY = 0xea;
private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>();
@@ -81,7 +82,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
0x20, 0x33, 0x44, 0x90, 0xc0, 0xc2, 0xc3, 0xd3,
0xd4, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xf0, 0xf9,
0x5a, 0x47, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
- 0xf7, 0xf8
+ 0xf7, 0xf8, 0xe2, 0xe9
};
for (int i : l1) {
TAG_LENGTH_MAP.put(i, 1);
@@ -102,7 +103,11 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
}
private static int getTagLength(int tag) {
- return TAG_LENGTH_MAP.get(tag);
+ Integer length = TAG_LENGTH_MAP.get(tag);
+ if (length == null) {
+ throw new IllegalArgumentException("Unknown tag: " + tag);
+ }
+ return length;
}
private void sendReply(Channel channel, int checksum) {
@@ -207,6 +212,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort());
break;
+ case TAG_ARRAY:
+ buf.skipBytes(buf.readUnsignedByte());
+ break;
+
default:
buf.skipBytes(getTagLength(tag));
break;
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 59f013313..ef434b779 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -107,7 +107,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.compile();
private static final Pattern PATTERN_LOCATION = new PatternBuilder()
- .number("(?:d{1,2})?,") // gps accuracy
+ .number("(d{1,2})?,") // hdop
.number("(d{1,3}.d)?,") // speed
.number("(d{1,3})?,") // course
.number("(-?d{1,5}.d)?,") // altitude
@@ -275,6 +275,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
.number("(d{15}|x{14}),") // imei
.any()
+ .number("(d{1,2})?,") // hdop
.number("(d{1,3}.d)?,") // speed
.number("(d{1,3})?,") // course
.number("(-?d{1,5}.d)?,") // altitude
@@ -399,6 +400,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
}
private void decodeLocation(Position position, Parser parser) {
+ int hdop = parser.nextInt();
+ position.setValid(hdop > 0);
+ position.set(Position.KEY_HDOP, hdop);
+
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.setCourse(parser.nextDouble());
position.setAltitude(parser.nextDouble());
@@ -451,11 +456,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
position.set("dtcsCodes", parser.next());
position.set(Position.KEY_THROTTLE, parser.next());
position.set(Position.KEY_FUEL, parser.next());
- position.set(Position.KEY_OBD_ODOMETER, parser.next());
+ position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000);
decodeLocation(position, parser);
- position.set(Position.KEY_ODOMETER, parser.next());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
if (parser.hasNext(6)) {
DateBuilder dateBuilder = new DateBuilder()
@@ -510,7 +515,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_BATTERY, parser.next());
- position.set(Position.KEY_ODOMETER, parser.next());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_HOURS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.PREFIX_ADC + 2, parser.next());
@@ -666,7 +671,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
- position.set(Position.KEY_ODOMETER, parser.next());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_BATTERY, parser.next());
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
@@ -703,12 +708,15 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ int hdop = parser.nextInt();
+ position.setValid(hdop > 0);
+ position.set(Position.KEY_HDOP, hdop);
+
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.setCourse(parser.nextDouble());
position.setAltitude(parser.nextDouble());
if (parser.hasNext(2)) {
- position.setValid(true);
position.setLongitude(parser.nextDouble());
position.setLatitude(parser.nextDouble());
} else {
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
index f1d305ab6..391fccc87 100644
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ b/src/org/traccar/protocol/H02FrameDecoder.java
@@ -50,7 +50,12 @@ public class H02FrameDecoder extends FrameDecoder {
// Return text message
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
if (index != -1) {
- return buf.readBytes(index + 1 - buf.readerIndex());
+ ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex());
+ while (buf.readable()
+ && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
+ buf.readByte(); // skip new line
+ }
+ return result;
}
break;
@@ -81,7 +86,7 @@ public class H02FrameDecoder extends FrameDecoder {
default:
- throw new IllegalArgumentException();
+ return null;
}
return null;
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 37f6294be..a717ddc4d 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -75,7 +75,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
}
- position.set(Position.KEY_IGNITION, !BitUtil.check(status, 10));
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 10));
position.set(Position.KEY_STATUS, status);
}
@@ -165,16 +165,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),")
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
- .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy)
- .any()
- .number("(x{8})") // status
- .groupBegin()
- .number(", *(x+),") // mcc
- .number(" *(x+),") // mnc
- .number(" *(x+),") // lac
- .number(" *(x+)") // cid
- .groupEnd("?")
+ .number("(?:(dd)(dd)(dd))?") // date (ddmmyy)
.any()
+ .number(",(x{8})") // status
+ .expression("(?:#|,.*)")
.compile();
private static final Pattern PATTERN_NBR = new PatternBuilder()
diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java
index 7927c28e6..c53538223 100644
--- a/src/org/traccar/protocol/TaipProtocolDecoder.java
+++ b/src/org/traccar/protocol/TaipProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,8 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?")
.number("(d{5})") // seconds
.or()
- .text("RGP") // type
+ .expression("(?:RGP|RCQ|RBR)") // type
+ .number("(?:dd)?")
.number("(dd)(dd)(dd)") // date
.number("(dd)(dd)(dd)") // time
.groupEnd()
@@ -56,6 +57,13 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
.number("([-+]ddd)(d{5})") // longitude
.number("(ddd)") // speed
.number("(ddd)") // course
+ .groupBegin()
+ .number("(xx)") // input
+ .number("(xx)") // satellites
+ .number("(ddd)") // battery
+ .number("(x{8})") // odometer
+ .number("[01]") // gps power
+ .groupEnd("?")
.number("(d)") // fix mode
.any()
.compile();
@@ -93,15 +101,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
position.setProtocol(getProtocolName());
- String week = parser.next();
- String day = parser.next();
- String seconds = parser.next();
- if (seconds != null) {
- if (week != null && day != null) {
- position.setTime(getTime(Integer.parseInt(week), Integer.parseInt(day), Integer.parseInt(seconds)));
- } else {
- position.setTime(getTime(Integer.parseInt(seconds)));
- }
+ if (parser.hasNext(2)) {
+ position.setTime(getTime(parser.nextInt(), parser.nextInt(), parser.nextInt()));
+ } else if (parser.hasNext()) {
+ position.setTime(getTime(parser.nextInt()));
}
if (parser.hasNext(6)) {
@@ -115,6 +118,14 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
position.setCourse(parser.nextDouble());
+
+ if (parser.hasNext(4)) {
+ position.set(Position.KEY_INPUT, parser.nextInt(16));
+ position.set(Position.KEY_SATELLITES, parser.nextInt(16));
+ position.set(Position.KEY_BATTERY, parser.nextInt());
+ position.set(Position.KEY_ODOMETER, parser.nextLong(16));
+ }
+
position.setValid(parser.nextInt() != 0);
String[] attributes = null;
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index e647a33a0..9c1e0a2ff 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -73,6 +73,12 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) {
switch (id) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ position.set("di" + id, buf.readUnsignedByte());
+ break;
case 9:
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
break;
@@ -82,6 +88,9 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
case 67:
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() + "mV");
break;
+ case 70:
+ position.set("pcbTemp", (length == 4 ? buf.readInt() : buf.readShort()) * 0.1);
+ break;
case 72:
position.set(Position.PREFIX_TEMP + 1, buf.readInt() * 0.1);
break;
diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java
index 9fa8759a0..3b73a1516 100644
--- a/src/org/traccar/protocol/TmgProtocolDecoder.java
+++ b/src/org/traccar/protocol/TmgProtocolDecoder.java
@@ -35,7 +35,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.text("$")
- .expression("...,") // type
+ .expression("(...),") // type
.expression("[LH],") // history
.number("(d+),") // imei
.number("(dd)(dd)(dddd),") // date
@@ -53,7 +53,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // visible satellites
.number("([^,]*),") // operator
.number("(d+),") // rssi
- .number("x+,") // cid
+ .number("[^,]*,") // cid
.expression("([01]),") // ignition
.number("(d+.?d*),") // battery
.number("(d+.?d*),") // power
@@ -72,6 +72,8 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ String type = parser.next();
+
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
@@ -81,6 +83,31 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ switch (type) {
+ case "rmv":
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ break;
+ case "ebl":
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ break;
+ case "ibl":
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ break;
+ case "tmp":
+ case "smt":
+ case "btt":
+ position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ break;
+ case "ion":
+ position.set(Position.KEY_IGNITION, true);
+ break;
+ case "iof":
+ position.set(Position.KEY_IGNITION, false);
+ break;
+ default:
+ break;
+ }
+
DateBuilder dateBuilder = new DateBuilder()
.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());