diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-10-27 17:25:52 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-10-27 17:25:52 +1300 |
commit | d3f29ab8a57299dc5bcc8031118f811d1182fdb1 (patch) | |
tree | 7aba54d513fe35965188fd52f3d56507fabbf59b /src/org/traccar/protocol/Ev603ProtocolDecoder.java | |
parent | 72171038c2140acfc11ccae2c90c8b28c592e554 (diff) | |
download | traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.tar.gz traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.tar.bz2 traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.zip |
Complete EV603 protocol (fix #64)
Diffstat (limited to 'src/org/traccar/protocol/Ev603ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Ev603ProtocolDecoder.java | 131 |
1 files changed, 63 insertions, 68 deletions
diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index 6bc13d6d7..7730642f4 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java @@ -1,6 +1,6 @@ /*
* Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
- * Enhancement done by Luis Parada (luis.parada@gmail.com)
+ * Luis Parada (luis.parada@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,10 +27,14 @@ import org.traccar.model.DataManager; import org.traccar.model.Position;
/**
- *
* Ev603 Protocol Decoder
*/
public class Ev603ProtocolDecoder extends GenericProtocolDecoder{
+
+ /**
+ * Device ID
+ */
+ private Long deviceId;
/**
* Initialize
@@ -43,16 +47,14 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ * Regular expressions pattern
*/
static private Pattern pattern = Pattern.compile(
- "!A," + // Start Character
- "([\\d]{2})\\/([\\d]{2})\\/([\\d]{2})," + // Date dd/mm/YY
- "([\\d]{2}):([\\d]{2}):([\\d]{2})," + // Time hh:mm:ss
- "(-?[\\d]+\\.[\\d]+)," + // Latitude (DDMM.MMMM)
- "(-?[\\d]+\\.[\\d]+)," + // Longitude (DDDMM.MMMM)
- "([\\d]+.[\\d]{2})," + // Speed
- "([\\d]+|[\\d]+\\.[\\d]+)," + // degrees
+ "!A," + // Type
+ "(\\d{2})\\/(\\d{2})\\/(\\d{2})," + // Date dd/mm/YY
+ "(\\d{2}):(\\d{2}):(\\d{2})," + // Time hh:mm:ss
+ "(-?\\d+\\.\\d+)," + // Latitude (DDMM.MMMM)
+ "(-?\\d+\\.\\d+)," + // Longitude (DDDMM.MMMM)
+ "(\\d+\\.\\d+)," + // Speed
+ "(\\d+\\.?\\d+)," + // Course
".*");
-
- static private Pattern deviceImei = Pattern.compile("([\\d]+);");
/**
* Decode message
@@ -63,67 +65,60 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ String sentence = (String) msg;
- // Parse message
- Matcher parser = pattern.matcher(sentence);
- if (!parser.matches()) {
- return null;
+ // Detect device ID
+ if (sentence.startsWith("!1,")) {
+ String imei = sentence.substring(3);
+ deviceId = getDataManager().getDeviceByImei(imei).getId();
}
-
- // Create new position
- Position position = new Position();
- StringBuilder extendedInfo = new StringBuilder("<protocol>ev603</protocol>");
-
- // Get imei from First message
- if (sentence.contains("!1,")) {
- Matcher imeiparser = deviceImei.matcher(sentence);
- if (!imeiparser.matches()){
+
+ else if (sentence.startsWith("!A,")) {
+ // Parse message
+ Matcher parser = pattern.matcher(sentence);
+ if (!parser.matches()) {
return null;
- }else{
- String imei = imeiparser.group(1);
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
}
+
+ // Create new position
+ Position position = new Position();
+ position.setDeviceId(deviceId);
+ StringBuilder extendedInfo = new StringBuilder("<protocol>ev603</protocol>");
+ Integer index = 1;
+
+ // 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());
+
+ // Validity
+ position.setValid(true);
+
+ // Coordinates
+ position.setLatitude(Double.valueOf(parser.group(index++)));
+ position.setLongitude(Double.valueOf(parser.group(index++)));
+
+ // Altitude
+ position.setAltitude(0.0);
+
+ // Speed
+ position.setSpeed(Double.valueOf(parser.group(index++)));
+
+ // Course
+ position.setCourse(Double.valueOf(parser.group(index++)));
+
+ // Extended info
+ position.setExtendedInfo(extendedInfo.toString());
+
+ return position;
}
-
- Integer index = 1;
-
- // 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());
-
- // Validity
- position.setValid(true);
-
- // Latitude
- Double latitude = Double.valueOf(parser.group(index++));
- latitude += Double.valueOf(parser.group(index++)) / 60;
- position.setLatitude(latitude);
-
- // Longitude
- Double lonlitude = Double.valueOf(parser.group(index++));
- lonlitude += Double.valueOf(parser.group(index++)) / 60;
- position.setLongitude(lonlitude);
-
- // Altitude
- position.setAltitude(0.0);
-
- // Speed
- position.setSpeed(Double.valueOf(parser.group(index++)));
- position.setCourse(0.0);
-
- // Extended info
- extendedInfo.append("<course>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</course>");
- return position;
+ return null;
}
}
|