diff options
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/At2000Protocol.java | 7 | ||||
-rw-r--r-- | src/org/traccar/protocol/At2000ProtocolDecoder.java | 6 | ||||
-rw-r--r-- | src/org/traccar/protocol/CalAmpProtocolDecoder.java | 15 | ||||
-rw-r--r-- | src/org/traccar/protocol/GoSafeProtocolDecoder.java | 36 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/GranitProtocolDecoder.java | 25 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 21 | ||||
-rw-r--r-- | src/org/traccar/protocol/OigoProtocolDecoder.java | 98 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 7 | ||||
-rw-r--r-- | src/org/traccar/protocol/XexunProtocol.java | 9 | ||||
-rw-r--r-- | src/org/traccar/protocol/XexunProtocolEncoder.java | 42 |
11 files changed, 218 insertions, 50 deletions
diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java index 418619cb4..35aa0b469 100644 --- a/src/org/traccar/protocol/At2000Protocol.java +++ b/src/org/traccar/protocol/At2000Protocol.java @@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; import org.traccar.TrackerServer; +import java.nio.ByteOrder; import java.util.List; public class At2000Protocol extends BaseProtocol { @@ -30,13 +31,15 @@ public class At2000Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new At2000FrameDecoder()); pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this)); } - }); + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); } } diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index 17da0eef7..e9c26d406 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -50,11 +50,11 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { private static void sendResponse(Channel channel) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(BLOCK_LENGTH); + ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH); response.writeByte(MSG_ACKNOWLEDGEMENT); - response.writeMedium(1); + response.writeMedium(ChannelBuffers.swapMedium(1)); response.writeByte(0x00); // success - response.writerIndex(BLOCK_LENGTH); + response.writerIndex(2 * BLOCK_LENGTH); channel.write(response); } } diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index 510684411..ee4cc65b4 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -149,19 +149,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { int content = buf.readUnsignedByte(); if (BitUtil.check(content, 0)) { - - int length = buf.readUnsignedByte(); - long id = 0; - for (int i = 0; i < length; i++) { - int b = buf.readUnsignedByte(); - id = id * 10 + (b >> 4); - if ((b & 0xf) != 0xf) { - id = id * 10 + (b & 0xf); - } - } - - getDeviceSession(channel, remoteAddress, String.valueOf(id)); - + String id = ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())); + getDeviceSession(channel, remoteAddress, id); } if (BitUtil.check(content, 1)) { diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index a258e922c..a7f1024c6 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -90,13 +90,14 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .groupBegin() .text("DTT:") .number("(x+);") // status - .expression("[^;]*;") - .number("x+;") // geo-fence 0-119 - .number("x+;") // geo-fence 120-155 - .number("x+,?") // event status + .number("(x+)?;") // io + .number("(x+);") // geo-fence 0-119 + .number("(x+);") // geo-fence 120-155 + .number("(x+)") // event status + .number("(?:;(x+))?,?") // packet type .groupEnd("?") .groupBegin() - .text("ETD:").expression("[^,]*,?") + .text("ETD:").expression("([^,]+),?") .groupEnd("?") .groupBegin() .text("OBD:") @@ -108,6 +109,9 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .groupBegin() .text("TRU:").expression("[^,]*,?") .groupEnd("?") + .groupBegin() + .text("TAG:").expression("([^,]+),?") + .groupEnd("?") .compile(); private static final Pattern PATTERN_OLD = new PatternBuilder() @@ -122,7 +126,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .number("([EW])(d+.d+);") // longitude .number("(d+)?;") // speed .number("(d+);") // course - .number("(d+.?d*)").optional() // hdop + .number("(d+.?d*)").optional() // hdop .number("(dd)(dd)(dd)") // date .any() .compile(); @@ -162,16 +166,28 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, parser.next()); position.set(Position.KEY_BATTERY, parser.next()); - String status = parser.next(); - if (status != null) { - position.set(Position.KEY_IGNITION, BitUtil.check(Integer.parseInt(status, 16), 13)); + if (parser.hasNext(6)) { + long status = parser.nextLong(16); + position.set(Position.KEY_IGNITION, BitUtil.check(status, 13)); position.set(Position.KEY_STATUS, status); + position.set("ioStatus", parser.next()); + position.set(Position.KEY_GEOFENCE, parser.next() + parser.next()); + position.set("eventStatus", parser.next()); + position.set("packetType", parser.next()); + } + + if (parser.hasNext()) { + position.set("eventData", parser.next()); } if (parser.hasNext()) { position.set("obd", parser.next()); } + if (parser.hasNext()) { + position.set("tagData", parser.next()); + } + return position; } @@ -211,7 +227,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); - position.setSpeed(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); position.set(Position.KEY_HDOP, parser.next()); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 57dc784d3..d929ae917 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -119,6 +119,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_POWER_OFF; case "door alarm": return Position.ALARM_DOOR; + case "ac alarm": + return Position.ALARM_POWER_CUT; default: return null; } diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index 5fa786e4d..6e8bc24bf 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.java @@ -61,7 +61,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { private static void sendResponseCurrent(Channel channel, int deviceId, long time) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); response.writeBytes("BB+UGRC~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(6); //binary length + response.writeShort(6); // length response.writeInt((int) time); response.writeShort(deviceId); appendChecksum(response, 16); @@ -71,7 +71,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { private static void sendResponseArchive(Channel channel, int deviceId, int packNum) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); response.writeBytes("BB+ARCF~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(4); //binary length + response.writeShort(4); // length response.writeShort(packNum); response.writeShort(deviceId); appendChecksum(response, 14); @@ -95,14 +95,19 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { int latDegrees = buf.readUnsignedByte(); int lonMinutes = buf.readUnsignedShort(); int latMinutes = buf.readUnsignedShort(); + double latitude = latDegrees + latMinutes / 60000.0; double longitude = lonDegrees + lonMinutes / 60000.0; - if (!BitUtil.check(flags, 4)) { - latitude = -latitude; - } - if (!BitUtil.check(flags, 5)) { - longitude = -longitude; + + if (position.getValid()) { + if (!BitUtil.check(flags, 4)) { + latitude = -latitude; + } + if (!BitUtil.check(flags, 5)) { + longitude = -longitude; + } } + position.setLongitude(longitude); position.setLatitude(latitude); @@ -135,11 +140,11 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(buf.readUnsignedByte() * 10); - short diOut = buf.readUnsignedByte(); + int output = buf.readUnsignedByte(); for (int i = 0; i < 8; i++) { - position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(diOut, i)); + position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(output, i)); } - buf.skipBytes(1); //StatMess + buf.readUnsignedByte(); // status message buffer } @Override diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 45a978571..2c7852d16 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -75,7 +75,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); } } - position.set(Position.KEY_IGNITION, BitUtil.check(status, 10)); + position.set(Position.KEY_IGNITION, !BitUtil.check(status, 10)); position.set(Position.KEY_STATUS, status); } @@ -167,6 +167,12 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy) .any() .number("(x{8})") // status + .groupBegin() + .number(", *(x+),") // mcc + .number(" *(x+),") // mnc + .number(" *(x+),") // lac + .number(" *(x+)") // cid + .groupEnd("?") .any() .compile(); @@ -237,6 +243,19 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { processStatus(position, parser.nextLong(16)); + if (parser.hasNext(4)) { + int mcc = parser.nextInt(16); + int mnc = parser.nextInt(16); + int lac = parser.nextInt(16); + int cid = parser.nextInt(16); + if (mcc != 0 && mnc != 0 && lac != 0 && cid != 0) { + position.set(Position.KEY_MCC, mcc); + position.set(Position.KEY_MNC, mnc); + position.set(Position.KEY_LAC, lac); + position.set(Position.KEY_CID, cid); + } + } + return position; } diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java index 15a215c4f..9e6a9a82e 100644 --- a/src/org/traccar/protocol/OigoProtocolDecoder.java +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -34,15 +34,12 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - public static final int MSG_LOCATION = 0x00; - public static final int MSG_REMOTE_START = 0x10; - public static final int MSG_ACKNOWLEDGEMENT = 0xE0; + public static final int MSG_AR_LOCATION = 0x00; + public static final int MSG_AR_REMOTE_START = 0x10; - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + public static final int MSG_ACKNOWLEDGEMENT = 0xE0; - ChannelBuffer buf = (ChannelBuffer) msg; + private Position decodeArMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { buf.skipBytes(1); // header buf.readUnsignedShort(); // length @@ -67,7 +64,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { break; } - if (deviceSession == null || type != MSG_LOCATION) { + if (deviceSession == null || type != MSG_AR_LOCATION) { return null; } @@ -154,4 +151,89 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { return position; } + private double convertCoordinate(long value) { + boolean negative = value < 0; + value = Math.abs(value); + double minutes = (value % 100000) * 0.001; + value /= 100000; + double degrees = value + minutes / 60; + return negative ? -degrees : degrees; + } + + private Position decodeMgMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + + buf.readUnsignedByte(); // tag + int flags = buf.getUnsignedByte(buf.readerIndex()); + + DeviceSession deviceSession; + if (BitUtil.check(flags, 6)) { + buf.readUnsignedByte(); // flags + deviceSession = getDeviceSession(channel, remoteAddress); + } else { + String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + deviceSession = getDeviceSession(channel, remoteAddress, imei); + } + + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + buf.skipBytes(8); // imsi + + int date = buf.readUnsignedShort(); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(2010 + BitUtil.from(date, 12), BitUtil.between(date, 8, 12), BitUtil.to(date, 8)) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), 0); + + position.setValid(true); + position.setLatitude(convertCoordinate(buf.readInt())); + position.setLongitude(convertCoordinate(buf.readInt())); + + position.setAltitude(UnitsConverter.metersFromFeet(buf.readShort())); + position.setCourse(buf.readUnsignedShort()); + position.setSpeed(UnitsConverter.knotsFromMph(buf.readUnsignedByte())); + + position.set(Position.KEY_POWER, buf.readUnsignedByte() * 100 + "mV"); + position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); + + dateBuilder.setSecond(buf.readUnsignedByte()); + position.setTime(dateBuilder.getDate()); + + position.set(Position.KEY_GSM, buf.readUnsignedByte()); + + int index = buf.readUnsignedByte(); + + position.set(Position.KEY_VERSION, buf.readUnsignedByte()); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER, (long) (buf.readUnsignedInt() * 1609.34)); + + if (channel != null && BitUtil.check(flags, 7)) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(MSG_ACKNOWLEDGEMENT); + response.writeByte(index); + response.writeByte(0x00); + channel.write(response, remoteAddress); + } + + return position; + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + if (buf.getUnsignedByte(buf.readerIndex()) == 0x7e) { + return decodeArMessage(channel, remoteAddress, buf); + } else { + return decodeMgMessage(channel, remoteAddress, buf); + } + } + } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 2d3cb9101..f3d9e8380 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -29,6 +29,10 @@ import java.util.regex.Pattern; public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
+ private static final int MAX_CHUNK_SIZE = 960;
+
+ private byte[] photo;
+
public Pt502ProtocolDecoder(Pt502Protocol protocol) {
super(protocol);
}
@@ -92,7 +96,8 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { String type = parser.next();
if (type.startsWith("PHO") && channel != null) {
- channel.write("#PHD0," + type.substring(3) + "\r\n");
+ photo = new byte[Integer.parseInt(type.substring(3))];
+ channel.write("#PHD0," + Math.min(photo.length, MAX_CHUNK_SIZE) + "\r\n");
}
position.set(Position.KEY_ALARM, decodeAlarm(type));
diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java index 2aea2f246..a52d9ff45 100644 --- a/src/org/traccar/protocol/XexunProtocol.java +++ b/src/org/traccar/protocol/XexunProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.Context; import org.traccar.TrackerServer; +import org.traccar.model.Command; import java.util.List; @@ -30,6 +31,9 @@ public class XexunProtocol extends BaseProtocol { public XexunProtocol() { super("xexun"); + setSupportedCommands( + Command.TYPE_ENGINE_STOP, + Command.TYPE_ENGINE_RESUME); } @Override @@ -43,8 +47,9 @@ public class XexunProtocol extends BaseProtocol { } else { pipeline.addLast("frameDecoder", new XexunFrameDecoder()); } - pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectEncoder", new XexunProtocolEncoder()); pipeline.addLast("objectDecoder", new XexunProtocolDecoder(XexunProtocol.this, full)); } }); diff --git a/src/org/traccar/protocol/XexunProtocolEncoder.java b/src/org/traccar/protocol/XexunProtocolEncoder.java new file mode 100644 index 000000000..cdf3ac6f7 --- /dev/null +++ b/src/org/traccar/protocol/XexunProtocolEncoder.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * + * 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 org.traccar.StringProtocolEncoder; +import org.traccar.helper.Log; +import org.traccar.model.Command; + +public class XexunProtocolEncoder extends StringProtocolEncoder { + + @Override + protected Object encodeCommand(Command command) { + + initDevicePassword(command, "123456"); + + switch (command.getType()) { + case Command.TYPE_ENGINE_STOP: + return formatCommand(command, "powercar{%s} 11", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_ENGINE_RESUME: + return formatCommand(command, "powercar{%s} 00", Command.KEY_DEVICE_PASSWORD); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; + } + + return null; + } + +} |