aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 11:12:18 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 11:12:18 +1300
commit43a64fc359f8acf08f97d70ebdb93dafa607dc08 (patch)
tree52da0b19c3da83a57348f603e7dd6467b6717b96
parente997c2642b35350241614acaef6d606e37223fe6 (diff)
downloadtrackermap-server-43a64fc359f8acf08f97d70ebdb93dafa607dc08.tar.gz
trackermap-server-43a64fc359f8acf08f97d70ebdb93dafa607dc08.tar.bz2
trackermap-server-43a64fc359f8acf08f97d70ebdb93dafa607dc08.zip
Remove data model and fix some issues
-rw-r--r--debug.xml30
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java18
-rw-r--r--src/org/traccar/Config.java5
-rw-r--r--src/org/traccar/model/Data.java25
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java6
-rw-r--r--test/org/traccar/helper/DecoderVerifier.java21
11 files changed, 48 insertions, 94 deletions
diff --git a/debug.xml b/debug.xml
index 5192dcb8b..b5ff02981 100644
--- a/debug.xml
+++ b/debug.xml
@@ -73,8 +73,7 @@
uniqueId VARCHAR(128) NOT NULL UNIQUE,
status VARCHAR(128),
lastUpdate TIMESTAMP,
- positionId INT,
- dataId INT);
+ positionId INT);
CREATE TABLE user_device (
userId INT NOT NULL,
@@ -105,16 +104,6 @@
CREATE INDEX position_deviceId_fixTime ON position (deviceId, fixTime);
- CREATE TABLE data (
- id INT PRIMARY KEY AUTO_INCREMENT,
- protocol VARCHAR(128),
- 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);
-
CREATE TABLE server (
id INT PRIMARY KEY AUTO_INCREMENT,
registration BIT NOT NULL,
@@ -245,23 +234,6 @@
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/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index c47c0dc69..f5b549e24 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -16,9 +16,12 @@
package org.traccar;
import java.net.SocketAddress;
+import java.util.Date;
+
import org.jboss.netty.channel.Channel;
import org.traccar.helper.Log;
import org.traccar.model.Device;
+import org.traccar.model.Position;
public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
@@ -71,4 +74,19 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
this.protocol = protocol;
}
+ public void initPositionDetails(Position position) {
+ Position last = Context.getConnectionManager().getLastPosition(getDeviceId());
+ if (last != null) {
+ position.setFixTime(last.getFixTime());
+ position.setValid(last.getValid());
+ position.setLatitude(last.getLatitude());
+ position.setLongitude(last.getLongitude());
+ position.setAltitude(last.getAltitude());
+ position.setSpeed(last.getSpeed());
+ position.setCourse(last.getCourse());
+ } else {
+ position.setFixTime(new Date(0));
+ }
+ }
+
}
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java
index 719f23038..49d6e4fde 100644
--- a/src/org/traccar/Config.java
+++ b/src/org/traccar/Config.java
@@ -17,6 +17,7 @@ package org.traccar;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Properties;
public class Config {
@@ -24,7 +25,9 @@ public class Config {
private final Properties properties = new Properties();
public void load(String file) throws IOException {
- properties.loadFromXML(new FileInputStream(file));
+ try (InputStream inputStream = new FileInputStream(file)) {
+ properties.loadFromXML(inputStream);
+ }
}
public boolean hasKey(String key) {
diff --git a/src/org/traccar/model/Data.java b/src/org/traccar/model/Data.java
deleted file mode 100644
index 4777543ff..000000000
--- a/src/org/traccar/model/Data.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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 Data extends Event implements Factory {
-
- @Override
- public Data create() {
- return new Data();
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index 322ebd06e..29748f489 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -39,9 +39,9 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_HISTORY = 0x12;
private static double convertCoordinate(int raw) {
- double result = raw / 1000000;
- result += (raw % 1000000) / 600000.0;
- return result;
+ int degrees = raw / 1000000;
+ double minutes = (raw % 1000000) / 10000.0;
+ return degrees + minutes / 60;
}
private Position decodePosition(ChannelBuffer buf, boolean history) {
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 6ce282988..184c96c97 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -34,6 +34,12 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private static double convertCoordinate(int raw) {
+ int degrees = raw / 1000000;
+ double minutes = (raw % 1000000) / 10000.0;
+ return degrees + minutes / 60;
+ }
+
private Position decodeNormalMessage(ChannelBuffer buf, Channel channel) {
Position position = new Position();
@@ -66,14 +72,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Coordinates
- int temp = ChannelBufferTools.readHexInteger(buf, 8);
- double latitude = temp % 1000000;
- latitude /= 60 * 10000;
- latitude += temp / 1000000;
- temp = ChannelBufferTools.readHexInteger(buf, 9);
- double longitude = temp % 1000000;
- longitude /= 60 * 10000;
- longitude += temp / 1000000;
+ double latitude = convertCoordinate(ChannelBufferTools.readHexInteger(buf, 8));
+ double longitude = convertCoordinate(ChannelBufferTools.readHexInteger(buf, 9));
// Flags
byte flags = buf.readByte();
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index 82cba08a5..7c5399a37 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -252,7 +252,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
command.append(imei).append(",CCC,").append(positions.size()).append("*");
int checksum = 0;
for (int i = 0; i < command.length(); i += 1) checksum += command.charAt(i);
- command.append(String.format("%02x\r\n", checksum & 0xff).toUpperCase());
+ command.append(String.format("%02x", checksum & 0xff).toUpperCase());
+ command.append("\r\n");
channel.write(command.toString());
}
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index 6dcc19db5..b2e1699c3 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -48,9 +48,9 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder {
}
}
- private static double convertCoordinate(int value) {
- double degrees = value / 1000000;
- double minutes = (value % 1000000) / 10000.0;
+ private static double convertCoordinate(int raw) {
+ int degrees = raw / 1000000;
+ double minutes = (raw % 1000000) / 10000.0;
return degrees + minutes / 60;
}
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index bf7c649ce..51cf6951c 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -125,13 +125,13 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
// Speed
- position.setSpeed(buf.readUnsignedInt() / 100);
+ position.setSpeed(buf.readUnsignedInt() / 100.0);
// Course
- position.setCourse(buf.readUnsignedShort() / 100);
+ position.setCourse(buf.readUnsignedShort() / 100.0);
// Altitude
- position.setAltitude(buf.readUnsignedShort() / 100);
+ position.setAltitude(buf.readUnsignedShort() / 100.0);
// Satellites
int satellitesNumber = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
index 0879d86be..9d5b499cc 100644
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -44,10 +44,10 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
coordinate = 0xffffffffl - coordinate;
}
- double degrees = coordinate / 1000000;
- degrees += (coordinate % 1000000) / 600000.0;
+ long degrees = coordinate / 1000000;
+ double minutes = (coordinate % 1000000) / 10000.0;
- return sign * degrees;
+ return sign * (degrees + minutes / 60);
}
@Override
diff --git a/test/org/traccar/helper/DecoderVerifier.java b/test/org/traccar/helper/DecoderVerifier.java
index 28220b711..38f73aabc 100644
--- a/test/org/traccar/helper/DecoderVerifier.java
+++ b/test/org/traccar/helper/DecoderVerifier.java
@@ -5,7 +5,6 @@ import java.util.List;
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 {
@@ -43,14 +42,6 @@ public class DecoderVerifier {
assertNotNull(position.getAttributes());
}
-
- private static void verifyData(Data data) {
-
- assertNotNull(data.getDeviceId());
-
- assertNotNull(data.getAttributes());
-
- }
public static void verify(Object object) {
@@ -58,19 +49,13 @@ public class DecoderVerifier {
if (object instanceof Position) {
verifyPosition((Position) object);
- } else if (object instanceof Data) {
- verifyData((Data) object);
} else if (object instanceof List) {
- List positions = (List) object;
+ List<Position> positions = (List<Position>) object;
assertFalse(positions.isEmpty());
- for (Object item : positions) {
- if (item instanceof Position) {
- verifyPosition((Position) item);
- } else if (item instanceof Data) {
- verifyData((Data) item);
- }
+ for (Position position : positions) {
+ verifyPosition(position);
}
}