aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/Server.java27
-rw-r--r--src/org/traccar/protocol/Ev603ProtocolDecoder.java131
2 files changed, 89 insertions, 69 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index 140862d8b..f61edcede 100644
--- a/src/org/traccar/Server.java
+++ b/src/org/traccar/Server.java
@@ -101,7 +101,7 @@ public class Server {
initProgressServer(properties);
initH02Server(properties);
initJt600Server(properties);
-
+ initEv603Server(properties);
// Initialize web server
if (Boolean.valueOf(properties.getProperty("http.enable"))) {
@@ -569,4 +569,29 @@ public class Server {
serverList.add(server);
}
}
+
+ /**
+ * Init EV603 server
+ */
+ private void initEv603Server(Properties properties) throws SQLException {
+
+ String protocol = "ev603";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties, protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) ';' };
+ pipeline.addLast("frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
}
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;
}
}