aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml18
-rw-r--r--src/org/traccar/model/Command.java35
-rw-r--r--src/org/traccar/model/Event.java10
-rw-r--r--src/org/traccar/model/Extensible.java2
-rw-r--r--src/org/traccar/model/Message.java40
-rw-r--r--test/org/traccar/helper/DecoderVerifier.java25
-rw-r--r--test/org/traccar/protocol/Gt06ProtocolDecoderTest.java5
7 files changed, 99 insertions, 36 deletions
diff --git a/debug.xml b/debug.xml
index 5350536a1..5192dcb8b 100644
--- a/debug.xml
+++ b/debug.xml
@@ -111,6 +111,7 @@
deviceId INT NOT NULL,
serverTime TIMESTAMP NOT NULL,
deviceTime TIMESTAMP NOT NULL,
+ type VARCHAR(128),
attributes VARCHAR(4096) NOT NULL,
FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE);
@@ -244,6 +245,23 @@
UPDATE device SET positionId = :id WHERE id = :deviceId;
</entry>
+ <entry key='database.selectData'>
+ SELECT * FROM data WHERE deviceId = :deviceId AND deviceTime BETWEEN :from AND :to ORDER BY deviceTime;
+ </entry>
+
+ <entry key='database.insertData'>
+ INSERT INTO data (deviceId, protocol, serverTime, deviceTime, type, attributes)
+ VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :type, :attributes);
+ </entry>
+
+ <entry key='database.selectLatestData'>
+ SELECT * FROM data WHERE id IN (SELECT dataId FROM device);
+ </entry>
+
+ <entry key='database.updateLatestData'>
+ UPDATE device SET dataId = :id WHERE id = :deviceId;
+ </entry>
+
<!-- PROTOCOL CONFIG -->
<!--<entry key='detector.port'>5000</entry>-->
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index 09bb81a74..99525a02b 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.model;
public class Command extends Extensible implements Factory {
@@ -21,24 +36,4 @@ public class Command extends Extensible implements Factory {
return new Command();
}
- private long deviceId;
-
- public long getDeviceId() {
- return deviceId;
- }
-
- public void setDeviceId(long deviceId) {
- this.deviceId = deviceId;
- }
-
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 586885c4a..172203a86 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -80,16 +80,6 @@ public abstract class Event extends Extensible {
this.protocol = protocol;
}
- private long deviceId;
-
- public long getDeviceId() {
- return deviceId;
- }
-
- public void setDeviceId(long deviceId) {
- this.deviceId = deviceId;
- }
-
private Date serverTime;
public Date getServerTime() {
diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java
index d32fec61a..a821d0e43 100644
--- a/src/org/traccar/model/Extensible.java
+++ b/src/org/traccar/model/Extensible.java
@@ -18,7 +18,7 @@ package org.traccar.model;
import java.util.LinkedHashMap;
import java.util.Map;
-public abstract class Extensible {
+public abstract class Extensible extends Message {
private Map<String, Object> attributes = new LinkedHashMap<>();
diff --git a/src/org/traccar/model/Message.java b/src/org/traccar/model/Message.java
new file mode 100644
index 000000000..bac6661a8
--- /dev/null
+++ b/src/org/traccar/model/Message.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.model;
+
+public class Message {
+
+ private long deviceId;
+
+ public long getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(long deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+}
diff --git a/test/org/traccar/helper/DecoderVerifier.java b/test/org/traccar/helper/DecoderVerifier.java
index 17b4f9633..28220b711 100644
--- a/test/org/traccar/helper/DecoderVerifier.java
+++ b/test/org/traccar/helper/DecoderVerifier.java
@@ -2,7 +2,10 @@ package org.traccar.helper;
import java.util.Date;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.traccar.model.Data;
import org.traccar.model.Position;
public class DecoderVerifier {
@@ -40,6 +43,14 @@ public class DecoderVerifier {
assertNotNull(position.getAttributes());
}
+
+ private static void verifyData(Data data) {
+
+ assertNotNull(data.getDeviceId());
+
+ assertNotNull(data.getAttributes());
+
+ }
public static void verify(Object object) {
@@ -47,13 +58,19 @@ public class DecoderVerifier {
if (object instanceof Position) {
verifyPosition((Position) object);
+ } else if (object instanceof Data) {
+ verifyData((Data) object);
} else if (object instanceof List) {
- List<Position> positions = (List<Position>) object;
+ List positions = (List) object;
assertFalse(positions.isEmpty());
- for (Position position : positions) {
- verifyPosition(position);
+ for (Object item : positions) {
+ if (item instanceof Position) {
+ verifyPosition((Position) item);
+ } else if (item instanceof Data) {
+ verifyData((Data) item);
+ }
}
}
diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index f8276b123..a72c709f2 100644
--- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -15,7 +15,10 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest {
assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"787811010123456789012345100B3201000171930D0A"))));
-
+
+ assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ "78780a13440604000201baaf540d0a"))));
+
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"787823120f081b121d37cb01c8e2cc08afd3c020d50201940701d600a1190041ee100576d1470d0a"))));