aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/WebDataHandler.java22
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/protocol/BceProtocolDecoder.java8
-rw-r--r--src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/OkoProtocolDecoder.java23
-rw-r--r--src/main/java/org/traccar/protocol/OmnicommProtocolDecoder.java31
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java18
-rw-r--r--src/main/java/org/traccar/protocol/SolarPoweredProtocolDecoder.java18
-rw-r--r--src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/TelicProtocolDecoder.java6
11 files changed, 113 insertions, 40 deletions
diff --git a/src/main/java/org/traccar/WebDataHandler.java b/src/main/java/org/traccar/WebDataHandler.java
index 39e54616b..d6bfb126b 100644
--- a/src/main/java/org/traccar/WebDataHandler.java
+++ b/src/main/java/org/traccar/WebDataHandler.java
@@ -33,6 +33,8 @@ import org.traccar.model.Position;
import org.traccar.model.Group;
import javax.inject.Inject;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
@@ -65,6 +67,7 @@ public class WebDataHandler extends BaseDataHandler {
private final String url;
private final String header;
private final boolean json;
+ private final boolean urlVariables;
private final boolean retryEnabled;
private final int retryDelay;
@@ -83,6 +86,7 @@ public class WebDataHandler extends BaseDataHandler {
this.url = config.getString(Keys.FORWARD_URL);
this.header = config.getString(Keys.FORWARD_HEADER);
this.json = config.getBoolean(Keys.FORWARD_JSON);
+ this.urlVariables = config.getBoolean(Keys.FORWARD_URL_VARIABLES);
this.retryEnabled = config.getBoolean(Keys.FORWARD_RETRY_ENABLE);
this.retryDelay = config.getInteger(Keys.FORWARD_RETRY_DELAY, 100);
@@ -184,12 +188,13 @@ public class WebDataHandler extends BaseDataHandler {
private int retries = 0;
private Map<String, Object> payload;
private Invocation.Builder requestBuilder;
+ private MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
AsyncRequestAndCallback(Position position) {
String formattedUrl;
try {
- formattedUrl = json ? url : formatRequest(position);
+ formattedUrl = (json && !urlVariables) ? url : formatRequest(position);
} catch (UnsupportedEncodingException | JsonProcessingException e) {
throw new RuntimeException("Forwarding formatting error", e);
}
@@ -198,7 +203,13 @@ public class WebDataHandler extends BaseDataHandler {
if (header != null && !header.isEmpty()) {
for (String line: header.split("\\r?\\n")) {
String[] values = line.split(":", 2);
- requestBuilder.header(values[0].trim(), values[1].trim());
+ String headerName = values[0].trim();
+ String headerValue = values[1].trim();
+ if (headerName.equals(HttpHeaders.CONTENT_TYPE)) {
+ mediaType = MediaType.valueOf(headerValue);
+ } else {
+ requestBuilder.header(headerName, headerValue);
+ }
}
}
@@ -211,7 +222,12 @@ public class WebDataHandler extends BaseDataHandler {
private void send() {
if (json) {
- requestBuilder.async().post(Entity.json(payload), this);
+ try {
+ Entity<String> entity = Entity.entity(objectMapper.writeValueAsString(payload), mediaType);
+ requestBuilder.async().post(entity, this);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to serialize location to json", e);
+ }
} else {
requestBuilder.async().get(this);
}
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index d88b36d28..200ef8aa3 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -101,6 +101,13 @@ public final class Keys {
"forward.json", Boolean.class);
/**
+ * Boolean value to enable URL parameters in json mode. For example, {uniqueId} for device identifier,
+ * {latitude} and {longitude} for coordinates.
+ */
+ public static final ConfigKey FORWARD_URL_VARIABLES = new ConfigKey(
+ "forward.urlVariables", Boolean.class);
+
+ /**
* Position forwarding retrying enable. When enabled, additional attempts are made to deliver positions. If initial
* delivery fails, because of an unreachable server or an HTTP response different from '2xx', the software waits
* for 'forward.retry.delay' milliseconds to retry delivery. On subsequent failures, this delay is duplicated.
diff --git a/src/main/java/org/traccar/protocol/BceProtocolDecoder.java b/src/main/java/org/traccar/protocol/BceProtocolDecoder.java
index 54136382c..a259e027a 100644
--- a/src/main/java/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/BceProtocolDecoder.java
@@ -113,7 +113,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
}
if (BitUtil.check(mask, 4)) {
- position.set(Position.KEY_RPM, buf.readUnsignedShortLE() * 0.0125);
+ position.set(Position.KEY_RPM, buf.readUnsignedShortLE() * 0.125);
}
if (BitUtil.check(mask, 5)) {
position.set(Position.KEY_HOURS, buf.readUnsignedIntLE());
@@ -217,9 +217,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShortLE();
}
if (BitUtil.check(mask, 6)) {
- position.set("maxAcceleration", buf.readUnsignedByte());
- position.set("maxBraking", buf.readUnsignedByte());
- position.set("maxCornering", buf.readUnsignedByte());
+ position.set("maxAcceleration", buf.readUnsignedByte() * 0.02);
+ position.set("maxBraking", buf.readUnsignedByte() * 0.02);
+ position.set("maxCornering", buf.readUnsignedByte() * 0.02);
}
if (BitUtil.check(mask, 7)) {
buf.skipBytes(16);
diff --git a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
index 382509793..ab89f10c8 100644
--- a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
@@ -97,7 +97,7 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
rootElement.appendChild(state);
Element stateMessage = document.createElement("stateMessage");
- stateMessage.appendChild(document.createTextNode("Messages received and stored successfully"));
+ stateMessage.appendChild(document.createTextNode("Store OK"));
rootElement.appendChild(stateMessage);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
diff --git a/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java b/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java
index 5adf61494..4d9c9afc4 100644
--- a/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 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.
@@ -36,7 +36,7 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.text("{")
.number("(d{15}),").optional() // imei
- .number("(dd)(dd)(dd).d+,") // time
+ .number("(dd)(dd)(dd)(?:.d+)?,") // time
.expression("([AV]),") // validity
.number("(dd)(dd.d+),") // latitude
.expression("([NS]),")
@@ -46,14 +46,23 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*)?,") // course
.number("(dd)(dd)(dd),") // date (ddmmyy)
.number("(d+),") // satellites
- .number("(d+.d+),") // adc
+ .number("(d+.d+|xx),") // adc
.number("(xx),") // event
- .number("(d+.d+),") // power
+ .number("(d+.d+|xx),") // power
.number("d,") // memory status
- .number("(xx)") // io
+ .number("(xx)?") // io
.any()
.compile();
+ private double decodeVoltage(Parser parser) {
+ String value = parser.next();
+ if (value.contains(".")) {
+ return Double.parseDouble(value);
+ } else {
+ return Integer.parseInt(value, 16) * 0.1;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -89,9 +98,9 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateBuilder.getDate());
position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
+ position.set(Position.PREFIX_ADC + 1, decodeVoltage(parser));
position.set(Position.KEY_EVENT, parser.next());
- position.set(Position.KEY_POWER, parser.nextDouble());
+ position.set(Position.KEY_POWER, decodeVoltage(parser));
position.set(Position.KEY_INPUT, parser.nextHexInt());
return position;
diff --git a/src/main/java/org/traccar/protocol/OmnicommProtocolDecoder.java b/src/main/java/org/traccar/protocol/OmnicommProtocolDecoder.java
index cd8b74c9a..6e9cf52a5 100644
--- a/src/main/java/org/traccar/protocol/OmnicommProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OmnicommProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2020 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.
@@ -111,16 +111,29 @@ public class OmnicommProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ if (message.hasGeneral()) {
+ OmnicommMessageOuterClass.OmnicommMessage.General data = message.getGeneral();
+ position.set(Position.KEY_POWER, data.getUboard() * 0.1);
+ position.set(Position.KEY_BATTERY_LEVEL, data.getBatLife());
+ }
+
if (message.hasNAV()) {
- OmnicommMessageOuterClass.OmnicommMessage.NAV nav = message.getNAV();
+ OmnicommMessageOuterClass.OmnicommMessage.NAV data = message.getNAV();
position.setValid(true);
- position.setTime(new Date((nav.getGPSTime() + 1230768000) * 1000L)); // from 2009-01-01 12:00
- position.setLatitude(nav.getLAT() * 0.0000001);
- position.setLongitude(nav.getLON() * 0.0000001);
- position.setSpeed(UnitsConverter.knotsFromKph(nav.getGPSVel() * 0.1));
- position.setCourse(nav.getGPSDir());
- position.setAltitude(nav.getGPSAlt() * 0.1);
- position.set(Position.KEY_SATELLITES, nav.getGPSNSat());
+ position.setTime(new Date((data.getGPSTime() + 1230768000) * 1000L)); // from 2009-01-01 12:00
+ position.setLatitude(data.getLAT() * 0.0000001);
+ position.setLongitude(data.getLON() * 0.0000001);
+ position.setSpeed(UnitsConverter.knotsFromKph(data.getGPSVel() * 0.1));
+ position.setCourse(data.getGPSDir());
+ position.setAltitude(data.getGPSAlt() * 0.1);
+ position.set(Position.KEY_SATELLITES, data.getGPSNSat());
+ }
+
+ if (message.hasLLSDt()) {
+ OmnicommMessageOuterClass.OmnicommMessage.LLSDt data = message.getLLSDt();
+ position.set("fuel1Temp", data.getTLLS1());
+ position.set("fuel1", data.getCLLS1());
+ position.set("fuel1State", data.getFLLS1());
}
if (position.getFixTime() != null) {
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index 304f61836..bda0600cc 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 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.
@@ -83,7 +83,14 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
}
JsonObject json = Json.createReader(new StringReader(content)).readObject();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, json.getString("device"));
+ String deviceId;
+ if (json.containsKey("device")) {
+ deviceId = json.getString("device");
+ } else {
+ deviceId = json.getString("deviceId");
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, deviceId);
if (deviceSession == null) {
sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
@@ -99,7 +106,8 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
}
if (json.containsKey("location")
- || json.containsKey("lat") && json.containsKey("lng") && !json.containsKey("data")) {
+ || json.containsKey("lat") && json.containsKey("lng") && !json.containsKey("data")
+ || json.containsKey("latitude") && json.containsKey("longitude") && !json.containsKey("data")) {
JsonObject location;
if (json.containsKey("location")) {
@@ -109,8 +117,8 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
}
position.setValid(true);
- position.setLatitude(getJsonDouble(location, "lat"));
- position.setLongitude(getJsonDouble(location, "lng"));
+ position.setLatitude(getJsonDouble(location, location.containsKey("lat") ? "lat" : "latitude"));
+ position.setLongitude(getJsonDouble(location, location.containsKey("lng") ? "lng" : "longitude"));
} else {
diff --git a/src/main/java/org/traccar/protocol/SolarPoweredProtocolDecoder.java b/src/main/java/org/traccar/protocol/SolarPoweredProtocolDecoder.java
index eae37386a..6fe54b0b0 100644
--- a/src/main/java/org/traccar/protocol/SolarPoweredProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SolarPoweredProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2020 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.
@@ -77,10 +77,24 @@ public class SolarPoweredProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(-position.getLongitude());
}
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.set(Position.KEY_DEVICE_TEMP, (int) buf.readByte());
+ int temperature = buf.readUnsignedByte();
+ if (BitUtil.check(temperature, 7)) {
+ position.set(Position.KEY_DEVICE_TEMP, -BitUtil.to(temperature, 7));
+ } else {
+ position.set(Position.KEY_DEVICE_TEMP, BitUtil.to(temperature, 7));
+ }
position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.02);
position.setCourse(buf.readUnsignedByte());
break;
+ case 0x83:
+ buf.readUnsignedInt(); // uptime
+ buf.readUnsignedInt(); // gps count
+ buf.readUnsignedInt(); // gsm count
+ buf.readUnsignedByte(); // positioning time
+ buf.readUnsignedByte(); // registration time
+ buf.readUnsignedByte(); // connection time
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ break;
default:
buf.skipBytes(length);
break;
diff --git a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
index bad6f03a9..2d1613e03 100644
--- a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 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.
@@ -140,6 +140,11 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
event = Integer.parseInt(data[i]);
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
+ if (event == 24) {
+ position.set(Position.KEY_IGNITION, true);
+ } else if (event == 25) {
+ position.set(Position.KEY_IGNITION, false);
+ }
break;
case "#PDT#":
position.setFixTime(dateFormat.parse(data[i]));
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
index 9b146ec90..3331ebb71 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 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.
@@ -177,8 +177,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
private Position decodePosition(
- Channel channel, DeviceSession deviceSession,
- ByteBuf buf, int type, int index, ByteBuf imei) {
+ Channel channel, DeviceSession deviceSession, ByteBuf buf, int type, int index, ByteBuf imei) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -214,8 +213,10 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(io, 7 + i));
}
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+ if (header != 0x2626) {
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+ }
}
diff --git a/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java b/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
index 457687b2e..a4f9e2989 100644
--- a/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2020 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.
@@ -42,8 +42,8 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)(dd)(dd)") // date (ddmmyy)
.number("(dd)(dd)(dd),") // time (hhmmss)
.groupBegin()
- .number("(-?d{9}),") // longitude
- .number("(-?d{8}),") // latitude
+ .number("(-?d{8,}),") // longitude
+ .number("(-?d{7,}),") // latitude
.or()
.number("(-?d+),") // longitude
.number("(-?d+),") // latitude