diff options
author | jon-stumpf <jon.stumpf@gmail.com> | 2017-02-20 10:54:34 -0500 |
---|---|---|
committer | jon-stumpf <jon.stumpf@gmail.com> | 2017-02-20 10:54:34 -0500 |
commit | 888c392af40187f3a0ecc3395495db9acd85b827 (patch) | |
tree | beb74dff8b8052ffb4a7d3c894b2b4e5a4434973 /src/org/traccar/protocol | |
parent | 38249673287b908c0ca55847a35ca16a7b6a0c50 (diff) | |
parent | 2449895139fa658d082c1085185003a001225bc3 (diff) | |
download | trackermap-server-888c392af40187f3a0ecc3395495db9acd85b827.tar.gz trackermap-server-888c392af40187f3a0ecc3395495db9acd85b827.tar.bz2 trackermap-server-888c392af40187f3a0ecc3395495db9acd85b827.zip |
Resolved conflict with master;
Diffstat (limited to 'src/org/traccar/protocol')
11 files changed, 194 insertions, 36 deletions
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index dc799054d..182066629 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -102,6 +102,10 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { return null; } + if (buf.capacity() <= BLOCK_LENGTH) { + return null; // empty message + } + byte[] data = new byte[buf.capacity() - BLOCK_LENGTH]; buf.readBytes(data); buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data)); diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java index bfaf03692..7c8510204 100644 --- a/src/org/traccar/protocol/CellocatorProtocol.java +++ b/src/org/traccar/protocol/CellocatorProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 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. @@ -20,6 +20,7 @@ import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; import org.traccar.TrackerServer; +import org.traccar.model.Command; import java.nio.ByteOrder; import java.util.List; @@ -28,6 +29,8 @@ public class CellocatorProtocol extends BaseProtocol { public CellocatorProtocol() { super("cellocator"); + setSupportedCommands( + Command.TYPE_OUTPUT_CONTROL); } @Override @@ -36,6 +39,7 @@ public class CellocatorProtocol extends BaseProtocol { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CellocatorFrameDecoder()); + pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder()); pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); } }; @@ -45,6 +49,7 @@ public class CellocatorProtocol extends BaseProtocol { server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder()); pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); } }; diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index 14325e619..7df8cad8a 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2017 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. @@ -68,6 +68,19 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(short reason) { + switch (reason) { + case 70: + return Position.ALARM_SOS; + case 80: + return Position.ALARM_POWER_CUT; + case 81: + return Position.ALARM_LOW_POWER; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -106,7 +119,8 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { operator += buf.readUnsignedByte(); buf.readUnsignedByte(); // reason data - buf.readUnsignedByte(); // reason + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); + buf.readUnsignedByte(); // mode buf.readUnsignedInt(); // IO diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java new file mode 100644 index 000000000..bb143d349 --- /dev/null +++ b/src/org/traccar/protocol/CellocatorProtocolEncoder.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017 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.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.traccar.BaseProtocolEncoder; +import org.traccar.helper.Log; +import org.traccar.model.Command; + +import java.nio.ByteOrder; + +public class CellocatorProtocolEncoder extends BaseProtocolEncoder { + + private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) { + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + buf.writeByte('M'); + buf.writeByte('C'); + buf.writeByte('G'); + buf.writeByte('P'); + buf.writeByte(0); + buf.writeInt(Integer.parseInt(getUniqueId(deviceId))); + buf.writeByte(0); // command numerator + buf.writeInt(0); // authentication code + buf.writeByte(command); + buf.writeByte(command); + buf.writeByte(data1); + buf.writeByte(data1); + buf.writeByte(data2); + buf.writeByte(data2); + buf.writeInt(0); // command specific data + + byte checksum = 0; + for (int i = 4; i < buf.writerIndex(); i++) { + checksum += buf.getByte(i); + } + buf.writeByte(checksum); + + return buf; + } + + @Override + protected Object encodeCommand(Command command) { + + switch (command.getType()) { + case Command.TYPE_OUTPUT_CONTROL: + int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4 + + command.getInteger(Command.KEY_INDEX); + return encodeContent(command.getDeviceId(), 0x03, data, 0); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; + } + + return null; + } + +} diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index 68063c5c3..c9aae8e96 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -55,6 +55,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private static final int TAG_ADC1 = 0x51; private static final int TAG_ADC2 = 0x52; private static final int TAG_ADC3 = 0x53; + private static final int TAG_ARRAY = 0xea; private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>(); @@ -81,7 +82,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { 0x20, 0x33, 0x44, 0x90, 0xc0, 0xc2, 0xc3, 0xd3, 0xd4, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xf0, 0xf9, 0x5a, 0x47, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, - 0xf7, 0xf8 + 0xf7, 0xf8, 0xe2, 0xe9 }; for (int i : l1) { TAG_LENGTH_MAP.put(i, 1); @@ -102,7 +103,11 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } private static int getTagLength(int tag) { - return TAG_LENGTH_MAP.get(tag); + Integer length = TAG_LENGTH_MAP.get(tag); + if (length == null) { + throw new IllegalArgumentException("Unknown tag: " + tag); + } + return length; } private void sendReply(Channel channel, int checksum) { @@ -207,6 +212,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort()); break; + case TAG_ARRAY: + buf.skipBytes(buf.readUnsignedByte()); + break; + default: buf.skipBytes(getTagLength(tag)); break; diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 59f013313..ef434b779 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -107,7 +107,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_LOCATION = new PatternBuilder() - .number("(?:d{1,2})?,") // gps accuracy + .number("(d{1,2})?,") // hdop .number("(d{1,3}.d)?,") // speed .number("(d{1,3})?,") // course .number("(-?d{1,5}.d)?,") // altitude @@ -275,6 +275,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version .number("(d{15}|x{14}),") // imei .any() + .number("(d{1,2})?,") // hdop .number("(d{1,3}.d)?,") // speed .number("(d{1,3})?,") // course .number("(-?d{1,5}.d)?,") // altitude @@ -399,6 +400,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } private void decodeLocation(Position position, Parser parser) { + int hdop = parser.nextInt(); + position.setValid(hdop > 0); + position.set(Position.KEY_HDOP, hdop); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); position.setAltitude(parser.nextDouble()); @@ -451,11 +456,11 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set("dtcsCodes", parser.next()); position.set(Position.KEY_THROTTLE, parser.next()); position.set(Position.KEY_FUEL, parser.next()); - position.set(Position.KEY_OBD_ODOMETER, parser.next()); + position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000); decodeLocation(position, parser); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { DateBuilder dateBuilder = new DateBuilder() @@ -510,7 +515,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); position.set(Position.KEY_BATTERY, parser.next()); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); position.set(Position.KEY_HOURS, parser.next()); position.set(Position.PREFIX_ADC + 1, parser.next()); position.set(Position.PREFIX_ADC + 2, parser.next()); @@ -666,7 +671,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); position.set(Position.KEY_BATTERY, parser.next()); position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); @@ -703,12 +708,15 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + int hdop = parser.nextInt(); + position.setValid(hdop > 0); + position.set(Position.KEY_HDOP, hdop); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); position.setAltitude(parser.nextDouble()); if (parser.hasNext(2)) { - position.setValid(true); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); } else { diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index f1d305ab6..391fccc87 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -50,7 +50,12 @@ public class H02FrameDecoder extends FrameDecoder { // Return text message int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#'); if (index != -1) { - return buf.readBytes(index + 1 - buf.readerIndex()); + ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex()); + while (buf.readable() + && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) { + buf.readByte(); // skip new line + } + return result; } break; @@ -81,7 +86,7 @@ public class H02FrameDecoder extends FrameDecoder { default: - throw new IllegalArgumentException(); + return null; } return null; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 37f6294be..a717ddc4d 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); } @@ -165,16 +165,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),") .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course - .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("?") + .number("(?:(dd)(dd)(dd))?") // date (ddmmyy) .any() + .number(",(x{8})") // status + .expression("(?:#|,.*)") .compile(); private static final Pattern PATTERN_NBR = new PatternBuilder() diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 7927c28e6..c53538223 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2017 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. @@ -48,7 +48,8 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .groupEnd("?") .number("(d{5})") // seconds .or() - .text("RGP") // type + .expression("(?:RGP|RCQ|RBR)") // type + .number("(?:dd)?") .number("(dd)(dd)(dd)") // date .number("(dd)(dd)(dd)") // time .groupEnd() @@ -56,6 +57,13 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .number("([-+]ddd)(d{5})") // longitude .number("(ddd)") // speed .number("(ddd)") // course + .groupBegin() + .number("(xx)") // input + .number("(xx)") // satellites + .number("(ddd)") // battery + .number("(x{8})") // odometer + .number("[01]") // gps power + .groupEnd("?") .number("(d)") // fix mode .any() .compile(); @@ -93,15 +101,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - String week = parser.next(); - String day = parser.next(); - String seconds = parser.next(); - if (seconds != null) { - if (week != null && day != null) { - position.setTime(getTime(Integer.parseInt(week), Integer.parseInt(day), Integer.parseInt(seconds))); - } else { - position.setTime(getTime(Integer.parseInt(seconds))); - } + if (parser.hasNext(2)) { + position.setTime(getTime(parser.nextInt(), parser.nextInt(), parser.nextInt())); + } else if (parser.hasNext()) { + position.setTime(getTime(parser.nextInt())); } if (parser.hasNext(6)) { @@ -115,6 +118,14 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble())); position.setCourse(parser.nextDouble()); + + if (parser.hasNext(4)) { + position.set(Position.KEY_INPUT, parser.nextInt(16)); + position.set(Position.KEY_SATELLITES, parser.nextInt(16)); + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_ODOMETER, parser.nextLong(16)); + } + position.setValid(parser.nextInt() != 0); String[] attributes = null; diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index e647a33a0..9c1e0a2ff 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -73,6 +73,12 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) { switch (id) { + case 1: + case 2: + case 3: + case 4: + position.set("di" + id, buf.readUnsignedByte()); + break; case 9: position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); break; @@ -82,6 +88,9 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { case 67: position.set(Position.KEY_BATTERY, buf.readUnsignedShort() + "mV"); break; + case 70: + position.set("pcbTemp", (length == 4 ? buf.readInt() : buf.readShort()) * 0.1); + break; case 72: position.set(Position.PREFIX_TEMP + 1, buf.readInt() * 0.1); break; diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java index 9fa8759a0..3b73a1516 100644 --- a/src/org/traccar/protocol/TmgProtocolDecoder.java +++ b/src/org/traccar/protocol/TmgProtocolDecoder.java @@ -35,7 +35,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$") - .expression("...,") // type + .expression("(...),") // type .expression("[LH],") // history .number("(d+),") // imei .number("(dd)(dd)(dddd),") // date @@ -53,7 +53,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // visible satellites .number("([^,]*),") // operator .number("(d+),") // rssi - .number("x+,") // cid + .number("[^,]*,") // cid .expression("([01]),") // ignition .number("(d+.?d*),") // battery .number("(d+.?d*),") // power @@ -72,6 +72,8 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { return null; } + String type = parser.next(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; @@ -81,6 +83,31 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + switch (type) { + case "rmv": + position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT); + break; + case "ebl": + position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER); + break; + case "ibl": + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + break; + case "tmp": + case "smt": + case "btt": + position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING); + break; + case "ion": + position.set(Position.KEY_IGNITION, true); + break; + case "iof": + position.set(Position.KEY_IGNITION, false); + break; + default: + break; + } + DateBuilder dateBuilder = new DateBuilder() .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); |