aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-05-19 00:37:00 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-05-19 00:37:00 +1200
commit05c7db487f3744f6abe348426c44fc708b252428 (patch)
tree028b162dbe0285afc5dd4e5c875c24e0a63af7bc
parentb3d221372103a677002428a57686b61e3facf32c (diff)
downloadtrackermap-server-05c7db487f3744f6abe348426c44fc708b252428.tar.gz
trackermap-server-05c7db487f3744f6abe348426c44fc708b252428.tar.bz2
trackermap-server-05c7db487f3744f6abe348426c44fc708b252428.zip
Improve V680 decoder
-rw-r--r--src/org/traccar/ServerManager.java2
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java168
-rw-r--r--test/org/traccar/protocol/V680ProtocolDecoderTest.java9
3 files changed, 101 insertions, 78 deletions
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 971859099..62de6bf0b 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -488,7 +488,7 @@ public class ServerManager {
serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) '#', (byte) '#', (byte) '#' };
+ byte delimiter[] = { (byte) '#', (byte) '#' };
pipeline.addLast("frameDecoder",
new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
index 205036ebb..e3388576e 100644
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ b/src/org/traccar/protocol/V680ProtocolDecoder.java
@@ -29,14 +29,15 @@ import org.traccar.model.Position;
public class V680ProtocolDecoder extends BaseProtocolDecoder {
+ private Long deviceId;
+
public V680ProtocolDecoder(ServerManager serverManager) {
super(serverManager);
}
static private Pattern pattern = Pattern.compile(
- "#?" +
- "(\\d+)#" + // IMEI
- "([^#]*)#" + // User
+ "(?:#(\\d+)#" + // IMEI
+ "([^#]*)#)?" + // User
"([01])#" + // Fix
"([^#]+)#" + // Password
"[^#]+#" +
@@ -59,78 +60,97 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
throws Exception {
String sentence = (String) msg;
-
- // Parse message
- Matcher parser = pattern.matcher(sentence);
- if (!parser.matches()) {
- return null;
+
+ // Detect device ID
+ if (sentence.length() == 16) {
+ String imei = sentence.substring(1, sentence.length());
+ try {
+ deviceId = getDataManager().getDeviceByImei(imei).getId();
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + imei);
+ }
+ } else {
+
+ // Parse message
+ Matcher parser = pattern.matcher(sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ // Create new position
+ Position position = new Position();
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("v680");
+ Integer index = 1;
+
+ // Get device by IMEI
+ String imei = parser.group(index++);
+ if (imei != null) {
+ try {
+ deviceId = getDataManager().getDeviceByImei(imei).getId();
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + imei);
+ return null;
+ }
+ }
+ if (deviceId == null) {
+ return null;
+ }
+ position.setDeviceId(deviceId);
+
+ // User
+ extendedInfo.set("user", parser.group(index++));
+
+ // Validity
+ position.setValid(parser.group(index++).compareTo("1") == 0 ? true : false);
+
+ // Password
+ extendedInfo.set("password", parser.group(index++));
+
+ // Packet number
+ extendedInfo.set("packet", parser.group(index++));
+
+ // GSM base station
+ extendedInfo.set("gsm", parser.group(index++));
+
+ // 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);
+
+ // 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);
+
+ // Altitude
+ position.setAltitude(0.0);
+
+ // Speed and Course
+ position.setSpeed(Double.valueOf(parser.group(index++)));
+ position.setCourse(Double.valueOf(parser.group(index++)));
+
+ // Date
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ time.clear();
+ time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
+ time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
+
+ // Time
+ 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++)));
+ position.setTime(time.getTime());
+
+ // Extended info
+ position.setExtendedInfo(extendedInfo.toString());
+
+ return position;
}
-
- // Create new position
- Position position = new Position();
- ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("v680");
- Integer index = 1;
-
- // Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
-
- // User
- extendedInfo.set("user", parser.group(index++));
-
- // Validity
- position.setValid(parser.group(index++).compareTo("1") == 0 ? true : false);
-
- // Password
- extendedInfo.set("password", parser.group(index++));
-
- // Packet number
- extendedInfo.set("packet", parser.group(index++));
-
- // GSM base station
- extendedInfo.set("gsm", parser.group(index++));
-
- // 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);
-
- // 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);
-
- // Altitude
- position.setAltitude(0.0);
-
- // Speed and Course
- position.setSpeed(Double.valueOf(parser.group(index++)));
- position.setCourse(Double.valueOf(parser.group(index++)));
-
- // Date
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
- time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
- time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
-
- // Time
- 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++)));
- position.setTime(time.getTime());
-
- // Extended info
- position.setExtendedInfo(extendedInfo.toString());
-
- return position;
+
+ return null;
}
}
diff --git a/test/org/traccar/protocol/V680ProtocolDecoderTest.java b/test/org/traccar/protocol/V680ProtocolDecoderTest.java
index fbf5d5ebd..1d1a74878 100644
--- a/test/org/traccar/protocol/V680ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/V680ProtocolDecoderTest.java
@@ -22,9 +22,6 @@ public class V680ProtocolDecoderTest {
"#356823033219838#1000#0#1478#AUT#1#66830FFB#03855.6628,E,4716.6821,N,001.41,259#130812#143905"));
assertNotNull(decoder.decode(null, null,
- "356823033219838#1000#0#1478#AUT#1#66830FFB#03855.6628,E,4716.6821,N,001.41,259#130812#143905"));
-
- assertNotNull(decoder.decode(null, null,
"#353588102019155##1#0000#AUT#01#7240060be7873f#4849.079800,W,2614.458200,S,0.00,0.00#130413#182110.000"));
assertNotNull(decoder.decode(null, null,
@@ -32,6 +29,12 @@ public class V680ProtocolDecoderTest {
assertNotNull(decoder.decode(null, null,
"#352897045085282##0#0000#AUT#1#72400510730208,00d36307,10734fc4#4647.8922,W,2339.1956,S,2.60,63.74#200413#094310.000"));
+
+ assertNotNull(decoder.decode(null, null,
+ "#356823033537791##0#0000#AUT#1#V#03610.2179,E,5004.5796,N,000.01,349#180513#073758"));
+
+ assertNotNull(decoder.decode(null, null,
+ "#356823031236214##0#0000#AUT#1#V#01904.5491,E,6941.0085,N,000.09,248#170513#160140"));
}