aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/model/Position.java1
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java34
-rw-r--r--src/org/traccar/reports/Trips.java39
-rw-r--r--test/org/traccar/protocol/CalAmpProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/GoSafeProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/reports/TripsTest.java69
7 files changed, 131 insertions, 33 deletions
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index b2965c89c..8ca2588e2 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -59,6 +59,7 @@ public class Position extends Message {
public static final String KEY_MOTION = "motion";
public static final String KEY_ARMED = "armed";
public static final String KEY_ACCURACY = "accuracy";
+ public static final String KEY_GEOFENCE = "geofence";
public static final String KEY_DTCS = "dtcs";
public static final String KEY_OBD_SPEED = "obdSpeed";
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index 510684411..ee4cc65b4 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -149,19 +149,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
int content = buf.readUnsignedByte();
if (BitUtil.check(content, 0)) {
-
- int length = buf.readUnsignedByte();
- long id = 0;
- for (int i = 0; i < length; i++) {
- int b = buf.readUnsignedByte();
- id = id * 10 + (b >> 4);
- if ((b & 0xf) != 0xf) {
- id = id * 10 + (b & 0xf);
- }
- }
-
- getDeviceSession(channel, remoteAddress, String.valueOf(id));
-
+ String id = ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()));
+ getDeviceSession(channel, remoteAddress, id);
}
if (BitUtil.check(content, 1)) {
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index a258e922c..1ae527160 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -90,13 +90,14 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.groupBegin()
.text("DTT:")
.number("(x+);") // status
- .expression("[^;]*;")
- .number("x+;") // geo-fence 0-119
- .number("x+;") // geo-fence 120-155
- .number("x+,?") // event status
+ .number("(x+)?;") // io
+ .number("(x+);") // geo-fence 0-119
+ .number("(x+);") // geo-fence 120-155
+ .number("(x+)") // event status
+ .number("(?:;(x+))?,?") // packet type
.groupEnd("?")
.groupBegin()
- .text("ETD:").expression("[^,]*,?")
+ .text("ETD:").expression("([^,]+),?")
.groupEnd("?")
.groupBegin()
.text("OBD:")
@@ -108,6 +109,9 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.groupBegin()
.text("TRU:").expression("[^,]*,?")
.groupEnd("?")
+ .groupBegin()
+ .text("TAG:").expression("([^,]+),?")
+ .groupEnd("?")
.compile();
private static final Pattern PATTERN_OLD = new PatternBuilder()
@@ -122,7 +126,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.number("([EW])(d+.d+);") // longitude
.number("(d+)?;") // speed
.number("(d+);") // course
- .number("(d+.?d*)").optional() // hdop
+ .number("(d+.?d*)").optional() // hdop
.number("(dd)(dd)(dd)") // date
.any()
.compile();
@@ -162,16 +166,28 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_POWER, parser.next());
position.set(Position.KEY_BATTERY, parser.next());
- String status = parser.next();
- if (status != null) {
- position.set(Position.KEY_IGNITION, BitUtil.check(Integer.parseInt(status, 16), 13));
+ if (parser.hasNext(6)) {
+ long status = parser.nextLong(16);
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 13));
position.set(Position.KEY_STATUS, status);
+ position.set("ioStatus", parser.next());
+ position.set(Position.KEY_GEOFENCE, parser.next() + parser.next());
+ position.set("eventStatus", parser.next());
+ position.set("packetType", parser.next());
+ }
+
+ if (parser.hasNext()) {
+ position.set("eventData", parser.next());
}
if (parser.hasNext()) {
position.set("obd", parser.next());
}
+ if (parser.hasNext()) {
+ position.set("tagData", parser.next());
+ }
+
return position;
}
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index d4e25f5e5..a52d48f16 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -46,7 +46,8 @@ public final class Trips {
private Trips() {
}
- private static TripReport calculateTrip(ArrayList<Position> positions, int startIndex, int endIndex) {
+ private static TripReport calculateTrip(
+ ArrayList<Position> positions, int startIndex, int endIndex, boolean ignoreOdometer) {
Position startTrip = positions.get(startIndex);
Position endTrip = positions.get(endIndex);
@@ -79,8 +80,6 @@ public final class Trips {
trip.setEndTime(endTrip.getFixTime());
trip.setEndAddress(endTrip.getAddress());
- boolean ignoreOdometer = Context.getDeviceManager()
- .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip, !ignoreOdometer));
trip.setDuration(tripDuration);
trip.setAverageSpeed(speedSum / (endIndex - startIndex));
@@ -90,15 +89,14 @@ public final class Trips {
return trip;
}
- private static Collection<TripReport> detectTrips(long deviceId, Date from, Date to) throws SQLException {
- double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01);
- long minimalTripDuration = Context.getConfig().getLong("report.trip.minimalTripDuration", 300) * 1000;
- double minimalTripDistance = Context.getConfig().getLong("report.trip.minimalTripDistance", 500);
- long minimalParkingDuration = Context.getConfig().getLong("report.trip.minimalParkingDuration", 300) * 1000;
- boolean greedyParking = Context.getConfig().getBoolean("report.trip.greedyParking");
+ protected static Collection<TripReport> detectTrips(
+ double speedThreshold, double minimalTripDistance,
+ long minimalTripDuration, long minimalParkingDuration, boolean greedyParking, boolean ignoreOdometer,
+ Collection<Position> positionCollection) {
+
Collection<TripReport> result = new ArrayList<>();
- ArrayList<Position> positions = new ArrayList<>(Context.getDataManager().getPositions(deviceId, from, to));
+ ArrayList<Position> positions = new ArrayList<>(positionCollection);
if (positions != null && !positions.isEmpty()) {
int previousStartParkingIndex = 0;
int startParkingIndex = -1;
@@ -150,7 +148,8 @@ public final class Trips {
if ((parkingDuration >= minimalParkingDuration || isLast)
&& previousEndParkingIndex < startParkingIndex) {
if (!tripFiltered) {
- result.add(calculateTrip(positions, previousEndParkingIndex, startParkingIndex));
+ result.add(calculateTrip(
+ positions, previousEndParkingIndex, startParkingIndex, ignoreOdometer));
}
previousEndParkingIndex = endParkingIndex;
skipped = false;
@@ -161,9 +160,26 @@ public final class Trips {
}
}
}
+
return result;
}
+ private static Collection<TripReport> detectTrips(long deviceId, Date from, Date to) throws SQLException {
+ double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01);
+ long minimalTripDuration = Context.getConfig().getLong("report.trip.minimalTripDuration", 300) * 1000;
+ double minimalTripDistance = Context.getConfig().getLong("report.trip.minimalTripDistance", 500);
+ long minimalParkingDuration = Context.getConfig().getLong("report.trip.minimalParkingDuration", 300) * 1000;
+ boolean greedyParking = Context.getConfig().getBoolean("report.trip.greedyParking");
+
+ boolean ignoreOdometer = Context.getDeviceManager()
+ .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
+
+ return detectTrips(
+ speedThreshold, minimalTripDistance, minimalTripDuration,
+ minimalParkingDuration, greedyParking, ignoreOdometer,
+ Context.getDataManager().getPositions(deviceId, from, to));
+ }
+
public static Collection<TripReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
ArrayList<TripReport> result = new ArrayList<>();
@@ -217,4 +233,5 @@ public final class Trips {
transformer.write();
}
}
+
}
diff --git a/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java b/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java
index 8d7d5f9fe..b6fb5bd0e 100644
--- a/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class CalAmpProtocolDecoderTest extends ProtocolTest {
CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(new CalAmpProtocol());
verifyPosition(decoder, binary(
+ "83092701131797081078220107010200dc583d4d3f583d4d3f19c70502cd1d512d00005f180000008500ec0800101eff980f090100313102000000000000000000"));
+
+ verifyPosition(decoder, binary(
"8305133303910501010102004557E5AB2457E3B3E01FD828DBFE9E3465000028C90000004201310704001EFFA12F0B22081BCA05000000000000000F87000E8E2F00EA029E0000082D"));
verifyPosition(decoder, binary(
diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
index fb0dec4fb..35cf5fcb2 100644
--- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest {
GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol());
+ verifyPositions(decoder, text(
+ "*GS26,356449061139936,022918011216,,SYS:G737IC;V1.13;V1.0.5,GPS:A;9;N42.651728;W70.623520;0;0;48;1.50,ADC:4.08,DTT:3900C;;0;0;0;1,#"));
+
verifyNotNull(decoder, text(
"*GS56,356449063230915,052339180916,,SYS:G7S;V1.08;V1.2,GPS:V;4;N24.730006;E46.637816;14;0;630,GSM:;;420;4;5655;507A;-70,COT:75242;2-8-17,ADC:13.22;0.08,DTT:23004;;0;0;0;1#"));
diff --git a/test/org/traccar/reports/TripsTest.java b/test/org/traccar/reports/TripsTest.java
new file mode 100644
index 000000000..7b860b63d
--- /dev/null
+++ b/test/org/traccar/reports/TripsTest.java
@@ -0,0 +1,69 @@
+package org.traccar.reports;
+
+import org.junit.Test;
+import org.traccar.model.Position;
+import org.traccar.reports.model.TripReport;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.TimeZone;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class TripsTest {
+
+ private Date date(String time) throws ParseException {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return dateFormat.parse(time);
+ }
+
+ private Position position(String time, double speed, double totalDistance) throws ParseException {
+
+ Position position = new Position();
+
+ if (time != null) {
+ position.setTime(date(time));
+ }
+ position.setValid(true);
+ position.setSpeed(speed);
+ position.set(Position.KEY_TOTAL_DISTANCE, totalDistance);
+
+ return position;
+ }
+
+ @Test
+ public void testDetectTripsSimple() throws ParseException {
+
+ Collection<Position> data = Arrays.asList(
+ position("2016-01-01 00:00:00.000", 0, 0),
+ position("2016-01-01 00:01:00.000", 0, 0),
+ position("2016-01-01 00:02:00.000", 10, 0),
+ position("2016-01-01 00:03:00.000", 10, 1000),
+ position("2016-01-01 00:04:00.000", 10, 2000),
+ position("2016-01-01 00:05:00.000", 0, 3000),
+ position("2016-01-01 00:06:00.000", 0, 3000));
+
+ Collection<TripReport> result = Trips.detectTrips(0.01, 500, 300000, 300000, false, false, data);
+
+ assertNotNull(result);
+ assertFalse(result.isEmpty());
+
+ TripReport item = result.iterator().next();
+
+ assertEquals(date("2016-01-01 00:02:00.000"), item.getStartTime());
+ assertEquals(date("2016-01-01 00:05:00.000"), item.getEndTime());
+ assertEquals(180000, item.getDuration());
+ assertEquals(10, item.getAverageSpeed(), 0.01);
+ assertEquals(10, item.getMaxSpeed(), 0.01);
+ assertEquals(3000, item.getDistance(), 0.01);
+
+ }
+
+}