aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE.md13
-rw-r--r--src/org/traccar/database/DeviceManager.java90
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java7
-rw-r--r--src/org/traccar/reports/Summary.java6
-rw-r--r--src/org/traccar/reports/Trips.java7
-rw-r--r--src/org/traccar/web/CsvBuilder.java4
-rwxr-xr-xtools/hex.sh20
7 files changed, 126 insertions, 21 deletions
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 000000000..2c9c8d04a
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,13 @@
+ Apache License, Version 2.0
+
+ 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.
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 5f68df831..f32c7edd2 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -316,7 +316,87 @@ public class DeviceManager implements IdentityManager {
groupsById.remove(groupId);
}
- public String lookupAttribute(long deviceId, String attributeName) {
+ public boolean lookupServerBoolean(long deviceId, String attributeName, boolean defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, true);
+ if (result != null) {
+ return Boolean.parseBoolean(result);
+ }
+ return defaultValue;
+ }
+
+ public String lookupServerString(long deviceId, String attributeName, String defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, true);
+ if (result != null) {
+ return result;
+ }
+ return defaultValue;
+ }
+
+ public int lookupServerInteger(long deviceId, String attributeName, int defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, true);
+ if (result != null) {
+ return Integer.parseInt(result);
+ }
+ return defaultValue;
+ }
+
+ public long lookupServerLong(long deviceId, String attributeName, long defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, true);
+ if (result != null) {
+ return Long.parseLong(result);
+ }
+ return defaultValue;
+ }
+
+ public double lookupServerDouble(long deviceId, String attributeName, double defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, true);
+ if (result != null) {
+ return Double.parseDouble(result);
+ }
+ return defaultValue;
+ }
+
+ public boolean lookupConfigBoolean(long deviceId, String attributeName, boolean defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, false);
+ if (result != null) {
+ return Boolean.parseBoolean(result);
+ }
+ return defaultValue;
+ }
+
+ public String lookupConfigString(long deviceId, String attributeName, String defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, false);
+ if (result != null) {
+ return result;
+ }
+ return defaultValue;
+ }
+
+ public int lookupConfigInteger(long deviceId, String attributeName, int defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, false);
+ if (result != null) {
+ return Integer.parseInt(result);
+ }
+ return defaultValue;
+ }
+
+ public long lookupConfigLong(long deviceId, String attributeName, long defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, false);
+ if (result != null) {
+ return Long.parseLong(result);
+ }
+ return defaultValue;
+ }
+
+ public double lookupConfigDouble(long deviceId, String attributeName, double defaultValue) {
+ String result = lookupAttribute(deviceId, attributeName, false);
+ if (result != null) {
+ return Double.parseDouble(result);
+ }
+ return defaultValue;
+ }
+
+ private String lookupAttribute(long deviceId, String attributeName, boolean lookupServer) {
String result = null;
Device device = getDeviceById(deviceId);
if (device != null) {
@@ -338,8 +418,12 @@ public class DeviceManager implements IdentityManager {
}
}
if (result == null) {
- Server server = Context.getPermissionsManager().getServer();
- result = (String) server.getAttributes().get(attributeName);
+ if (lookupServer) {
+ Server server = Context.getPermissionsManager().getServer();
+ result = (String) server.getAttributes().get(attributeName);
+ } else {
+ result = Context.getConfig().getString(attributeName);
+ }
}
}
return result;
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 302fa87cd..57f60d864 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -47,11 +47,8 @@ public class OverspeedEventHandler extends BaseEventHandler {
Collection<Event> events = new ArrayList<>();
double speed = position.getSpeed();
- double speedLimit = 0;
- String speedLimitAttribute = Context.getDeviceManager().lookupAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT);
- if (speedLimitAttribute != null) {
- speedLimit = Double.parseDouble(speedLimitAttribute);
- }
+ double speedLimit = Context.getDeviceManager()
+ .lookupServerDouble(device.getId(), ATTRIBUTE_SPEED_LIMIT, 0);
if (speedLimit == 0) {
return null;
}
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index 44fb1dd4c..d4171f644 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -37,7 +37,7 @@ public final class Summary {
private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException {
SummaryReport result = new SummaryReport();
result.setDeviceId(deviceId);
- result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName());
+ result.setDeviceName(Context.getIdentityManager().getDeviceById(deviceId).getName());
Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to);
if (positions != null && !positions.isEmpty()) {
Position firstPosition = null;
@@ -60,7 +60,9 @@ public final class Summary {
speedSum += position.getSpeed();
result.setMaxSpeed(position.getSpeed());
}
- result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition));
+ boolean ignoreOdometer = Context.getDeviceManager()
+ .lookupConfigBoolean(deviceId, "report.ignoreOdometer", false);
+ result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer));
result.setAverageSpeed(speedSum / positions.size());
}
return result;
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 2171d5f93..f0a10edbd 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -53,15 +53,16 @@ public final class Trips {
long tripDuration = endTrip.getFixTime().getTime() - positions.get(startIndex).getFixTime().getTime();
long deviceId = startTrip.getDeviceId();
trip.setDeviceId(deviceId);
- String deviceName = Context.getDeviceManager().getDeviceById(deviceId).getName();
- trip.setDeviceName(deviceName);
+ trip.setDeviceName(Context.getIdentityManager().getDeviceById(deviceId).getName());
trip.setStartPositionId(startTrip.getId());
trip.setStartTime(startTrip.getFixTime());
trip.setStartAddress(startTrip.getAddress());
trip.setEndPositionId(endTrip.getId());
trip.setEndTime(endTrip.getFixTime());
trip.setEndAddress(endTrip.getAddress());
- trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip));
+ boolean ignoreOdometer = Context.getDeviceManager()
+ .lookupConfigBoolean(deviceId, "report.ignoreOdometer", false);
+ trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip, !ignoreOdometer));
trip.setDuration(tripDuration);
trip.setAverageSpeed(speedSum / (endIndex - startIndex));
trip.setMaxSpeed(speedMax);
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
index a25b839a9..f59aabc7f 100644
--- a/src/org/traccar/web/CsvBuilder.java
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -37,10 +37,10 @@ public class CsvBuilder {
SortedSet<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
@Override
public int compare(Method m1, Method m2) {
- if (m1.getName().equals("getAttributes") & !m1.getName().equals(m2.getName())) {
+ if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
return 1;
}
- if (m2.getName().equals("getAttributes") & !m1.getName().equals(m2.getName())) {
+ if (m2.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
return -1;
}
return m1.getName().compareTo(m2.getName());
diff --git a/tools/hex.sh b/tools/hex.sh
index cfae14bb6..78cd8fa38 100755
--- a/tools/hex.sh
+++ b/tools/hex.sh
@@ -10,26 +10,34 @@
if [ $# -lt 2 ]
then
- echo "USAGE: $0 <port> <hex>"
+ echo "USAGE: $0 <host> <port> <hex>"
+ echo "If only <port> and <hex> are present, <host> defaults to localhost."
exit 1
fi
+host="$1"; port="$2"; hex="$3";
+
+if [ $# -eq 2 ]
+then
+ host="localhost"; port="$1"; hex="$2";
+fi
+
send_hex_udp () {
- echo $2 | xxd -r -p | nc -u -w 0 localhost $1
+ echo "$hex" | xxd -r -p | nc -u -w 0 "$host" "$port"
}
send_hex_tcp () {
- echo $2 | xxd -r -p | nc localhost $1
+ echo "$hex" | xxd -r -p | nc "$host" "$port"
}
send_text_udp () {
- echo -n -e $2 | nc -u -w 0 localhost $1
+ echo -n -e "$hex" | nc -u -w 0 "$host" "$port"
}
send_text_tcp () {
- echo -n -e $2 | nc localhost $1
+ echo -n -e "$hex" | nc "$host" "$port"
}
-send_hex_tcp $1 $2
+send_hex_tcp "$host" "$port" "$hex"
exit $?