diff options
Diffstat (limited to 'src/main')
5 files changed, 50 insertions, 28 deletions
diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java index 47e5aede0..529643f6c 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -287,9 +288,15 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, SocketAddress remoteAddress, String id, String type) { if (channel != null && id != null) { - DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String response; + DateFormat dateFormat = new SimpleDateFormat(type.equals("R12") ? "HHmmss" : "yyyyMMddHHmmss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - String response = String.format("*HQ,%s,V4,%s,%s#", id, type, dateFormat.format(new Date())); + String time = dateFormat.format(new Date()); + if (type.equals("R12")) { + response = String.format("*HQ,%s,%s,%s#", id, type, time); + } else { + response = String.format("*HQ,%s,V4,%s,%s#", id, type, time); + } channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } @@ -316,6 +323,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext() && parser.next().equals("V1")) { sendResponse(channel, remoteAddress, id, "V1"); + } else if (Context.getConfig().getBoolean(getProtocolName() + ".ack")) { + sendResponse(channel, remoteAddress, id, "R12"); } DateBuilder dateBuilder = new DateBuilder(); diff --git a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java index 4746f7dd5..e8d77f1a8 100644 --- a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2018 - 2020 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. @@ -81,8 +81,8 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { .number("([01]{2}),") // outputs .groupBegin() .number("d+,") // index - .number("(d+.d+),") // adc1 - .number("(d+.d+),") // adc2 + .number("(d+.?d*),") // adc1 + .number("(d+.?d*),") // adc2 .groupEnd("?") .groupEnd("?") .or() @@ -195,22 +195,25 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { position.set("emergency", parser.nextInt() > 0); - String[] cells = parser.next().split(","); - int mcc = Integer.parseInt(cells[1]); - int mnc = Integer.parseInt(cells[2]); - int lac = Integer.parseInt(cells[3], 16); - int cid = Integer.parseInt(cells[4], 16); - Network network = new Network(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(cells[0]))); - if (!cells[5].startsWith("(")) { - for (int i = 0; i < 4; i++) { - lac = Integer.parseInt(cells[5 + 3 * i + 1], 16); - cid = Integer.parseInt(cells[5 + 3 * i + 2], 16); - if (lac > 0 && cid > 0) { - network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + String cellsString = parser.next(); + if (!cellsString.contains("x")) { + String[] cells = cellsString.split(","); + int mcc = Integer.parseInt(cells[1]); + int mnc = Integer.parseInt(cells[2]); + int lac = Integer.parseInt(cells[3], 16); + int cid = Integer.parseInt(cells[4], 16); + Network network = new Network(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(cells[0]))); + if (!cells[5].startsWith("(")) { + for (int i = 0; i < 4; i++) { + lac = Integer.parseInt(cells[5 + 3 * i + 1], 16); + cid = Integer.parseInt(cells[5 + 3 * i + 2], 16); + if (lac > 0 && cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } } } + position.setNetwork(network); } - position.setNetwork(network); String input = parser.next(); if (input.charAt(input.length() - 1) == '2') { diff --git a/src/main/java/org/traccar/protocol/OmnicommFrameDecoder.java b/src/main/java/org/traccar/protocol/OmnicommFrameDecoder.java index d6fedc40e..1caf6ceb9 100644 --- a/src/main/java/org/traccar/protocol/OmnicommFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/OmnicommFrameDecoder.java @@ -31,14 +31,14 @@ public class OmnicommFrameDecoder extends BaseFrameDecoder { return null; } - int endIndex = buf.getUnsignedShortLE(2) + buf.readerIndex() + 5; + int endIndex = buf.getUnsignedShortLE(2) + buf.readerIndex() + 6; if (buf.writerIndex() < endIndex) { return null; } ByteBuf result = Unpooled.buffer(); result.writeByte(buf.readUnsignedByte()); - while (buf.readerIndex() <= endIndex) { + while (buf.readerIndex() < endIndex) { int b = buf.readUnsignedByte(); if (b == 0xDB) { int ext = buf.readUnsignedByte(); @@ -47,11 +47,12 @@ public class OmnicommFrameDecoder extends BaseFrameDecoder { } else if (ext == 0xDD) { result.writeByte(0xDB); } + endIndex += 1; } else { result.writeByte(b); } } - return result; + return result; } } diff --git a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java index 40caa9727..23e2afbbd 100644 --- a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java @@ -41,14 +41,16 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { .setYear((int) BitUtil.between(value, 26, 32)) .setMonth((int) BitUtil.between(value, 22, 26)) .setDay((int) BitUtil.between(value, 17, 22)) - .setMonth((int) BitUtil.between(value, 12, 17)) - .setMonth((int) BitUtil.between(value, 6, 12)) - .setMonth((int) BitUtil.between(value, 0, 6)).getDate(); + .setHour((int) BitUtil.between(value, 12, 17)) + .setMinute((int) BitUtil.between(value, 6, 12)) + .setSecond((int) BitUtil.between(value, 0, 6)).getDate(); } private double readCoordinate(ByteBuf buf) { long value = buf.readUnsignedInt(); - return (BitUtil.from(value, 16) + BitUtil.to(value, 16) * 0.00001) / 60; + int sign = BitUtil.check(value, 31) ? -1 : 1; + value = BitUtil.to(value, 31); + return sign * (BitUtil.from(value, 16) + BitUtil.to(value, 16) * 0.00001) / 60; } @Override @@ -85,7 +87,10 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { switch (tag) { case 0x0D: - position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte() * 5); + int battery = buf.readUnsignedByte(); + if (battery <= 20) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte() * 5); + } break; case 0x10: position.setFixTime(readDate(buf)); @@ -102,7 +107,7 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { } } - return position; + return position.getFixTime() != null ? position : null; } return null; diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java index f9fcfe79d..8d58803c9 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2020 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. @@ -242,6 +242,10 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); position.set(Position.KEY_STATUS, Integer.parseInt(values[index++])); + if (values[index].length() == 3) { + index += 1; // collaborative network + } + DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); position.setTime(dateFormat.parse(values[index++] + values[index++])); |