aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-08 16:05:21 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-08 16:05:21 +1200
commit58c407feec28c66062b21d7a93fb8b491a255ca4 (patch)
tree815fa2bb82221e96c8d9716e51988dc01bf414bd
parent49ef740b5a2a0ed40c59225a3ccf2b8fbc12139e (diff)
downloadtrackermap-server-58c407feec28c66062b21d7a93fb8b491a255ca4.tar.gz
trackermap-server-58c407feec28c66062b21d7a93fb8b491a255ca4.tar.bz2
trackermap-server-58c407feec28c66062b21d7a93fb8b491a255ca4.zip
Support Castel multiple GPS items
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java81
-rw-r--r--test/org/traccar/protocol/CastelProtocolDecoderTest.java18
2 files changed, 64 insertions, 35 deletions
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index ea4c9dd5b..453e58128 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -18,9 +18,8 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
+import java.util.*;
+
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
@@ -72,11 +71,10 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_LOGIN || type == MSG_GPS) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
if (!identify(id.toString(Charset.defaultCharset()).trim(), channel, remoteAddress)) {
+
return null;
+
} else if (type == MSG_LOGIN) {
if (channel != null) {
@@ -96,46 +94,59 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
- position.setDeviceId(getDeviceId());
-
if (type == MSG_GPS) {
buf.readUnsignedByte(); // historical
}
buf.readUnsignedInt(); // ACC ON time
buf.readUnsignedInt(); // UTC time
- position.set(Event.KEY_ODOMETER, buf.readUnsignedInt());
+ long odometer = buf.readUnsignedInt();
buf.readUnsignedInt(); // trip odometer
buf.readUnsignedInt(); // total fuel consumption
buf.readUnsignedShort(); // current fuel consumption
- position.set(Event.KEY_STATUS, buf.readUnsignedInt());
+ long status = buf.readUnsignedInt();
buf.skipBytes(8);
- buf.readUnsignedByte(); // count
-
- // Date and time
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
- time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
- time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
- time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
- time.set(Calendar.MINUTE, buf.readUnsignedByte());
- time.set(Calendar.SECOND, buf.readUnsignedByte());
- position.setTime(time.getTime());
-
- double lat = buf.readUnsignedInt() / 3600000.0;
- double lon = buf.readUnsignedInt() / 3600000.0;
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort() % 360);
-
- int flags = buf.readUnsignedByte();
- position.setLatitude((flags & 0x02) == 0 ? -lat : lat);
- position.setLongitude((flags & 0x01) == 0 ? -lon : lon);
- position.setValid((flags & 0x0C) > 0);
- position.set(Event.KEY_SATELLITES, flags >> 4);
-
- return position;
+ int count = buf.readUnsignedByte();
+
+ List<Position> positions = new LinkedList<Position>();
+
+ for (int i = 0; i < count; i++) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+ position.set(Event.KEY_ODOMETER, odometer);
+ position.set(Event.KEY_STATUS, status);
+
+ // Date and time
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ time.clear();
+ time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
+ time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
+ time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
+ time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
+ time.set(Calendar.MINUTE, buf.readUnsignedByte());
+ time.set(Calendar.SECOND, buf.readUnsignedByte());
+ position.setTime(time.getTime());
+
+ double lat = buf.readUnsignedInt() / 3600000.0;
+ double lon = buf.readUnsignedInt() / 3600000.0;
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
+ position.setCourse(buf.readUnsignedShort() % 360);
+
+ int flags = buf.readUnsignedByte();
+ position.setLatitude((flags & 0x02) == 0 ? -lat : lat);
+ position.setLongitude((flags & 0x01) == 0 ? -lon : lon);
+ position.setValid((flags & 0x0C) > 0);
+ position.set(Event.KEY_SATELLITES, flags >> 4);
+
+ positions.add(position);
+ }
+
+ if (!positions.isEmpty()) {
+ return positions;
+ }
}
return null;
diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
index e814beb74..a28078ef4 100644
--- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
@@ -15,6 +15,24 @@ public class CastelProtocolDecoderTest extends ProtocolDecoderTest {
CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol());
assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "4040450004323132474c31313433303035303033000000000040082ca89b55a6a99b555c57000000000000c40200000b0000001400036401111f000302f5533bd653f10d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "40404d0004323132474c3131343330303530303300000000004007120000002ca89b55cba99b555c57000000000000c40200000b0000000000036401111f000102000101170000000068850d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "4040420004323132474c31313433303035303033000000000010022ca89b55cca99b555c57000000000000cf0200000b0000000000036401111f0000020013be0d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "4040870004323132474c31313433303035303033000000000040052ca89b55e3a89b555c57000000000000c4020000040000001400036401111f0003000012042105210b210c210d210f211021112113211c2121212321242133213421422146214f212b50663603003ce9030dff060000600dffffc25865ffff9e02b43624000000003cbc0d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "4040d00004323132474c31313433303035303033000000000010013ec09b5596c29b555c57000000000000de0200000f0000000000036401111f000000004944445f3231334730325f532056322e322e36004944445f3231334730325f482056322e322e360032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f012102210126012701288a690d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
+ "40404d0004323132474c3131343330303530303300000000004007050000003ec09b5564c29b555c57000000000000de0200000f0000002000036401111f0000020001010e00000000237e0d0a"))));
+
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
"40401F00043130303131313235323939383700000000000000100303320D0A"))));
verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(