aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-03-23 11:01:41 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-03-23 11:01:41 +1300
commitee4f40561f5cce1a9a07576662af69fadb9851ca (patch)
treea1e674953278269d206653683189fa2cbf924ea7
parent34f61800a807370383df1cafd0d442d69325c648 (diff)
downloadtraccar-server-ee4f40561f5cce1a9a07576662af69fadb9851ca.tar.gz
traccar-server-ee4f40561f5cce1a9a07576662af69fadb9851ca.tar.bz2
traccar-server-ee4f40561f5cce1a9a07576662af69fadb9851ca.zip
Add TK5000 support (fix #177)
-rw-r--r--default.cfg6
-rw-r--r--src/org/traccar/ServerManager.java6
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java (renamed from src/org/traccar/protocol/Vt300ProtocolDecoder.java)49
-rw-r--r--test/org/traccar/protocol/WondexProtocolDecoderTest.java (renamed from test/org/traccar/protocol/Vt300ProtocolDecoderTest.java)7
4 files changed, 39 insertions, 29 deletions
diff --git a/default.cfg b/default.cfg
index 4240bf429..749bdf4d2 100644
--- a/default.cfg
+++ b/default.cfg
@@ -189,9 +189,9 @@
<entry key='syrus.enable'>true</entry>
<entry key='syrus.port'>5031</entry>
- <!-- VT300 server configuration -->
- <entry key='vt300.enable'>true</entry>
- <entry key='vt300.port'>5032</entry>
+ <!-- Wondex server configuration -->
+ <entry key='wondex.enable'>true</entry>
+ <entry key='wondex.port'>5032</entry>
<!-- Cellocator server configuration -->
<entry key='cellocator.enable'>true</entry>
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 9416c4183..59d98af0e 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -137,7 +137,7 @@ public class ServerManager {
initMta6CanServer("mta6can");
initTlt2hServer("tlt2h");
initSyrusServer("syrus");
- initVt300Server("vt300");
+ initWondexServer("wondex");
initCellocatorServer("cellocator");
initGalileoServer("galileo");
@@ -703,7 +703,7 @@ public class ServerManager {
}
}
- private void initVt300Server(String protocol) throws SQLException {
+ private void initWondexServer(String protocol) throws SQLException {
if (isProtocolEnabled(properties, protocol)) {
serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
@Override
@@ -713,7 +713,7 @@ public class ServerManager {
new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Vt300ProtocolDecoder(ServerManager.this));
+ pipeline.addLast("objectDecoder", new WondexProtocolDecoder(ServerManager.this));
}
});
}
diff --git a/src/org/traccar/protocol/Vt300ProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index 9e2b2db13..5e3f3f390 100644
--- a/src/org/traccar/protocol/Vt300ProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -26,17 +26,15 @@ import org.traccar.ServerManager;
import org.traccar.helper.Log;
import org.traccar.model.Position;
-public class Vt300ProtocolDecoder extends BaseProtocolDecoder {
+public class WondexProtocolDecoder extends BaseProtocolDecoder {
- public Vt300ProtocolDecoder(ServerManager serverManager) {
+ public WondexProtocolDecoder(ServerManager serverManager) {
super(serverManager);
}
/**
* Regular expressions pattern
*/
- //210000001,20070313170040,121.123456,12.654321,0,233,0,9,2,0.0, 0,0.00,0.00,0
- //YYYYMMDDhhmmss
static private Pattern pattern = Pattern.compile(
".*" + // Header
"(\\d+)," + // Device Identifier
@@ -48,12 +46,12 @@ public class Vt300ProtocolDecoder extends BaseProtocolDecoder {
"(\\d+)," + // Course
"(\\d+)," + // Altitude
"(\\d+)," + // Satellites
- "(\\d+)," + // Event
- "(\\d+\\.\\d+)," + // Milage
- "(\\d+)," + // Input
- "(\\d+\\.\\d+)," + // ADC1
- "(\\d+\\.\\d+)," + // ADC2
- "(\\d+)"); // Output
+ "(\\d+),?" + // Event
+ "(\\d+\\.\\d+)?,?" + // Milage
+ "(\\d+)?,?" + // Input
+ "(\\d+\\.\\d+)?,?" + // ADC1
+ "(\\d+\\.\\d+)?,?" + // ADC2
+ "(\\d+)?"); // Output
@Override
protected Object decode(
@@ -109,23 +107,32 @@ public class Vt300ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.append("</event>");
// Milage
- extendedInfo.append("<milage>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</milage>");
+ String milage = parser.group(index++);
+ if (milage != null) {
+ extendedInfo.append("<milage>").append(milage).append("</milage>");
+ }
// Input
- extendedInfo.append("<input>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</input>");
+ String input = parser.group(index++);
+ if (input != null) {
+ extendedInfo.append("<input>").append(input).append("</input>");
+ }
// ADC
- extendedInfo.append("<adc1>").append(parser.group(index++)).append("</adc1>");
- extendedInfo.append("<adc2>").append(parser.group(index++)).append("</adc2>");
+ String adc1 = parser.group(index++);
+ if (adc1 != null) {
+ extendedInfo.append("<adc1>").append(adc1).append("</adc1>");
+ }
+ String adc2 = parser.group(index++);
+ if (adc2 != null) {
+ extendedInfo.append("<adc2>").append(adc2).append("</adc2>");
+ }
// Output
- extendedInfo.append("<output>");
- extendedInfo.append(parser.group(index++));
- extendedInfo.append("</output>");
+ String output = parser.group(index++);
+ if (output != null) {
+ extendedInfo.append("<output>").append(output).append("</output>");
+ }
position.setExtendedInfo(extendedInfo.toString());
return position;
diff --git a/test/org/traccar/protocol/Vt300ProtocolDecoderTest.java b/test/org/traccar/protocol/WondexProtocolDecoderTest.java
index 5a1bf685f..e8e52c149 100644
--- a/test/org/traccar/protocol/Vt300ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WondexProtocolDecoderTest.java
@@ -3,17 +3,20 @@ package org.traccar.protocol;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-public class Vt300ProtocolDecoderTest {
+public class WondexProtocolDecoderTest {
@Test
public void testDecode() throws Exception {
- Vt300ProtocolDecoder decoder = new Vt300ProtocolDecoder(null);
+ WondexProtocolDecoder decoder = new WondexProtocolDecoder(null);
decoder.setDataManager(new TestDataManager());
assertNotNull(decoder.decode(null, null,
"210000001,20070313170040,121.123456,12.654321,0,233,0,9,2,0.0,0,0.00,0.00,0"));
+ assertNotNull(decoder.decode(null, null,
+ "1044989601,20130322172647,13.572583,52.401070,22,204,49,0,2"));
+
}
}