diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-08 16:05:21 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-08 16:05:21 +1200 |
commit | 58c407feec28c66062b21d7a93fb8b491a255ca4 (patch) | |
tree | 815fa2bb82221e96c8d9716e51988dc01bf414bd /src/org/traccar | |
parent | 49ef740b5a2a0ed40c59225a3ccf2b8fbc12139e (diff) | |
download | traccar-server-58c407feec28c66062b21d7a93fb8b491a255ca4.tar.gz traccar-server-58c407feec28c66062b21d7a93fb8b491a255ca4.tar.bz2 traccar-server-58c407feec28c66062b21d7a93fb8b491a255ca4.zip |
Support Castel multiple GPS items
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/CastelProtocolDecoder.java | 81 |
1 files changed, 46 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; |