diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java | 137 |
1 files changed, 64 insertions, 73 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java index 2d00ea81e..5bf76eba7 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 - 2021 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. @@ -45,6 +45,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { private boolean includeAdc; private boolean includeRpm; private boolean includeTemp; + private boolean m2m; public SuntechProtocolDecoder(Protocol protocol) { super(protocol); @@ -98,6 +99,15 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { return Context.getIdentityManager().lookupAttributeBoolean( deviceId, getProtocolName() + ".includeTemp", includeTemp, false, true); } + + public void setM2M(boolean m2m) { + this.m2m = m2m; + } + + public boolean isM2M(long deviceId) { + return Context.getIdentityManager().lookupAttributeBoolean( + deviceId, getProtocolName() + ".m2m", m2m, true, false); + } private Position decode9( Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { @@ -161,7 +171,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { case 7: return Position.ALARM_MOVEMENT; case 8: - return Position.ALARM_VIBRATION; + return Position.ALARM_SHOCK; default: return null; } @@ -178,7 +188,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { case 14: return Position.ALARM_LOW_BATTERY; case 15: - return Position.ALARM_VIBRATION; + return Position.ALARM_SHOCK; case 16: return Position.ALARM_ACCIDENT; case 40: @@ -396,11 +406,15 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { if (isHbm(deviceSession.getDeviceId())) { if (index < values.length) { - position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(Integer.parseInt(values[index++]))); + try { + position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(Integer.parseInt(values[index++]))); + } catch (NumberFormatException e) {} } if (index < values.length) { - position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + try { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } catch (NumberFormatException e) {} } if (index < values.length && values[index++].equals("0")) { @@ -448,7 +462,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { String type = values[index++]; - if (!type.equals("STT") && !type.equals("ALT") && !type.equals("BLE")) { + if (!type.equals("STT") && !type.equals("ALT")) { return null; } @@ -461,12 +475,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_TYPE, type); - int mask; - if (type.equals("BLE")) { - mask = 0b1100000110110; - } else { - mask = Integer.parseInt(values[index++], 16); - } + int mask = Integer.parseInt(values[index++], 16); if (BitUtil.check(mask, 1)) { index += 1; // model @@ -515,83 +524,65 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(Double.parseDouble(values[index++])); } - if (type.equals("BLE")) { + if (BitUtil.check(mask, 13)) { + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + } - position.setValid(true); + if (BitUtil.check(mask, 14)) { + position.setCourse(Double.parseDouble(values[index++])); + } - int count = Integer.parseInt(values[index++]); + if (BitUtil.check(mask, 15)) { + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + } - for (int i = 1; i <= count; i++) { - position.set("tag" + i + "Rssi", Integer.parseInt(values[index++])); - index += 1; // rssi min - index += 1; // rssi max - position.set("tag" + i + "Id", values[index++]); - position.set("tag" + i + "Samples", Integer.parseInt(values[index++])); - position.set("tag" + i + "Major", Integer.parseInt(values[index++])); - position.set("tag" + i + "Minor", Integer.parseInt(values[index++])); - } + if (BitUtil.check(mask, 16)) { + position.setValid(values[index++].equals("1")); + } - } else { + if (BitUtil.check(mask, 17)) { + String in = values[index++]; + position.set(Position.KEY_INPUT, Integer.parseInt(in)); + position.set(Position.KEY_IGNITION, in.charAt(7) == '1'); + } - if (BitUtil.check(mask, 13)) { - position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); - } + if (BitUtil.check(mask, 18)) { + position.set(Position.KEY_OUTPUT, Integer.parseInt(values[index++])); + } - if (BitUtil.check(mask, 14)) { - position.setCourse(Double.parseDouble(values[index++])); + if (type.equals("ALT")) { + if (BitUtil.check(mask, 19)) { + position.set("alertId", values[index++]); } - - if (BitUtil.check(mask, 15)) { - position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + if (BitUtil.check(mask, 20)) { + position.set("alertModifier", values[index++]); } - - if (BitUtil.check(mask, 16)) { - position.setValid(values[index++].equals("1")); + if (BitUtil.check(mask, 21)) { + position.set("alertData", values[index++]); } - - if (BitUtil.check(mask, 17)) { - position.set(Position.KEY_INPUT, Integer.parseInt(values[index++])); + } else { + if (BitUtil.check(mask, 19)) { + position.set("mode", Integer.parseInt(values[index++])); } - - if (BitUtil.check(mask, 18)) { - position.set(Position.KEY_OUTPUT, Integer.parseInt(values[index++])); + if (BitUtil.check(mask, 20)) { + position.set("reason", Integer.parseInt(values[index++])); } - - if (type.equals("ALT")) { - if (BitUtil.check(mask, 19)) { - position.set("alertId", values[index++]); - } - if (BitUtil.check(mask, 20)) { - position.set("alertModifier", values[index++]); - } - if (BitUtil.check(mask, 21)) { - position.set("alertData", values[index++]); - } - } else { - if (BitUtil.check(mask, 19)) { - position.set("mode", Integer.parseInt(values[index++])); - } - if (BitUtil.check(mask, 20)) { - position.set("reason", Integer.parseInt(values[index++])); - } - if (BitUtil.check(mask, 21)) { - position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); - } + if (BitUtil.check(mask, 21)) { + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); } + } - if (BitUtil.check(mask, 22)) { - index += 1; // reserved - } + if (BitUtil.check(mask, 22)) { + index += 1; // reserved + } - if (BitUtil.check(mask, 23)) { - int assignMask = Integer.parseInt(values[index++], 16); - for (int i = 0; i <= 30; i++) { - if (BitUtil.check(assignMask, i)) { - position.set(Position.PREFIX_IO + (i + 1), values[index++]); - } + if (BitUtil.check(mask, 23)) { + int assignMask = Integer.parseInt(values[index++], 16); + for (int i = 0; i <= 30; i++) { + if (BitUtil.check(assignMask, i)) { + position.set(Position.PREFIX_IO + (i + 1), values[index++]); } } - } return position; |