From ee4f40561f5cce1a9a07576662af69fadb9851ca Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Mar 2013 11:01:41 +1300 Subject: Add TK5000 support (fix #177) --- default.cfg | 6 +- src/org/traccar/ServerManager.java | 6 +- src/org/traccar/protocol/Vt300ProtocolDecoder.java | 134 -------------------- .../traccar/protocol/WondexProtocolDecoder.java | 141 +++++++++++++++++++++ .../traccar/protocol/Vt300ProtocolDecoderTest.java | 19 --- .../protocol/WondexProtocolDecoderTest.java | 22 ++++ 6 files changed, 169 insertions(+), 159 deletions(-) delete mode 100644 src/org/traccar/protocol/Vt300ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/WondexProtocolDecoder.java delete mode 100644 test/org/traccar/protocol/Vt300ProtocolDecoderTest.java create mode 100644 test/org/traccar/protocol/WondexProtocolDecoderTest.java diff --git a/default.cfg b/default.cfg index 4240bf429..749bdf4d2 100644 --- a/default.cfg +++ b/default.cfg @@ -189,9 +189,9 @@ true 5031 - - true - 5032 + + true + 5032 true 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/Vt300ProtocolDecoder.java deleted file mode 100644 index 9e2b2db13..000000000 --- a/src/org/traccar/protocol/Vt300ProtocolDecoder.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol; - -import java.util.Calendar; -import java.util.TimeZone; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.BaseProtocolDecoder; -import org.traccar.ServerManager; -import org.traccar.helper.Log; -import org.traccar.model.Position; - -public class Vt300ProtocolDecoder extends BaseProtocolDecoder { - - public Vt300ProtocolDecoder(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 - "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) - "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - "(-?\\d+\\.\\d+)," + // Longitude - "(-?\\d+\\.\\d+)," + // Latitude - "(\\d+)," + // Speed - "(\\d+)," + // Course - "(\\d+)," + // Altitude - "(\\d+)," + // Satellites - "(\\d+)," + // Event - "(\\d+\\.\\d+)," + // Milage - "(\\d+)," + // Input - "(\\d+\\.\\d+)," + // ADC1 - "(\\d+\\.\\d+)," + // ADC2 - "(\\d+)"); // Output - - @Override - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - // Parse message - Matcher parser = pattern.matcher((String) msg); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - StringBuilder extendedInfo = new StringBuilder("vt300"); - int index = 1; - - // Device identifier - String id = parser.group(index++); - try { - position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); - } catch(Exception error) { - Log.warning("Unknown device - " + id); - return null; - } - - // Time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - 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()); - - // Position data - position.setLongitude(Double.valueOf(parser.group(index++))); - position.setLatitude(Double.valueOf(parser.group(index++))); - position.setSpeed(Double.valueOf(parser.group(index++))); - position.setCourse(Double.valueOf(parser.group(index++))); - position.setAltitude(Double.valueOf(parser.group(index++))); - - // Satellites - int satellites = Integer.valueOf(parser.group(index++)); - position.setValid(satellites >= 3); - extendedInfo.append("").append(satellites).append(""); - - // Event - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); - - // Milage - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); - - // Input - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); - - // ADC - extendedInfo.append("").append(parser.group(index++)).append(""); - extendedInfo.append("").append(parser.group(index++)).append(""); - - // Output - extendedInfo.append(""); - extendedInfo.append(parser.group(index++)); - extendedInfo.append(""); - - position.setExtendedInfo(extendedInfo.toString()); - return position; - } - -} diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java new file mode 100644 index 000000000..5e3f3f390 --- /dev/null +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -0,0 +1,141 @@ +/* + * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; +import org.traccar.helper.Log; +import org.traccar.model.Position; + +public class WondexProtocolDecoder extends BaseProtocolDecoder { + + public WondexProtocolDecoder(ServerManager serverManager) { + super(serverManager); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + ".*" + // Header + "(\\d+)," + // Device Identifier + "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) + "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) + "(-?\\d+\\.\\d+)," + // Longitude + "(-?\\d+\\.\\d+)," + // Latitude + "(\\d+)," + // Speed + "(\\d+)," + // Course + "(\\d+)," + // Altitude + "(\\d+)," + // Satellites + "(\\d+),?" + // Event + "(\\d+\\.\\d+)?,?" + // Milage + "(\\d+)?,?" + // Input + "(\\d+\\.\\d+)?,?" + // ADC1 + "(\\d+\\.\\d+)?,?" + // ADC2 + "(\\d+)?"); // Output + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + // Parse message + Matcher parser = pattern.matcher((String) msg); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + StringBuilder extendedInfo = new StringBuilder("vt300"); + int index = 1; + + // Device identifier + String id = parser.group(index++); + try { + position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + id); + return null; + } + + // Time + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + 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()); + + // Position data + position.setLongitude(Double.valueOf(parser.group(index++))); + position.setLatitude(Double.valueOf(parser.group(index++))); + position.setSpeed(Double.valueOf(parser.group(index++))); + position.setCourse(Double.valueOf(parser.group(index++))); + position.setAltitude(Double.valueOf(parser.group(index++))); + + // Satellites + int satellites = Integer.valueOf(parser.group(index++)); + position.setValid(satellites >= 3); + extendedInfo.append("").append(satellites).append(""); + + // Event + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); + + // Milage + String milage = parser.group(index++); + if (milage != null) { + extendedInfo.append("").append(milage).append(""); + } + + // Input + String input = parser.group(index++); + if (input != null) { + extendedInfo.append("").append(input).append(""); + } + + // ADC + String adc1 = parser.group(index++); + if (adc1 != null) { + extendedInfo.append("").append(adc1).append(""); + } + String adc2 = parser.group(index++); + if (adc2 != null) { + extendedInfo.append("").append(adc2).append(""); + } + + // Output + String output = parser.group(index++); + if (output != null) { + extendedInfo.append("").append(output).append(""); + } + + position.setExtendedInfo(extendedInfo.toString()); + return position; + } + +} diff --git a/test/org/traccar/protocol/Vt300ProtocolDecoderTest.java b/test/org/traccar/protocol/Vt300ProtocolDecoderTest.java deleted file mode 100644 index 5a1bf685f..000000000 --- a/test/org/traccar/protocol/Vt300ProtocolDecoderTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.traccar.protocol; - -import static org.junit.Assert.assertNotNull; -import org.junit.Test; - -public class Vt300ProtocolDecoderTest { - - @Test - public void testDecode() throws Exception { - - Vt300ProtocolDecoder decoder = new Vt300ProtocolDecoder(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")); - - } - -} diff --git a/test/org/traccar/protocol/WondexProtocolDecoderTest.java b/test/org/traccar/protocol/WondexProtocolDecoderTest.java new file mode 100644 index 000000000..e8e52c149 --- /dev/null +++ b/test/org/traccar/protocol/WondexProtocolDecoderTest.java @@ -0,0 +1,22 @@ +package org.traccar.protocol; + +import static org.junit.Assert.assertNotNull; +import org.junit.Test; + +public class WondexProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + 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")); + + } + +} -- cgit v1.2.3