aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net/sourceforge/opentracking/TrackerEventHandler.java10
-rw-r--r--src/net/sourceforge/opentracking/helper/NamedParameterStatement.java43
-rw-r--r--src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java6
-rw-r--r--test/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoderTest.java2
4 files changed, 21 insertions, 40 deletions
diff --git a/src/net/sourceforge/opentracking/TrackerEventHandler.java b/src/net/sourceforge/opentracking/TrackerEventHandler.java
index b47f3be5a..d052cb86e 100644
--- a/src/net/sourceforge/opentracking/TrackerEventHandler.java
+++ b/src/net/sourceforge/opentracking/TrackerEventHandler.java
@@ -40,21 +40,23 @@ public class TrackerEventHandler extends SimpleChannelHandler {
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
- //System.out.println("message recieved");
-
if (e.getMessage() instanceof Position) {
+
+ Position position = (Position) e.getMessage();
+
+ System.out.println("id: " + position.getDeviceId() + ", lat: " + position.getLatitude() + ", lon: " + position.getLongitude() );
// Write position to database
try {
- dataManager.setPosition((Position) e.getMessage());
+ dataManager.setPosition(position);
} catch (Exception error) {
+ System.out.println(error.getMessage());
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
- //System.out.println("error: " + e.getCause().getMessage());
e.getChannel().close();
}
diff --git a/src/net/sourceforge/opentracking/helper/NamedParameterStatement.java b/src/net/sourceforge/opentracking/helper/NamedParameterStatement.java
index 2480a15e2..4e5ffc4fc 100644
--- a/src/net/sourceforge/opentracking/helper/NamedParameterStatement.java
+++ b/src/net/sourceforge/opentracking/helper/NamedParameterStatement.java
@@ -1,18 +1,3 @@
-/*
- * Copyright 2010 Anton Tananaev (anton@tananaev.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 net.sourceforge.opentracking.helper;
import java.sql.Connection;
@@ -128,34 +113,26 @@ public class NamedParameterStatement {
statement.close();
}
- /**
- * Set a parameter
- */
- /*public void setObject(String name, Object value) throws SQLException {
+ public void setInt(String name, int value) throws SQLException {
List indexList = (List) indexMap.get(name);
- if (indexList != null) {
- for (Object index: indexList) {
- statement.setObject((Integer) index, value);
- }
- }
- else {
- throw new IllegalArgumentException();
+ if (indexList != null) for (Object index: indexList) {
+ statement.setInt((Integer) index, value);
}
- }*/
+ }
- public void setInt(String name, int value) throws SQLException {
+ public void setLong(String name, long value) throws SQLException {
List indexList = (List) indexMap.get(name);
- for (Object index: indexList) {
- statement.setInt((Integer) index, value);
+ if (indexList != null) for (Object index: indexList) {
+ statement.setLong((Integer) index, value);
}
}
public void setBoolean(String name, boolean value) throws SQLException {
List indexList = (List) indexMap.get(name);
- for (Object index: indexList) {
+ if (indexList != null) for (Object index: indexList) {
statement.setBoolean((Integer) index, value);
}
}
@@ -163,7 +140,7 @@ public class NamedParameterStatement {
public void setDouble(String name, double value) throws SQLException {
List indexList = (List) indexMap.get(name);
- for (Object index: indexList) {
+ if (indexList != null) for (Object index: indexList) {
statement.setDouble((Integer) index, value);
}
}
@@ -171,7 +148,7 @@ public class NamedParameterStatement {
public void setTimestamp(String name, Date value) throws SQLException {
List indexList = (List) indexMap.get(name);
- for (Object index: indexList) {
+ if (indexList != null) for (Object index: indexList) {
statement.setTimestamp(
(Integer) index,
new Timestamp(value.getTime()));
diff --git a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
index 63b1e0f13..bcce3531c 100644
--- a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java
@@ -17,6 +17,7 @@ package net.sourceforge.opentracking.protocol.gps103;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.TimeZone;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.jboss.netty.channel.Channel;
@@ -69,7 +70,9 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder {
throws Exception {
// Parse message
+
String sentence = (String) msg;
+ System.out.println("message: " + sentence);
Matcher parser = pattern.matcher(sentence);
if (!parser.matches()) {
return null;
@@ -85,8 +88,7 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder {
position.setDeviceId(dataManager.getDeviceByImei(imei).getId());
// Time
- Calendar time = new GregorianCalendar();
- time.clear();
+ Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
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++)));
diff --git a/test/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoderTest.java b/test/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoderTest.java
index 3ec430db2..6e767cb43 100644
--- a/test/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoderTest.java
+++ b/test/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoderTest.java
@@ -56,4 +56,4 @@ public class Gps103ProtocolDecoderTest {
assertEquals(deviceId, position.getDeviceId());
}
-} \ No newline at end of file
+}