aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-08-06 22:18:45 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-08-06 22:18:45 +1200
commitc10858c1ae7f4dca0c9ae88e19bb069b91ad0792 (patch)
tree1334c6cd825a4622055bb14d8fbf8f67018b4799
parent5060907d594f54287e9cbd402c1d8804151fcede (diff)
downloadtrackermap-server-c10858c1ae7f4dca0c9ae88e19bb069b91ad0792.tar.gz
trackermap-server-c10858c1ae7f4dca0c9ae88e19bb069b91ad0792.tar.bz2
trackermap-server-c10858c1ae7f4dca0c9ae88e19bb069b91ad0792.zip
Added Ruptela protocol
-rw-r--r--default.cfg4
-rw-r--r--src/org/traccar/ServerManager.java13
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java133
-rw-r--r--test/org/traccar/protocol/RuptelaProtocolDecoderTest.java36
4 files changed, 186 insertions, 0 deletions
diff --git a/default.cfg b/default.cfg
index 70abf19dc..3bbcf2445 100644
--- a/default.cfg
+++ b/default.cfg
@@ -246,4 +246,8 @@
<entry key='pt3000.enable'>true</entry>
<entry key='pt3000.port'>5045</entry>
+ <!-- Ruptela server configuration -->
+ <entry key='ruptela.enable'>true</entry>
+ <entry key='ruptela.port'>5046</entry>
+
</properties>
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 4432ad07c..84933b093 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -141,6 +141,7 @@ public class ServerManager {
initGlobalSatServer("globalsat");
initAtrackServer("atrack");
initPt3000Server("pt3000");
+ initRuptelaServer("ruptela");
// Initialize web server
if (Boolean.valueOf(properties.getProperty("http.enable"))) {
@@ -857,4 +858,16 @@ public class ServerManager {
}
}
+ private void initRuptelaServer(String protocol) throws SQLException {
+ if (isProtocolEnabled(properties, protocol)) {
+ serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, 2, 0));
+ pipeline.addLast("objectDecoder", new RuptelaProtocolDecoder(ServerManager.this));
+ }
+ });
+ }
+ }
+
}
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
new file mode 100644
index 000000000..32bf76425
--- /dev/null
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -0,0 +1,133 @@
+/*
+ * 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.Date;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+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.ExtendedInfoFormatter;
+import org.traccar.model.Position;
+
+public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
+
+ public RuptelaProtocolDecoder(ServerManager serverManager) {
+ super(serverManager);
+ }
+
+ private static final int COMMAND_RECORDS = 0x01;
+
+ @Override
+ protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
+ throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.readUnsignedShort(); // data length
+
+ // Identify device
+ String imei = String.valueOf(buf.readLong());
+ long deviceId;
+ try {
+ deviceId = getDataManager().getDeviceByImei(imei).getId();
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + imei);
+ return null;
+ }
+
+ int type = buf.readUnsignedByte();
+
+ if (type == COMMAND_RECORDS) {
+ List<Position> positions = new LinkedList<Position>();
+
+ buf.readUnsignedByte(); // records left
+ int count = buf.readUnsignedByte();
+
+ for (int i = 0; i < count; i++) {
+ Position position = new Position();
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("ruptela");
+ position.setDeviceId(deviceId);
+
+ // Time
+ position.setTime(new Date(buf.readUnsignedInt() * 1000));
+ buf.readUnsignedByte(); // timestamp extension
+
+ buf.readUnsignedByte(); // priority (reserved)
+
+ // Location
+ position.setLongitude(buf.readInt() / 10000000.0);
+ position.setLatitude(buf.readInt() / 10000000.0);
+ position.setAltitude(buf.readUnsignedShort() / 10.0);
+ position.setCourse(buf.readUnsignedShort() / 100.0);
+
+ // Validity
+ int satellites = buf.readUnsignedByte();
+ extendedInfo.set("satellites", satellites);
+ position.setValid(satellites >= 3);
+
+ position.setSpeed(buf.readUnsignedShort() * 0.539957);
+
+ extendedInfo.set("hdop", buf.readUnsignedByte() / 10.0);
+
+ buf.readUnsignedByte();
+
+ // Read 1 byte data
+ int cnt = buf.readUnsignedByte();
+ for (int j = 0; j < cnt; j++) {
+ extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedByte());
+ }
+
+ // Read 2 byte data
+ cnt = buf.readUnsignedByte();
+ for (int j = 0; j < cnt; j++) {
+ extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedShort());
+ }
+
+ // Read 4 byte data
+ cnt = buf.readUnsignedByte();
+ for (int j = 0; j < cnt; j++) {
+ extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedInt());
+ }
+
+ // Read 8 byte data
+ cnt = buf.readUnsignedByte();
+ for (int j = 0; j < cnt; j++) {
+ extendedInfo.set("io" + buf.readUnsignedByte(), buf.readLong());
+ }
+
+ position.setExtendedInfo(extendedInfo.toString());
+ positions.add(position);
+ }
+
+ // Acknowledgement
+ if (channel != null) {
+ byte[] response = {0x00, 0x02, 0x64, 0x01, 0x13, (byte)0xbc};
+ channel.write(ChannelBuffers.wrappedBuffer(response));
+ }
+
+ return positions;
+ }
+
+ return null;
+ }
+
+}
diff --git a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java
new file mode 100644
index 000000000..165f417b4
--- /dev/null
+++ b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java
@@ -0,0 +1,36 @@
+package org.traccar.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffers;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+
+public class RuptelaProtocolDecoderTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(null);
+ decoder.setDataManager(new TestDataManager());
+
+ byte[] buf1 = {0x00,0x79,0x00,0x00,0x0b,0x1a,0x2a,0x55,(byte)0x85,(byte)0xc3,0x01,0x00,0x02,0x4e,(byte)0x9c,0x03,0x69,0x00,0x00,0x0f,0x10,0x17,0x33,0x20,(byte)0x8f,(byte)0xf4,0x5e,0x07,(byte)0xb3,0x1b,0x57,0x0a,0x00,0x10,0x09,0x09,0x06,0x05,0x01,0x1b,0x1a,0x02,0x00,0x03,0x00,0x1c,0x01,(byte)0xad,0x01,0x02,0x1d,0x33,(byte)0x8e,0x16,0x00,0x00,0x02,(byte)0x96,0x00,0x00,0x60,0x1a,0x41,0x01,0x4b,(byte)0xc1,0x6d,0x00,0x4e,(byte)0x9c,0x03,(byte)0x84,0x00,0x00,0x0f,0x10,0x4f,(byte)0xdf,0x20,(byte)0x90,0x0d,0x20,0x07,0x51,0x03,(byte)0xb0,0x0a,0x00,0x13 ,0x08,0x09,0x06,0x05,0x01,0x1b,0x1a,0x02,0x00,0x03,0x00,0x1c,0x01,(byte)0xad,0x01,0x02,0x1d,0x33,(byte)0xb1,0x16,0x00,0x00,0x02,(byte)0x96,0x00,0x00,0x60,0x1a,0x41,0x01,0x4b,(byte)0xc1,(byte)0xea,0x00,0x28,(byte)0xf9};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1)));
+
+ /*byte[] buf2 = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xA7,0x08,0x04,0x00,0x00,0x01,0x13,(byte)0xfc,0x20,(byte)0x8d,(byte)0xff,0x00,0x0f,0x14,(byte)0xf6,0x50,0x20,(byte)0x9c,(byte)0xca,(byte)0x80,0x00,0x6f,0x00,(byte)0xd6,0x04,0x00,0x04,0x00,0x04,0x03,0x01,0x01,0x15,0x03,0x16,0x03,0x00,0x01,0x46,0x00,0x00,0x01,0x5d,0x00,0x00,0x00,0x01,0x13,(byte)0xfc,0x17,0x61,0x0b,0x00,0x0f,0x14,(byte)0xff,(byte)0xe0,0x20,(byte)0x9c,(byte)0xc5,(byte)0x80,0x00,0x6e,0x00,(byte)0xc0,0x05,0x00,0x01,0x00,0x04,0x03,0x01,0x01,0x15,0x03,0x16,0x01,0x00,0x01,0x46,0x00,0x00,0x01,0x5e,0x00,0x00,0x00,0x01,0x13,(byte)0xfc,0x28,0x49,0x45,0x00,0x0f,0x15,0x0f,0x00,0x20,(byte)0x9c,(byte)0xd2,0x00,0x00,(byte)0x95,0x01,0x08,0x04,0x00,0x00,0x00,0x04,0x03,0x01,0x01,0x15,0x00,0x16,0x03,0x00,0x01,0x46,0x00,0x00,0x01,0x5d,0x00,0x00,0x00,0x01,0x13,(byte)0xfc,0x26,0x7c,0x5b,0x00,0x0f,0x15,0x0a,0x50,0x20,(byte)0x9c,(byte)0xcc,(byte)0xc0,0x00,(byte)0x93,0x00,0x68,0x04,0x00,0x00,0x00,0x04,0x03,0x01,0x01,0x15,0x00,0x16,0x03,0x00,0x01,0x46,0x00,0x00,0x01,0x5b,0x00,0x04,0x00,0x00};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2)));
+
+ byte[] buf3 = {0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x47,0x08,0x06,0x00,0x00,0x01,0x3e,0x5a,0x60,(byte)0xa4,(byte)0xcb,0x00,0x3f,(byte)0xa7,(byte)0xb7,(byte)0x80,(byte)0xfc,0x42,0x45,0x18,0x00,0x42,0x00,0x00,0x0a,0x00,0x00,0x00,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x00,0x03,0x42,0x68,(byte)0xa7,0x46,0x01,0x18,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3e,0x5d,(byte)0xc8,(byte)0xba,0x28,0x00,0x3f,(byte)0xa7,(byte)0xc0,(byte)0x80,(byte)0xfc,0x42,0x46,0x04,0x00,0x01,0x00,0x00,0x05,0x00,0x00,0x00,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x01,0x03,0x42,0x68,(byte)0xb4,0x46,0x00,(byte)0xef,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3e,0x5d,(byte)0xc9,0x04,0x55,0x00,0x3f,(byte)0xa7,(byte)0xb6,0x40,(byte)0xfc,0x42,0x43,(byte)0x88,0x00,0x3a,0x00,0x00,0x07,0x00,0x00,(byte)0xf0,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x00,0x03,0x42,0x68,(byte)0xdc,0x46,0x00,(byte)0xf7,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x1d,0x00,0x00,0x00,0x01,0x3e,0x5d,(byte)0xc9,(byte)0xd3,0x68,0x00,0x3f,(byte)0xa7,(byte)0xb8,0x00,(byte)0xfc,0x42,0x44,0x30,0x00,0x49,0x00,0x00,0x04,0x00,0x00,0x00,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x01,0x03,0x42,0x67,(byte)0xde,0x46,0x01,0x07,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3e,0x5d,(byte)0xca,0x31,0x1d,0x00,0x3f,(byte)0xa7,(byte)0xb6,(byte)0x80,(byte)0xfc,0x42,0x43,(byte)0xcc,0x00,0x42,0x00,0x00,0x07,0x00,0x00,(byte)0xf0,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x00,0x03,0x42,0x68,0x53,0x46,0x01,0x0b,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3e,0x5d,(byte)0xcf,(byte)0xaf,(byte)0xe9,0x00,0x3f,(byte)0xa7,(byte)0xb6,0x00,(byte)0xfc,0x42,0x42,(byte)0xf0,0x00,0x3d,0x00,0x00,0x08,0x00,0x00,0x00,0x09,0x05,0x01,0x01,0x02,0x00,(byte)0xb3,0x00,(byte)0xb4,0x00,(byte)0xf0,0x00,0x03,0x42,0x68,0x52,0x46,0x01,0x19,0x18,0x00,0x00,0x01,(byte)0xc7,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x02,0x75};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf3)));
+
+ byte[] buf4 = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2c,0x08,0x01,0x00,0x00,0x01,0x3e,(byte)0xff,(byte)0x8d,0x6f,(byte)0x98,0x00,0x17,0x32,(byte)0x95,0x00,0x21,0x11,(byte)0xf4,0x00,0x00,(byte)0x81,0x00,(byte)0xae,0x0b,0x00,0x00,0x00,0x04,0x01,0x01,0x00,0x03,0x09,0x00,0x16,0x43,0x29,(byte)0x80,0x42,0x2f,0x72,0x00,0x00,0x01,0x00,0x00,0x7a,0x5d};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf4)));
+
+ byte[] buf5 = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xc7,0x07,0x04,0x41,(byte)0xbf,(byte)0x9d,(byte)0xb0,0x0f,(byte)0xff,0x42,0x5a,(byte)0xdb,(byte)0xd7,0x41,(byte)0xca,0x6e,0x1e,0x00,(byte)0x9e,0x12,0x05,0x07,0x00,0x01,0x03,0x0b,0x16,0x00,0x00,0x60,0x1a,0x02,0x01,0x5e,0x02,0x00,0x03,0x14,0x00,0x66,0x15,0x00,0x0a,0x16,0x00,0x67,0x01,0x05,0x00,0x00,0x0c,(byte)0xe4,0x41,(byte)0xbf,(byte)0x9d,(byte)0x92,0x0f,(byte)0xff,0x42,0x5a,(byte)0xdb,(byte)0xb1,0x41,(byte)0xca,0x6f,(byte)0xc9,0x00,(byte)0xa2,(byte)0xb2,0x18,0x07,0x00,0x01,0x03,0x0b,0x16,0x00,0x00,0x60,0x1a,0x02,0x01,0x5e,0x02,0x00,0x03,0x14,0x00,0x66,0x15,0x00,0x0a,0x16,0x00,0x67,0x01,0x05,0x00,0x00,0x0c,(byte)0xc6,0x41,(byte)0xbf,(byte)0x9d,0x74,0x0f,(byte)0xff,0x42,0x5a,(byte)0xdb,(byte)0xee,0x41,(byte)0xca,0x73,(byte)0x92,0x00,(byte)0xb6,(byte)0xc9,0x1e,0x07,0x00,0x01,0x03,0x0b,0x1f,0x00,0x00,0x60,0x1a,0x02,0x01,0x5f,0x02,0x00,0x03,0x14,0x00,0x66,0x15,0x00,0x0a,0x16,0x00,0x66,0x01,0x05,0x00,0x00,0x0c,(byte)0xa8,0x41,(byte)0xbf,(byte)0x9c,(byte)0xfc,0x0f,(byte)0xff,0x42,0x5a,(byte)0xdb,(byte)0xa0,0x41,(byte)0xca,0x70,(byte)0xc1,0x00,(byte)0xb9,0x38,0x13,0x07,0x00,0x01,0x03,0x0b,0x1f,0x00,0x00,0x60,0x1a,0x02,0x01,0x5f,0x02,0x00,0x03,0x14,0x00,0x23,0x15,0x00,0x0a,0x16,0x00,0x25,0x01,0x05,0x00,0x00,0x0c,0x30,0x04,0x00,0x00,0x00};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf5)));
+
+ byte[] buf6 = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x07,0x02,0x4c,0x61,0x41,0x0b,0x01,0x3f,0x42,0x31,(byte)0xc2,(byte)0xc1,0x41,(byte)0xd0,(byte)0xbe,(byte)0xb9,0x00,0x3d,0x00,0x00,0x05,0x00,0x64,(byte)0x83,(byte)0xff,0x4c,0x61,0x40,(byte)0xeb,0x01,0x3f,0x42,0x31,(byte)0xc2,(byte)0xc1,0x41,(byte)0xd0,(byte)0xbe,(byte)0xb9,0x00,0x3d,0x00,0x00,0x05,0x00,0x64,(byte)0x83,(byte)0xff,0x02,0x00,0x00,0x41,(byte)0xdf};
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf6)));*/
+
+ }
+
+}