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 | |
parent | 72171038c2140acfc11ccae2c90c8b28c592e554 (diff) | |
download | traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.tar.gz traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.tar.bz2 traccar-server-d3f29ab8a57299dc5bcc8031118f811d1182fdb1.zip |
Complete EV603 protocol (fix #64)
-rw-r--r-- | default.cfg | 4 | ||||
-rw-r--r-- | src/org/traccar/Server.java | 27 | ||||
-rw-r--r-- | src/org/traccar/protocol/Ev603ProtocolDecoder.java | 131 | ||||
-rwxr-xr-x | test.sh | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/Ev603ProtocolDecoderTest.java | 24 |
5 files changed, 120 insertions, 69 deletions
diff --git a/default.cfg b/default.cfg index b55178f92..7801a457b 100644 --- a/default.cfg +++ b/default.cfg @@ -151,4 +151,8 @@ <entry key="jt600.enable">true</entry> <entry key="jt600.port">5014</entry> + <!-- EV603 server configuration --> + <entry key="ev603.enable">true</entry> + <entry key="ev603.port">5015</entry> + </properties> 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;
}
}
@@ -53,3 +53,6 @@ echo "13. h02" echo "14. jt600" (echo -n -e "\$\x00\x00\x12\x34\x56\x11\x00\x1B\x01\x01\x12\x12\x14\x00\x60\x00\x00\x00\x13\x00\x00\x00\x0F\x00\x00\x07\x50\x00\x00\x00\x2B\x91\x04\x4D\x1F\xA1";) | nc -v localhost 5014 + +echo "15. ev603" +(echo -n -e "!1,123456789012345;!A,01/01/12,12:15:00,60.000000,130.000000,0.0,25101,0;";) | nc -v localhost 5015 diff --git a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java new file mode 100644 index 000000000..32aaa8ea7 --- /dev/null +++ b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java @@ -0,0 +1,24 @@ +package org.traccar.protocol; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.Test; + +public class Ev603ProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(new TestDataManager(), 0); + + assertNull(decoder.decode(null, null, "!5,17,V")); + + assertNotNull(decoder.decode(null, null, + "!A,26/10/12,00:28:41,7.770385,-72.215706,0.0,25101,0")); + + assertNotNull(decoder.decode(null, null, + "!A,01/12/10,13:25:35,22.641724,114.023666,000.1,281.6,0")); + + } + +} |