aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml7
-rw-r--r--src/org/traccar/BasePipelineFactory.java5
-rw-r--r--src/org/traccar/OdometerHandler.java55
-rw-r--r--src/org/traccar/model/Position.java4
-rw-r--r--web/app/store/DistanceUnits.js22
-rw-r--r--web/app/store/SpeedUnits.js6
-rw-r--r--web/app/view/main/MainMobile.js5
-rw-r--r--web/app/view/report/Report.js9
-rw-r--r--web/app/view/state/StateController.js13
9 files changed, 118 insertions, 8 deletions
diff --git a/debug.xml b/debug.xml
index 85cdb46b8..25f2cc320 100644
--- a/debug.xml
+++ b/debug.xml
@@ -25,6 +25,8 @@
<entry key='filter.duplicate'>true</entry>
<entry key='filter.distance'>50</entry>-->
+ <entry key='system.odometer.enable'>true</entry>
+
<!--<entry key='forward.enable'>true</entry>
<entry key='forward.url'>http://example.com:8080/gprmc/Data?id={uniqueId}&amp;code=0x0000&amp;gprmc={gprmc}</entry>-->
@@ -97,6 +99,7 @@
altitude FLOAT NOT NULL,
speed FLOAT NOT NULL,
course FLOAT NOT NULL,
+ odometer FLOAT NOT NULL,
address VARCHAR(512),
other VARCHAR(4096) NOT NULL,
FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE);
@@ -232,8 +235,8 @@
</entry>
<entry key='database.insertPosition'>
- INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, other)
- VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :other);
+ INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, odometer, address, other)
+ VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :odometer, :address, :other);
</entry>
<entry key='database.selectLatestPositions'>
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 4d8b0ffc4..6c4a6b5bd 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -25,7 +25,6 @@ import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.DownstreamMessageEvent;
-import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.handler.logging.LoggingHandler;
@@ -38,6 +37,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private int resetDelay;
private FilterHandler filterHandler;
+ private OdometerHandler odometerHandler;
private ReverseGeocoderHandler reverseGeocoderHandler;
protected class OpenChannelHandler extends SimpleChannelHandler {
@@ -114,6 +114,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
if (filterHandler != null) {
pipeline.addLast("filter", filterHandler);
}
+ if (odometerHandler != null) {
+ pipeline.addLast("odometer", odometerHandler);
+ }
if (reverseGeocoderHandler != null) {
pipeline.addLast("geocoder", reverseGeocoderHandler);
}
diff --git a/src/org/traccar/OdometerHandler.java b/src/org/traccar/OdometerHandler.java
new file mode 100644
index 000000000..d5860c02e
--- /dev/null
+++ b/src/org/traccar/OdometerHandler.java
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package org.traccar;
+
+import org.traccar.helper.DistanceCalculator;
+import org.traccar.helper.Log;
+import org.traccar.model.Position;
+
+/**
+ * <p>
+ * Odometer - total mileage calculation handler
+ * </p>
+ *
+ * @author Amila Silva
+ *
+ */
+public class OdometerHandler extends BaseDataHandler {
+
+ public OdometerHandler() {
+ Log.debug("System based odometer calculation enabled for all devices");
+ }
+
+ private Position getLastPosition(long deviceId) {
+ if (Context.getConnectionManager() != null) {
+ return Context.getConnectionManager().getLastPosition(deviceId);
+ }
+ return null;
+ }
+
+ private Position calculateDistance(Position position) {
+ Position last = getLastPosition(position.getDeviceId());
+ if (last != null) {
+ // set odometer only on movement
+ double odometer = 0.0;
+ if (last.getSpeed() == 0 && position.getSpeed() == 0) {
+ odometer = last.getOdometer();
+ } else {
+ double distance = DistanceCalculator.distance(
+ position.getLatitude(), position.getLongitude(),
+ last.getLatitude(), last.getLongitude());
+ distance = Math.round((distance) * 100.0) / 100.0;
+ odometer = distance + last.getOdometer();
+ }
+ position.setOdometer(odometer);
+ }
+ return position;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ return calculateDistance(position);
+ }
+
+}
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 62c999d94..0c928439c 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -56,6 +56,10 @@ public class Position extends Event implements Factory {
private double course;
public double getCourse() { return course; }
public void setCourse(double course) { this.course = course; }
+
+ private double odometer; // value in meters
+ public double getOdometer() { return odometer; }
+ public void setOdometer(double odometer) { this.odometer = odometer; }
private String address;
public String getAddress() { return address; }
diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js
index 506f1077c..7f0f93b70 100644
--- a/web/app/store/DistanceUnits.js
+++ b/web/app/store/DistanceUnits.js
@@ -20,5 +20,25 @@ Ext.define('Traccar.store.DistanceUnits', {
data: [
{'key': 'km', 'name': strings.sharedKm},
{'key': 'mi', 'name': strings.sharedMi}
- ]
+ ],
+
+ convert: function(value, unit) {
+ switch (unit) {
+ case 'km':
+ value = value * 0.001;
+ return Math.round(value * 100) / 100;
+ case 'mi':
+ value = value * 0.000621371;
+ return Math.round(value * 100) / 100;
+ }
+ return value;
+ },
+
+ getUnitName: function(unit) {
+ if (unit) {
+ return this.findRecord('key', unit).get('name');
+ } else {
+ return '';
+ }
+ },
});
diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js
index 78686fbb9..934d03717 100644
--- a/web/app/store/SpeedUnits.js
+++ b/web/app/store/SpeedUnits.js
@@ -25,9 +25,11 @@ Ext.define('Traccar.store.SpeedUnits', {
convert: function(value, unit) {
switch (unit) {
case 'kmh':
- return value * 1.852;
+ value = value * 1.852;
+ return Math.round(value * 10) / 10;
case 'mph':
- return value * 1.15078;
+ value = value * 1.15078;
+ return Math.round(value * 10) / 10;
}
return value;
},
diff --git a/web/app/view/main/MainMobile.js b/web/app/view/main/MainMobile.js
index f32ad9fb1..1cdd6f525 100644
--- a/web/app/view/main/MainMobile.js
+++ b/web/app/view/main/MainMobile.js
@@ -40,6 +40,11 @@ Ext.define('Traccar.view.main.MainMobile', {
xtype: 'deviceView',
header: false,
flex: 1
+ },{
+ region: 'east',
+ xtype: 'stateView',
+ header: false,
+ flex: 1
}]
});
diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js
index ff8cc7b3d..5466c7887 100644
--- a/web/app/view/report/Report.js
+++ b/web/app/view/report/Report.js
@@ -90,7 +90,14 @@ Ext.define('Traccar.view.report.Report', {
return speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit);
}
},
- { text: strings.positionCourse, dataIndex: 'course', flex: 1 },
+ /* { text: strings.positionCourse, dataIndex: 'course', flex: 1 }, */
+ { text: 'Odometer', dataIndex: 'odometer', flex: 1,
+ renderer: function(value) {
+ var distanceUnits = Ext.getStore('DistanceUnits');
+ var unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || '';
+ return distanceUnits.convert(value, unit) + ' ' + distanceUnits.getUnitName(unit);
+ }
+ },
{ text: strings.positionAddress, dataIndex: 'address', flex: 1 }
]
diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js
index 58b63120b..685805418 100644
--- a/web/app/view/state/StateController.js
+++ b/web/app/view/state/StateController.js
@@ -59,9 +59,13 @@ Ext.define('Traccar.view.state.StateController', {
priority: 6,
name: strings.positionSpeed
},
- 'course': {
+/* 'course': {
priority: 7,
name: strings.positionCourse
+ },*/
+ 'odometer': {
+ priority: 7,
+ name: 'Odometer'
},
'address': {
priority: 8,
@@ -87,6 +91,13 @@ Ext.define('Traccar.view.state.StateController', {
var unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || '';
value = speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit);
}
+
+ if (key === 'odometer') {
+ var distanceUnits = Ext.getStore('DistanceUnits');
+ var unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || '';
+ value = distanceUnits.convert(value, unit) + ' ' + distanceUnits.getUnitName(unit);
+ }
+
store.add(Ext.create('Traccar.model.Parameter', {
priority: this.keys[key].priority,
name: this.keys[key].name,