aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup/default.xml2
-rw-r--r--src/org/traccar/database/StatisticsManager.java24
-rw-r--r--src/org/traccar/model/Statistics.java1
-rw-r--r--src/org/traccar/protocol/AtrackFrameDecoder.java43
-rw-r--r--src/org/traccar/protocol/DmtProtocolDecoder.java1
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java3
-rw-r--r--test/org/traccar/protocol/AtrackFrameDecoderTest.java28
-rw-r--r--test/org/traccar/protocol/DmtProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java3
9 files changed, 95 insertions, 13 deletions
diff --git a/setup/default.xml b/setup/default.xml
index 6c5035022..47954c9aa 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -22,6 +22,8 @@
<entry key='media.path'>./media</entry>
+ <entry key='server.statistics'>https://www.traccar.org/analytics/</entry>
+
<!-- DATABASE CONFIG -->
<entry key='database.ignoreUnknown'>true</entry>
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java
index 8abadddc5..5b42416ad 100644
--- a/src/org/traccar/database/StatisticsManager.java
+++ b/src/org/traccar/database/StatisticsManager.java
@@ -15,6 +15,9 @@
*/
package org.traccar.database;
+import com.ning.http.client.Request;
+import com.ning.http.client.RequestBuilder;
+import org.joda.time.format.ISODateTimeFormat;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Statistics;
@@ -63,6 +66,27 @@ public class StatisticsManager {
Log.warning(e);
}
+ String url = Context.getConfig().getString("server.statistics");
+ if (url != null) {
+ String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime());
+ Request request = new RequestBuilder("POST")
+ .setUrl(url)
+ .addHeader("Content-Type", "application/x-www-form-urlencoded")
+ .addFormParam("version", Log.getAppVersion())
+ .addFormParam("captureTime", time)
+ .addFormParam("activeUsers", String.valueOf(statistics.getActiveUsers()))
+ .addFormParam("activeDevices", String.valueOf(statistics.getActiveDevices()))
+ .addFormParam("requests", String.valueOf(statistics.getRequests()))
+ .addFormParam("messagesReceived", String.valueOf(statistics.getMessagesReceived()))
+ .addFormParam("messagesStored", String.valueOf(statistics.getMessagesStored()))
+ .addFormParam("mailSent", String.valueOf(statistics.getMailSent()))
+ .addFormParam("smsSent", String.valueOf(statistics.getSmsSent()))
+ .addFormParam("geocoderRequests", String.valueOf(statistics.getGeocoderRequests()))
+ .addFormParam("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()))
+ .build();
+ Context.getAsyncHttpClient().prepareRequest(request).execute();
+ }
+
users.clear();
devices.clear();
requests = 0;
diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java
index 93a9c0d39..c7ae5af7a 100644
--- a/src/org/traccar/model/Statistics.java
+++ b/src/org/traccar/model/Statistics.java
@@ -116,6 +116,7 @@ public class Statistics extends Extensible {
public void setGeocoderRequests(int geocoderRequests) {
this.geocoderRequests = geocoderRequests;
}
+
private int geolocationRequests;
public int getGeolocationRequests() {
diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java
index a075254ea..ce4a9a65f 100644
--- a/src/org/traccar/protocol/AtrackFrameDecoder.java
+++ b/src/org/traccar/protocol/AtrackFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,27 +18,46 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import org.traccar.helper.StringFinder;
-public class AtrackFrameDecoder extends LengthFieldBasedFrameDecoder {
+public class AtrackFrameDecoder extends FrameDecoder {
private static final int KEEPALIVE_LENGTH = 12;
- public AtrackFrameDecoder() {
- super(1024, 4, 2);
- }
-
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
- // Keep alive message
- if (buf.readableBytes() >= KEEPALIVE_LENGTH
- && buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
- return buf.readBytes(KEEPALIVE_LENGTH);
+ if (buf.readableBytes() >= 2) {
+
+ if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
+
+ if (buf.readableBytes() >= KEEPALIVE_LENGTH) {
+ return buf.readBytes(KEEPALIVE_LENGTH);
+ }
+
+ } else if (buf.getUnsignedShort(buf.readerIndex()) == 0x4050) {
+
+ if (buf.readableBytes() > 6) {
+ int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2;
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+ }
+
+ } else {
+
+ int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
+ if (endIndex > 0) {
+ return buf.readBytes(endIndex - buf.readerIndex() + 2);
+ }
+
+ }
+
}
- return super.decode(ctx, channel, buf);
+ return null;
}
}
diff --git a/src/org/traccar/protocol/DmtProtocolDecoder.java b/src/org/traccar/protocol/DmtProtocolDecoder.java
index 9b4f9400b..de51cce7a 100644
--- a/src/org/traccar/protocol/DmtProtocolDecoder.java
+++ b/src/org/traccar/protocol/DmtProtocolDecoder.java
@@ -117,6 +117,7 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder {
position.setFixTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000));
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
+ position.setLongitude(buf.readShort());
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
buf.readUnsignedByte(); // speed accuracy
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 2b546bb26..ec8871865 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -92,7 +92,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+)?,") // fuel average
.number("(d+)?,") // hours
.number("(d+),") // speed
- .number("d+.?d*%,") // power load
+ .number("(d+.?d*%),") // power load
.number("(?:([-+]?d+)|[-+]?),") // temperature
.number("(d+.?d*%),") // throttle
.number("(d+),") // rpm
@@ -211,6 +211,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble(0));
position.set(Position.KEY_HOURS, parser.nextInt());
position.set(Position.KEY_OBD_SPEED, parser.nextInt(0));
+ position.set("powerLoad", parser.next());
position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
position.set(Position.KEY_THROTTLE, parser.next());
position.set(Position.KEY_RPM, parser.nextInt(0));
diff --git a/test/org/traccar/protocol/AtrackFrameDecoderTest.java b/test/org/traccar/protocol/AtrackFrameDecoderTest.java
new file mode 100644
index 000000000..93e804dc9
--- /dev/null
+++ b/test/org/traccar/protocol/AtrackFrameDecoderTest.java
@@ -0,0 +1,28 @@
+package org.traccar.protocol;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class AtrackFrameDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ AtrackFrameDecoder decoder = new AtrackFrameDecoder();
+
+ Assert.assertEquals(
+ binary("244F4B0D0A"),
+ decoder.decode(null, null, binary("244F4B0D0A")));
+
+ Assert.assertEquals(
+ binary("fe0200014104d8f196820001"),
+ decoder.decode(null, null, binary("fe0200014104d8f196820001")));
+
+ Assert.assertEquals(
+ binary("40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000"),
+ decoder.decode(null, null, binary("40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000")));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/DmtProtocolDecoderTest.java b/test/org/traccar/protocol/DmtProtocolDecoderTest.java
index 3a2bf28f1..2575d77ed 100644
--- a/test/org/traccar/protocol/DmtProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/DmtProtocolDecoderTest.java
@@ -19,6 +19,9 @@ public class DmtProtocolDecoderTest extends ProtocolTest {
"0255220000"));
verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
+ "025504d80352000602000052185c0803001552185c0842ee19eaba2524682d000d060973112b0302080100000000000300060901421003e40604140007190b300000000c030000000de80100000ec90e00000f0700000052000702000069185c0803001569185c089ac019ea0ad223682300fb02047d152f03020801000000000003000609013f1003fc0604140007190b300000000c030000000de90100000ecb0e00000f0700000052000802000092185c0803001592185c0800a619eaa5e7226821009c0506880e250302080100000000000300060901411003f30604140007190b300000000c030000000dea0100000ef10e00000f07000000520009020000a9185c08030015a9185c0818ae19ea1e62226826001e05038e0e2203020801000000000003000609013f1003030704140007190b300000000c030000000deb0100000ef60e00000f0700000052000a020000c0185c08030015c0185c0893b619ea7fd321681a00640403860f1d0302080100000000000300060901401003ff0604140007190b300000000c030000000dec0100000ef80e00000f0700000052000b020000d7185c08030015d7185c08e08519eab7c921682300fd04035510270302080100000000000300060901401003ea0604140007190b300000000c030000000ded0100000efa0e00000f0700000052000c020000ee185c08030015ee185c08f61719ea61e221682c004c0503540f190302080100000000000300060901421003dd0604140007190b300000000c030000000dee0100000efc0e00000f0700000052000d02000005195c0803001505195c0836b518eac9f221683000fa0107740e2d03020801000000000003000609013f1003fe0604140007190b300000000c030000000def0100000efe0e00000f0700000052000e0200001d195c080300151d195c08d1b518ea2d6721682300980502870e1d0302080100000000000300060901411003ed0604140007190b300000000c030000000df00100000e000f00000f0700000052000f02000034195c0803001534195c086acd18ea742b2168400006020500132903020801000000000003000609013d10030d0704140007190b300000000c030000000df10100000e030f00000f070000005200100200004d195c080300154d195c08dfba18eab81721684e003000093b0e1e03020801000000000003000609013e1003130704140007190b300000000c030000000df20100000e050f00000f0700000052001102000065195c0803001565195c081db318ea871f216822000400080416250302080100000000000300060901401003060704140007190b300000000c030000000df30100000e090f00000f07000000"));
+
+ verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
"025504e9032f000d000000000000001501222700524553455420446172742033342e322e312e3920666c6167733d312057443d303f000e0000000000000015013214004e6f2041646d696e20706172616d7320666f756e64202d207573696e672064656661756c7473202b204175746f41504e37000f00000000000000090015000000000000000000000000000000000000000000020805000000000007000609012b1002400003700e37001000000000000000090015000000000000000000000000000000000000000000020801000000000007000609012b1002400003700e37001100000000000000090015000000000000000000000000000000000000000000020800000000000007000609012b1002400003700e37001200000000000000020015000000000000000000000000000000000000000000020800000000000006000609012b1002400003700e370013000000000000000f001500000000000000000000000000000000000000000002080000000000000200060901271002370003670e2e0014000000000000001501211300526f6c6c20646574656374656420636f735e32203c203338333535333838343700150000000000000017001500000000000000000000000000000000000000000002080000000000000200060901071002300003d60e2a00160000000000000015011d130054756d626c65722074726967676572656420636f735e32203c20302e0017000000000000001501211300526f6c6c20646574656374656420636f735e32203c203338333535333838343700180000000000000017001500000000000000000000000000000000000000000002080000000000000200060901071002300003f70e2a00190000000000000015011d130054756d626c65722074726967676572656420636f735e32203c203026001a000000000000001501190b0047534d3a20544350206261642053594e432063686172732e001b000000000000001501211300526f6c6c20646574656374656420636f735e32203c203338333535333838343a001c0000000000000017001500000000000000000000000000000000000000000002080000000000000200060c01c90f02300003e20f041f002a001d0000000000000015011d130054756d626c65722074726967676572656420636f735e32203c20302e001e000000000000001501211300526f6c6c20646574656374656420636f735e32203c203338333535333838343a001f0000000000000017001500000000000000000000000000000000000000000002080000000000000200060c01d80f02300003ff0f0418002a00200000000000000015011d130054756d626c65722074726967676572656420636f735e32203c2030"));
verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
index ee48ebb27..acafe3982 100644
--- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest {
Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol());
+ verifyAttributes(decoder, text(
+ "imei:862106025092216,OBD,170605095949,195874,,370.8,808,066,30.0%,+87,13.0%,02444,14.3,,,,;"));
+
verifyNull(decoder, text(
"imei:868683027825532,OBD,170613203014,,,,0,0,0.00%,0,0.00%,0,0.00,,,,;"));