aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-12-17 22:57:05 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-12-17 22:57:05 +1300
commit34923934e0ee7d707aa9ffef2712942115236472 (patch)
tree1e213cce9e4544421cb0196dc8c4df5bcf98e9f7 /src
parent1cde955eb9e506ec3a4cf4b3829d88b798d45175 (diff)
downloadtraccar-server-34923934e0ee7d707aa9ffef2712942115236472.tar.gz
traccar-server-34923934e0ee7d707aa9ffef2712942115236472.tar.bz2
traccar-server-34923934e0ee7d707aa9ffef2712942115236472.zip
Improved progress decoder
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/Server.java34
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java1
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java51
3 files changed, 77 insertions, 9 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index 9deb271da..506513b60 100644
--- a/src/org/traccar/Server.java
+++ b/src/org/traccar/Server.java
@@ -111,6 +111,8 @@ public class Server {
initNavisServer(properties);
initMeitrackServer(properties);
initSkypatrolServer(properties);
+ initGt02Server(properties);
+ initGt06Server(properties);
// Initialize web server
if (Boolean.valueOf(properties.getProperty("http.enable"))) {
@@ -810,4 +812,36 @@ public class Server {
serverList.add(server);
}
}
+
+ /**
+ * Init GT02 server
+ */
+ private void initGt02Server(Properties properties) throws SQLException {
+
+ String protocol = "gt02";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(new ServerBootstrap());
+ server.setPort(getProtocolPort(properties, protocol));
+ server.setAddress(getProtocolInterface(properties, protocol));
+ //server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ final Integer resetDelay = getProtocolResetDelay(properties, protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), resetDelay, geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0));
+ pipeline.addLast("objectDecoder", new NavisProtocolDecoder(getDataManager()));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init GT06 server
+ */
+ private void initGt06Server(Properties properties) throws SQLException {
+ }
+
}
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index f17839594..073d6ef71 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -220,6 +220,7 @@ public class DatabaseDataManager implements DataManager {
queryAddPosition.prepare();
+ queryAddPosition.setLong("id", position.getId());
queryAddPosition.setLong("device_id", position.getDeviceId());
queryAddPosition.setTimestamp("time", position.getTime());
queryAddPosition.setBoolean("valid", position.getValid());
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 0494b339f..64aca8157 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -15,9 +15,9 @@
*/
package org.traccar.protocol;
+import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.TimeZone;
-import java.nio.charset.Charset;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
@@ -60,6 +60,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
/**
* Decode message
*/
+ @Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
@@ -74,22 +75,24 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
length = buf.readUnsignedShort();
buf.skipBytes(length);
length = buf.readUnsignedShort();
+ buf.skipBytes(length);
+ length = buf.readUnsignedShort();
String imei = buf.readBytes(length).toString(Charset.defaultCharset());
try {
deviceId = getDataManager().getDeviceByImei(imei).getId();
} catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ Log.warning("Unknown device - " + imei + " (id - " + id + ")");
}
}
// Position
- else if (type == MSG_POINT || type == MSG_ALARM) {
+ else if (deviceId != 0 && (type == MSG_POINT || type == MSG_ALARM)) {
Position position = new Position();
StringBuilder extendedInfo = new StringBuilder("<protocol>progress</protocol>");
position.setDeviceId(deviceId);
// Message index
- buf.readUnsignedInt();
+ position.setId(buf.readUnsignedInt());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -114,9 +117,11 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
// Satellites
int satellitesNumber = buf.readUnsignedByte();
- extendedInfo.append("<sat>");
+ extendedInfo.append("<satellites>");
extendedInfo.append(satellitesNumber);
- extendedInfo.append("</sat>");
+ extendedInfo.append("</satellites>");
+
+ // Validity
position.setValid(satellitesNumber >= 3); // TODO: probably wrong
// Cell signal
@@ -124,10 +129,35 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
extendedInfo.append(buf.readUnsignedByte());
extendedInfo.append("</gsm>");
- // TODO: process other data
+ // Milage
+ extendedInfo.append("<milage>");
+ extendedInfo.append(buf.readUnsignedInt());
+ extendedInfo.append("</milage>");
+
+ long extraFlags = buf.readLong();
+
+ // Analog inputs
+ if ((extraFlags & 0x1) == 0x1) {
+ int count = buf.readUnsignedShort();
+ for (int i = 1; i <= count; i++) {
+ extendedInfo.append("<adc").append(i).append(">");
+ extendedInfo.append(buf.readUnsignedShort());
+ extendedInfo.append("</adc").append(i).append(">");
+ }
+
+ }
- // Extended info
- position.setExtendedInfo(extendedInfo.toString());
+ // CAN adapter
+ if ((extraFlags & 0x2) == 0x2) {
+ int size = buf.readUnsignedShort();
+ buf.skipBytes(size);
+ }
+
+ // Passenger sensor
+ if ((extraFlags & 0x4) == 0x4) {
+ int size = buf.readUnsignedShort();
+ buf.skipBytes(size);
+ }
// Send response for alarm message
if (type == MSG_ALARM) {
@@ -137,6 +167,9 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
extendedInfo.append("<alarm>true</alarm>");
}
+ // Extended info
+ position.setExtendedInfo(extendedInfo.toString());
+
return position;
}