aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/sourceforge/opentracking/Position.java13
-rw-r--r--src/net/sourceforge/opentracking/Server.java55
-rw-r--r--src/net/sourceforge/opentracking/protocol/gl200/Gl200ProtocolDecoder.java71
-rw-r--r--src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java3
-rw-r--r--src/net/sourceforge/opentracking/protocol/tk103/Tk103ProtocolDecoder.java3
-rw-r--r--src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java7
6 files changed, 106 insertions, 46 deletions
diff --git a/src/net/sourceforge/opentracking/Position.java b/src/net/sourceforge/opentracking/Position.java
index 0e20c22c1..0c4117448 100644
--- a/src/net/sourceforge/opentracking/Position.java
+++ b/src/net/sourceforge/opentracking/Position.java
@@ -99,6 +99,19 @@ public class Position {
public void setLongitude(Double newLongitude) {
longitude = newLongitude;
}
+
+ /**
+ * Altitude
+ */
+ private Double altitude;
+
+ public Double getAltitude() {
+ return altitude;
+ }
+
+ public void setAltitude(Double newAltitude) {
+ altitude = newAltitude;
+ }
/**
* Speed (knots)
diff --git a/src/net/sourceforge/opentracking/Server.java b/src/net/sourceforge/opentracking/Server.java
index b34e4cf46..5d1332f38 100644
--- a/src/net/sourceforge/opentracking/Server.java
+++ b/src/net/sourceforge/opentracking/Server.java
@@ -44,6 +44,7 @@ import net.sourceforge.opentracking.protocol.xexun.XexunFrameDecoder;
import net.sourceforge.opentracking.protocol.xexun.XexunProtocolDecoder;
import net.sourceforge.opentracking.protocol.gps103.Gps103ProtocolDecoder;
import net.sourceforge.opentracking.protocol.tk103.Tk103ProtocolDecoder;
+import net.sourceforge.opentracking.protocol.gl200.Gl200ProtocolDecoder;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
@@ -90,6 +91,7 @@ public class Server implements DataManager {
initXexunServer(properties);
initGps103Server(properties);
initTk103Server(properties);
+ initGl200Server(properties);
}
/**
@@ -177,6 +179,7 @@ public class Server implements DataManager {
insertPosition.setLong("device_id", position.getDeviceId());
insertPosition.setTimestamp("time", position.getTime());
insertPosition.setBoolean("valid", position.getValid());
+ insertPosition.setDouble("altitude", position.getAltitude());
insertPosition.setDouble("latitude", position.getLatitude());
insertPosition.setDouble("longitude", position.getLongitude());
insertPosition.setDouble("speed", position.getSpeed());
@@ -393,6 +396,58 @@ public class Server implements DataManager {
}
/**
+ * Gl200 pipeline factory
+ */
+ protected class Gl200PipelineFactory implements ChannelPipelineFactory {
+
+ private TrackerServer server;
+ private Server serverCreator;
+ private Integer resetDelay;
+
+ public Gl200PipelineFactory(
+ TrackerServer server, Server serverCreator, Integer resetDelay) {
+ this.server = server;
+ this.serverCreator = serverCreator;
+ this.resetDelay = resetDelay;
+ }
+
+ public ChannelPipeline getPipeline() {
+ ChannelPipeline pipeline = Channels.pipeline();
+ pipeline.addLast("openHandler", new OpenChannelHandler(server));
+ if (serverCreator.isLoggerEnabled()) {
+ pipeline.addLast("logger", new LoggingHandler("logger"));
+ }
+ byte delimiter[] = { (byte) '$' };
+ pipeline.addLast("frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(serverCreator, resetDelay));
+ pipeline.addLast("handler", new TrackerEventHandler(serverCreator));
+ return pipeline;
+ }
+ }
+
+ /**
+ * Init Gl200 server
+ */
+ public void initGl200Server(Properties properties) throws SQLException {
+
+ boolean enable = Boolean.valueOf(properties.getProperty("gl200.enable"));
+ if (enable) {
+
+ TrackerServer server = new TrackerServer(
+ Integer.valueOf(properties.getProperty("gl200.port")));
+
+ String resetDelay = properties.getProperty("gl200.resetDelay");
+ server.setPipelineFactory(new Gl200PipelineFactory(
+ server, this, (resetDelay == null) ? 0 : Integer.valueOf(resetDelay)));
+
+ serverList.add(server);
+ }
+ }
+
+ /**
* Start
*/
public void start() {
diff --git a/src/net/sourceforge/opentracking/protocol/gl200/Gl200ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/gl200/Gl200ProtocolDecoder.java
index 0b7166ab2..6d0e0a8d9 100644
--- a/src/net/sourceforge/opentracking/protocol/gl200/Gl200ProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/gl200/Gl200ProtocolDecoder.java
@@ -58,19 +58,22 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder {
* Regular expressions pattern
*/
static private Pattern pattern = Pattern.compile(
- "imei:" +
- "([\\d]+)," + // IMEI
- "[^,]+," +
- "(\\d{2})(\\d{2})(\\d{2})[\\d]+," + // Date
- "[+]?[\\d]*," +
- "[FL]," + // F - full / L - low
- "([\\d]{2})([\\d]{2})([\\d]{2}).([\\d]{3})," + // Time (HHMMSS.SSS)
- "([AV])," + // Validity
- "([\\d]{2})([\\d]{2}.[\\d]{4})," + // Latitude (DDMM.MMMM)
- "([NS])," +
- "([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM)
- "([EW])," +
- "([\\d]+.[\\d]{2}),"); // Speed
+ "\\+RESP:GT...," +
+ "\\d{6}," + // Protocol version
+ "(\\d{15})," + // IMEI
+ "[^,]*," + // Device name
+ "\\d," + // Report ID
+ "\\d," + // Report type
+ "\\d*," + // Number
+ "(\\d*)," + // GPS accuracy
+ "(\\d+.\\d)," + // Speed
+ "(\\d+)," + // Course
+ "(-?\\d+.\\d)," + // Altitude
+ "(-?\\d+.\\d+)," + // Longitude
+ "(-?\\d+.\\d+)," + // Latitude
+ "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD)
+ "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS)
+ "[^$]*");
/**
* Decode message
@@ -81,16 +84,6 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder {
String sentence = (String) msg;
- // Send response #1
- if (sentence.contains("##")) {
- channel.write("LOAD");
- }
-
- // Send response #2
- if (sentence.length() == 15 && Character.isDigit(sentence.charAt(0))) {
- channel.write("ON");
- }
-
// Parse message
Matcher parser = pattern.matcher(sentence);
if (!parser.matches()) {
@@ -106,10 +99,20 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder {
String imei = parser.group(index++);
position.setDeviceId(dataManager.getDeviceByImei(imei).getId());
+ // Validity
+ position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true);
+
+ // Position info
+ position.setSpeed(Double.valueOf(parser.group(index++)));
+ position.setCourse(Double.valueOf(parser.group(index++)));
+ position.setAltitude(Double.valueOf(parser.group(index++)));
+ position.setLongitude(Double.valueOf(parser.group(index++)));
+ position.setLatitude(Double.valueOf(parser.group(index++)));
+
// Date
Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
time.clear();
- time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++)));
time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
@@ -117,28 +120,8 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder {
time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++)));
time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++)));
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
- time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
position.setTime(time.getTime());
- // Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
-
- // Latitude
- Double latitude = Double.valueOf(parser.group(index++));
- latitude += Double.valueOf(parser.group(index++)) / 60;
- if (parser.group(index++).compareTo("S") == 0) latitude = -latitude;
- position.setLatitude(latitude);
-
- // Longitude
- Double lonlitude = Double.valueOf(parser.group(index++));
- lonlitude += Double.valueOf(parser.group(index++)) / 60;
- if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude;
- position.setLongitude(lonlitude);
-
- // Speed
- position.setSpeed(Double.valueOf(parser.group(index++)));
- position.setCourse(0.0);
-
return position;
}
diff --git a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
index faccc97d7..c9d8e2da1 100644
--- a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
@@ -134,6 +134,9 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder {
lonlitude += Double.valueOf(parser.group(index++)) / 60;
if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude;
position.setLongitude(lonlitude);
+
+ // Altitude
+ position.setAltitude(0.0);
// Speed
position.setSpeed(Double.valueOf(parser.group(index++)));
diff --git a/src/net/sourceforge/opentracking/protocol/tk103/Tk103ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/tk103/Tk103ProtocolDecoder.java
index 2ff6ce949..79350307c 100644
--- a/src/net/sourceforge/opentracking/protocol/tk103/Tk103ProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/tk103/Tk103ProtocolDecoder.java
@@ -126,6 +126,9 @@ public class Tk103ProtocolDecoder extends OneToOneDecoder {
if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude;
position.setLongitude(lonlitude);
+ // Altitude
+ position.setAltitude(0.0);
+
// Speed
position.setSpeed(Double.valueOf(parser.group(index++)));
diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
index afd2405c8..73b7cef11 100644
--- a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
@@ -66,8 +66,8 @@ public class XexunProtocolDecoder extends OneToOneDecoder {
"([NS])," +
"([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM)
"([EW])," +
- "([\\d]+.[\\d]{2})," + // Speed
- "([\\d]+.[\\d]{2})?," + // Course
+ "([\\d]+.[\\d]+)," + // Speed
+ "([\\d]+.[\\d]+)?," + // Course
"([\\d]{2})([\\d]{2})([\\d]{2})," + // Date (DDMMYY)
".*imei:" +
"([\\d]+),"); // IMEI
@@ -114,6 +114,9 @@ public class XexunProtocolDecoder extends OneToOneDecoder {
if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude;
position.setLongitude(lonlitude);
+ // Altitude
+ position.setAltitude(0.0);
+
// Speed
position.setSpeed(Double.valueOf(parser.group(index++)));