From 0350d762a7c08199e79dc401b6c6821d7e2a21bd Mon Sep 17 00:00:00 2001 From: amilasilva88 Date: Thu, 13 Aug 2015 20:28:58 +0800 Subject: Added ODOMeter and Modification to Mobile UI --- src/org/traccar/BasePipelineFactory.java | 10 +++++++ src/org/traccar/ODOMeterHandler.java | 51 ++++++++++++++++++++++++++++++++ src/org/traccar/model/Position.java | 4 +++ 3 files changed, 65 insertions(+) create mode 100644 src/org/traccar/ODOMeterHandler.java (limited to 'src/org') diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 4d8b0ffc4..410b57318 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -38,6 +38,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private int resetDelay; private FilterHandler filterHandler; + private ODOMeterHandler odoMeterHandler; private ReverseGeocoderHandler reverseGeocoderHandler; protected class OpenChannelHandler extends SimpleChannelHandler { @@ -92,6 +93,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { filterHandler = new FilterHandler(); } + if (Context.getConfig().getBoolean("system.odometer.enable")) { + odoMeterHandler = new ODOMeterHandler(); + } + if (Context.getReverseGeocoder() != null) { reverseGeocoderHandler = new ReverseGeocoderHandler( Context.getReverseGeocoder(), Context.getConfig().getBoolean("geocode.processInvalidPositions")); @@ -114,6 +119,11 @@ 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..1dc3aed44 --- /dev/null +++ b/src/org/traccar/ODOMeterHandler.java @@ -0,0 +1,51 @@ +/** + * + */ +package org.traccar; + +import org.traccar.helper.DistanceCalculator; +import org.traccar.helper.Log; +import org.traccar.model.Position; + +/** + *

+ * ODO Meter handler + *

+ * + * @author Amila Silva + * + */ +public class ODOMeterHandler extends BaseDataHandler { + + public ODOMeterHandler() { + Log.debug("System based ODO meter 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) { + double distance = DistanceCalculator.distance( + position.getLatitude(), position.getLongitude(), + last.getLatitude(), last.getLongitude()); + distance = Math.round((distance) * 100.0) / 100.0; + double odoMeter = distance + last.getOdoMeter(); + Log.info("::: Device Course : " + position.getDeviceId() + + ", Distance :" + distance + "m, ODO Meter :" + odoMeter + " m"); + 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..8c3340d9c 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; } -- cgit v1.2.3 From 064cbff8e9f581bbd57988e5dd78a1f7e5480880 Mon Sep 17 00:00:00 2001 From: amilasilva88 Date: Fri, 14 Aug 2015 09:00:58 +0800 Subject: Resolved the review comments --- src/org/traccar/ODOMeterHandler.java | 7 ++++--- web/app/view/report/Report.js | 2 +- web/app/view/state/StateController.js | 2 +- web/release.html | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/ODOMeterHandler.java b/src/org/traccar/ODOMeterHandler.java index 1dc3aed44..87dde6b92 100644 --- a/src/org/traccar/ODOMeterHandler.java +++ b/src/org/traccar/ODOMeterHandler.java @@ -36,10 +36,11 @@ public class ODOMeterHandler extends BaseDataHandler { last.getLatitude(), last.getLongitude()); distance = Math.round((distance) * 100.0) / 100.0; double odoMeter = distance + last.getOdoMeter(); - Log.info("::: Device Course : " + position.getDeviceId() - + ", Distance :" + distance + "m, ODO Meter :" + odoMeter + " m"); +// Log.debug("::: Device Course : " + position.getDeviceId() +// + ", Distance :" + distance + "m, Odometer :" + odoMeter +// + " m"); position.setOdoMeter(odoMeter); - } + } return position; } diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js index f081333d4..6c43b9463 100644 --- a/web/app/view/report/Report.js +++ b/web/app/view/report/Report.js @@ -91,7 +91,7 @@ Ext.define('Traccar.view.report.Report', { } }, /* { text: strings.positionCourse, dataIndex: 'course', flex: 1 }, */ - { text: 'ODO Meter', dataIndex: 'odoMeter', 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') || ''; diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js index 858feab52..6f222f6a8 100644 --- a/web/app/view/state/StateController.js +++ b/web/app/view/state/StateController.js @@ -65,7 +65,7 @@ Ext.define('Traccar.view.state.StateController', { },*/ 'odoMeter': { priority: 7, - name: 'ODO Meter' + name: 'Odometer' }, 'address': { priority: 8, diff --git a/web/release.html b/web/release.html index fc2ff6e87..2a4df7537 100644 --- a/web/release.html +++ b/web/release.html @@ -3,7 +3,7 @@ -BlueSky +Traccar