diff options
Diffstat (limited to 'src/org/traccar/protocol/Gl200TextProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Gl200TextProtocolDecoder.java | 139 |
1 files changed, 91 insertions, 48 deletions
diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java index e664c4734..ff300d429 100644 --- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -210,7 +210,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version .number("(d{15}|x{14}),") // imei .expression("[^,]*,") // device name - .number("x{8},") // mask + .number("(x{8}),") // mask .number("(d+)?,") // power .number("d{1,2},") // report type .number("d{1,2},") // count @@ -429,8 +429,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { parser.next(); // odometer or external power - position.set(Position.KEY_BATTERY, parser.nextDouble(0)); - position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + position.set(Position.KEY_CHARGE, parser.nextInt() == 1); position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); @@ -444,7 +444,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, parser.nextDateTime()); - position.set(Position.KEY_INDEX, parser.nextHexInt(0)); + position.set(Position.KEY_INDEX, parser.nextHexInt()); return position; } @@ -457,8 +457,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { } position.set("deviceType", parser.next()); - position.set(Position.KEY_VERSION_FW, parser.nextHexInt(0)); - position.set(Position.KEY_VERSION_HW, parser.nextHexInt(0)); + position.set(Position.KEY_VERSION_FW, parser.nextHexInt()); + position.set(Position.KEY_VERSION_HW, parser.nextHexInt()); getLastLocation(position, parser.nextDateTime()); @@ -466,8 +466,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { } private void decodeLocation(Position position, Parser parser) { - int hdop = parser.nextInt(0); - position.setValid(hdop > 0); + Integer hdop = parser.nextInt(); + position.setValid(hdop == null || hdop > 0); position.set(Position.KEY_HDOP, hdop); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); @@ -476,25 +476,27 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(8)) { position.setValid(true); - position.setLongitude(parser.nextDouble(0)); - position.setLatitude(parser.nextDouble(0)); + position.setLongitude(parser.nextDouble()); + position.setLatitude(parser.nextDouble()); position.setTime(parser.nextDateTime()); } else { getLastLocation(position, null); } if (parser.hasNext(6)) { - int mcc = parser.nextInt(0); - int mnc = parser.nextInt(0); + int mcc = parser.nextInt(); + int mnc = parser.nextInt(); if (parser.hasNext(2)) { - position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(0), parser.nextInt(0)))); + position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(), parser.nextInt()))); } if (parser.hasNext(2)) { - position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0)))); + position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt()))); } } - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + } } private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) { @@ -509,16 +511,22 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_TEMP + 1, parser.nextInt()); position.set(Position.KEY_FUEL_CONSUMPTION, parser.next()); position.set("dtcsClearedDistance", parser.nextInt()); - position.set("odbConnect", parser.nextInt(0) == 1); + if (parser.hasNext()) { + position.set("odbConnect", parser.nextInt() == 1); + } position.set("dtcsNumber", parser.nextInt()); position.set("dtcsCodes", parser.next()); position.set(Position.KEY_THROTTLE, parser.nextInt()); position.set(Position.KEY_FUEL_LEVEL, parser.nextInt()); - position.set(Position.KEY_OBD_ODOMETER, parser.nextInt(0) * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000); + } decodeLocation(position, parser); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_OBD_ODOMETER, (int) (parser.nextDouble() * 1000)); + } decodeDeviceTime(position, parser); @@ -649,14 +657,14 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { private void decodeStatus(Position position, Parser parser) { if (parser.hasNext(3)) { - int ignition = parser.nextHexInt(0); + int ignition = parser.nextHexInt(); if (BitUtil.check(ignition, 4)) { position.set(Position.KEY_IGNITION, false); } else if (BitUtil.check(ignition, 5)) { position.set(Position.KEY_IGNITION, true); } - position.set(Position.KEY_INPUT, parser.nextHexInt(0)); - position.set(Position.KEY_OUTPUT, parser.nextHexInt(0)); + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_OUTPUT, parser.nextHexInt()); } } @@ -674,7 +682,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { LinkedList<Position> positions = new LinkedList<>(); String vin = parser.next(); - int power = parser.nextInt(0); + Integer power = parser.nextInt(); Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); while (itemParser.find()) { @@ -692,14 +700,18 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - if (power > 10) { + if (power != null && power > 10) { position.set(Position.KEY_POWER, power * 0.001); // only on some devices } - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + } position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (parser.hasNext()) { + 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()); @@ -730,9 +742,11 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { return null; } + long mask = parser.nextHexLong(); + LinkedList<Position> positions = new LinkedList<>(); - int power = parser.nextInt(0); + Integer power = parser.nextInt(); Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); while (itemParser.find()) { @@ -748,8 +762,10 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - position.set(Position.KEY_POWER, power * 0.001); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (power != null) { + position.set(Position.KEY_POWER, power * 0.001); + } + 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()); @@ -759,14 +775,37 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { int index = 0; String[] data = parser.next().split(","); - if (data.length > 1) { - int deviceType = Integer.parseInt(data[index++]); - if (deviceType == 2) { - int deviceCount = Integer.parseInt(data[index++]); - for (int i = 1; i <= deviceCount; i++) { - index++; // id - index++; // type - position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index++], 16) * 0.0625); + + index += 1; // device type + + if (BitUtil.check(mask, 0)) { + index += 1; // digital fuel sensor data + } + + if (BitUtil.check(mask, 1)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; // id + index += 1; // type + if (!data[index++].isEmpty()) { + position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625); + } + } + } + + if (BitUtil.check(mask, 2)) { + index += 1; // can data + } + + if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; // type + if (BitUtil.check(mask, 3)) { + position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++])); + } + if (BitUtil.check(mask, 4)) { + index += 1; // volume } } } @@ -790,7 +829,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); position.set(Position.KEY_HOURS, parser.next()); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); decodeDeviceTime(position, parser); @@ -808,7 +847,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); decodeDeviceTime(position, parser); @@ -826,7 +865,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { Network network = new Network(); - parser.nextInt(0); // count + parser.nextInt(); // count Matcher matcher = Pattern.compile("([0-9a-fA-F]{12}),(-?\\d+),,,,").matcher(parser.next()); while (matcher.find()) { String mac = matcher.group(1).replaceAll("(..)", "$1:"); @@ -836,7 +875,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.setNetwork(network); - position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); return position; } @@ -874,7 +913,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { return null; } - int reportType = parser.nextInt(0); + int reportType = parser.nextInt(); if (type.equals("NMR")) { position.set(Position.KEY_MOTION, reportType == 1); } else if (type.equals("SOS")) { @@ -883,10 +922,14 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); - position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + } + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + } decodeDeviceTime(position, parser); @@ -904,7 +947,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { return null; } - int hdop = parser.nextInt(0); + int hdop = parser.nextInt(); position.setValid(hdop > 0); position.set(Position.KEY_HDOP, hdop); @@ -913,8 +956,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextDouble(0)); if (parser.hasNext(2)) { - position.setLongitude(parser.nextDouble(0)); - position.setLatitude(parser.nextDouble(0)); + position.setLongitude(parser.nextDouble()); + position.setLatitude(parser.nextDouble()); } else { getLastLocation(position, null); } @@ -925,7 +968,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(4)) { position.setNetwork(new Network(CellTower.from( - parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0)))); + parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt()))); } decodeDeviceTime(position, parser); |