diff options
-rw-r--r-- | src/org/traccar/Context.java | 3 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/MotionEventHandler.java | 8 | ||||
-rw-r--r-- | src/org/traccar/model/User.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Vt200ProtocolDecoder.java | 58 | ||||
-rw-r--r-- | src/org/traccar/reports/model/TripsConfig.java | 15 | ||||
-rw-r--r-- | test/org/traccar/events/MotionEventHandlerTest.java | 30 | ||||
-rw-r--r-- | test/org/traccar/protocol/Vt200ProtocolDecoderTest.java | 7 | ||||
-rw-r--r-- | test/org/traccar/reports/ReportUtilsTest.java | 12 |
9 files changed, 115 insertions, 22 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 0d2a05b7a..10fdd9f29 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -255,7 +255,8 @@ public final class Context { config.getLong("report.trip.minimalTripDistance", 500), config.getLong("report.trip.minimalTripDuration", 300) * 1000, config.getLong("report.trip.minimalParkingDuration", 300) * 1000, - config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000); + config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000, + config.getBoolean("report.trip.useIgnition")); } public static void init(String[] arguments) throws Exception { diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index b7d3cb1e4..2e3e68bc9 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -297,7 +297,7 @@ public class DataManager { public User login(String email, String password) throws SQLException { User user = QueryBuilder.create(dataSource, getQuery("database.loginUser")) - .setString("email", email) + .setString("email", email.trim()) .executeQuerySingle(User.class); if (user != null && user.isPasswordValid(password)) { return user; diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index b20a11999..8c2d4c56c 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -78,13 +78,19 @@ public class MotionEventHandler extends BaseEventHandler { if (motionPosition != null) { long motionTime = motionPosition.getFixTime().getTime(); double distance = ReportUtils.calculateDistance(motionPosition, position, false); + Boolean ignition = null; + if (tripsConfig.getUseIgnition() + && position.getAttributes().containsKey(Position.KEY_IGNITION)) { + ignition = position.getBoolean(Position.KEY_IGNITION); + } if (newMotion) { if (motionTime + tripsConfig.getMinimalTripDuration() <= currentTime || distance >= tripsConfig.getMinimalTripDistance()) { result = newEvent(deviceState, newMotion); } } else { - if (motionTime + tripsConfig.getMinimalParkingDuration() <= currentTime) { + if (motionTime + tripsConfig.getMinimalParkingDuration() <= currentTime + || ignition != null && !ignition) { result = newEvent(deviceState, newMotion); } } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index b71666f87..3557521ab 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -43,7 +43,7 @@ public class User extends ExtendedModel { } public void setEmail(String email) { - this.email = email; + this.email = email.trim(); } private String phone; diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index 111c29313..6be70c3c1 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -27,6 +27,8 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.Arrays; +import java.util.Date; public class Vt200ProtocolDecoder extends BaseProtocolDecoder { @@ -40,6 +42,13 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes * 0.0001 / 60; } + protected Date decodeDate(ChannelBuffer buf) { + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)) + .setTime(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); + return dateBuilder.getDate(); + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -66,12 +75,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // data type buf.readUnsignedShort(); // trip id - DateBuilder dateBuilder = new DateBuilder(); - dateBuilder.setDateReverse( - BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); - dateBuilder.setTime( - BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); - position.setTime(dateBuilder.getDate()); + position.setTime(decodeDate(buf)); position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); @@ -97,6 +101,48 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type == 0x3088) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.readUnsignedShort(); // trip id + buf.skipBytes(8); // imei + buf.skipBytes(8); // imsi + + position.set("tripStart", decodeDate(buf).getTime()); + position.set("tripEnd", decodeDate(buf).getTime()); + position.set("drivingTime", buf.readUnsignedShort()); + + position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt()); + + position.set("maxSpeed", UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + position.set("maxRpm", buf.readUnsignedShort()); + position.set("maxTemp", buf.readUnsignedByte() - 40); + position.set("hardAccelerationCount", buf.readUnsignedByte()); + position.set("hardBreakingCount", buf.readUnsignedByte()); + + for (String speedType : Arrays.asList("over", "high", "normal", "low")) { + position.set(speedType + "SpeedTime", buf.readUnsignedShort()); + position.set(speedType + "SpeedDistance", buf.readUnsignedInt()); + position.set(speedType + "SpeedFuel", buf.readUnsignedInt()); + } + + position.set("idleTime", buf.readUnsignedShort()); + position.set("idleFuel", buf.readUnsignedInt()); + + position.set("hardCorneringCount", buf.readUnsignedByte()); + position.set("overspeedCount", buf.readUnsignedByte()); + position.set("overheatCount", buf.readUnsignedShort()); + position.set("laneChangeCount", buf.readUnsignedByte()); + position.set("emergencyRefueling", buf.readUnsignedByte()); + + return position; + } return null; diff --git a/src/org/traccar/reports/model/TripsConfig.java b/src/org/traccar/reports/model/TripsConfig.java index 4898c1389..22fddd072 100644 --- a/src/org/traccar/reports/model/TripsConfig.java +++ b/src/org/traccar/reports/model/TripsConfig.java @@ -21,12 +21,13 @@ public class TripsConfig { public TripsConfig() { } - public TripsConfig(double minimalTripDistance, long minimalTripDuration, - long minimalParkingDuration, long minimalNoDataDuration) { + public TripsConfig(double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration, + long minimalNoDataDuration, boolean useIgnition) { this.minimalTripDistance = minimalTripDistance; this.minimalTripDuration = minimalTripDuration; this.minimalParkingDuration = minimalParkingDuration; this.minimalNoDataDuration = minimalNoDataDuration; + this.useIgnition = useIgnition; } private double minimalTripDistance; @@ -69,4 +70,14 @@ public class TripsConfig { this.minimalNoDataDuration = minimalNoDataDuration; } + private boolean useIgnition; + + public boolean getUseIgnition() { + return useIgnition; + } + + public void setUseIgnition(boolean useIgnition) { + this.useIgnition = useIgnition; + } + } diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java index 0543d86fe..902be8b87 100644 --- a/test/org/traccar/events/MotionEventHandlerTest.java +++ b/test/org/traccar/events/MotionEventHandlerTest.java @@ -1,6 +1,7 @@ package org.traccar.events; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -29,7 +30,7 @@ public class MotionEventHandlerTest extends BaseTest { @Test public void testMotionWithPosition() throws Exception { MotionEventHandler motionEventHandler = new MotionEventHandler( - new TripsConfig(500, 300 * 1000, 300 * 1000, 0)); + new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false)); Position position = new Position(); position.setTime(date("2017-01-01 00:00:00")); @@ -68,7 +69,7 @@ public class MotionEventHandlerTest extends BaseTest { @Test public void testMotionWithStatus() throws Exception { MotionEventHandler motionEventHandler = new MotionEventHandler( - new TripsConfig(500, 300 * 1000, 300 * 1000, 0)); + new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false)); Position position = new Position(); position.setTime(new Date(System.currentTimeMillis() - 360000)); @@ -85,4 +86,29 @@ public class MotionEventHandlerTest extends BaseTest { assertNull(deviceState.getMotionPosition()); } + @Test + public void testStopWithPositionIgnition() throws Exception { + MotionEventHandler motionEventHandler = new MotionEventHandler( + new TripsConfig(500, 300 * 1000, 300 * 1000, 0, true)); + + Position position = new Position(); + position.setTime(date("2017-01-01 00:00:00")); + position.set(Position.KEY_MOTION, false); + position.set(Position.KEY_IGNITION, true); + DeviceState deviceState = new DeviceState(); + deviceState.setMotionState(true); + deviceState.setMotionPosition(position); + + Position nextPosition = new Position(); + nextPosition.setTime(date("2017-01-01 00:02:00")); + nextPosition.set(Position.KEY_MOTION, false); + nextPosition.set(Position.KEY_IGNITION, false); + + Event event = motionEventHandler.updateMotionState(deviceState, nextPosition); + assertNotNull(event); + assertEquals(Event.TYPE_DEVICE_STOPPED, event.getType()); + assertFalse(deviceState.getMotionState()); + assertNull(deviceState.getMotionPosition()); + } + } diff --git a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java index 37d9c46d9..42ed4a652 100644 --- a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "286310373094563082002701033d010817143327c68a14841e00c27f550e9a000000000c000000084700200120007d01af260b29")); + verifyAttributes(decoder, binary( + "2863103730945630880062033d862631037309456f222014604362936f010817140954010817144135076b00002a3800003b7d6127cc91040000000000000000000000005a0000088e000001ce02630000263b000009b401ff00000cb40000069c02af000018190200000102019729")); + verifyPosition(decoder, binary( "286310373094562086002101033d010817143328441790420114817637207d090a00000847002001207f00d6f229")); @@ -25,7 +28,7 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "28631037309456108800002e29")); - verifyNull(decoder, binary( + verifyAttributes(decoder, binary( "2863103730945630880062033c862631037309456f222014604362936f01081713365601081713571904c800001b2c000034f66827f0840000000000000000000000000047000006e7000001b9022a000023ff000007f2018a00000a10000003f300cd00000d8d0300000302002729")); verifyNull(decoder, binary( @@ -40,7 +43,7 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "286310373094563089001200032f2107171740144417075001147188872c29")); - verifyNull(decoder, binary( + verifyAttributes(decoder, binary( "2863103730945630880062032f862631037309456f222014604362936f21071717373221071717401400a100000cd700000004020d3c8e0000000000000000000000000000000000000000000000000000000000000000000a000000040000000e009700000cc9000000000000e929")); verifyPosition(decoder, binary( diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java index 14d8d87e0..c74109550 100644 --- a/test/org/traccar/reports/ReportUtilsTest.java +++ b/test/org/traccar/reports/ReportUtilsTest.java @@ -79,7 +79,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:06:00.000", 0, 3000), position("2016-01-01 00:07:00.000", 0, 3000)); - TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 300000, 180000, 900000, false); Collection<TripReport> trips = ReportUtils.detectTrips(data, tripsConfig, false, 0.01); @@ -127,7 +127,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:04:00.000", 1, 0), position("2016-01-01 00:05:00.000", 0, 0)); - TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false); Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01); @@ -153,7 +153,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:04:00.000", 1, 0), position("2016-01-01 00:05:00.000", 2, 0)); - TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false); Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01); @@ -179,7 +179,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:04:00.000", 0, 0), position("2016-01-01 00:05:00.000", 0, 0)); - TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false); Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01); @@ -205,7 +205,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:04:00.000", 5, 0), position("2016-01-01 00:05:00.000", 5, 0)); - TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 300000, 200000, 900000, false); Collection<StopReport> result = ReportUtils.detectStops(data, tripsConfig, false, 0.01); @@ -227,7 +227,7 @@ public class ReportUtilsTest extends BaseTest { position("2016-01-01 00:24:00.000", 5, 800), position("2016-01-01 00:25:00.000", 5, 900)); - TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, 900000); + TripsConfig tripsConfig = new TripsConfig(500, 200000, 200000, 900000, false); Collection<TripReport> trips = ReportUtils.detectTrips(data, tripsConfig, false, 0.01); |