diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-11-30 10:31:58 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-11-30 10:31:58 +1300 |
commit | 347880dbffce82f8d2859077b750b6245ea7d0ac (patch) | |
tree | 4db817f50af195b20639f325aba193414686642c /src | |
parent | 021728a530608d771c381e0f8fbaf120997717c2 (diff) | |
download | traccar-server-347880dbffce82f8d2859077b750b6245ea7d0ac.tar.gz traccar-server-347880dbffce82f8d2859077b750b6245ea7d0ac.tar.bz2 traccar-server-347880dbffce82f8d2859077b750b6245ea7d0ac.zip |
Support Suntech per device config
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/SuntechProtocolDecoder.java | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index ad1da537b..9ef0474b2 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -41,29 +41,44 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { public SuntechProtocolDecoder(Protocol protocol) { super(protocol); - - protocolType = Context.getConfig().getInteger(getProtocolName() + ".protocolType"); - hbm = Context.getConfig().getBoolean(getProtocolName() + ".hbm"); - includeAdc = Context.getConfig().getBoolean(getProtocolName() + ".includeAdc"); - includeTemp = Context.getConfig().getBoolean(getProtocolName() + ".includeTemp"); } public void setProtocolType(int protocolType) { this.protocolType = protocolType; } + public int getProtocolType(long deviceId) { + return Context.getIdentityManager().lookupAttributeInteger( + deviceId, getProtocolName() + ".protocolType", protocolType, true); + } + public void setHbm(boolean hbm) { this.hbm = hbm; } + public boolean isHbm(long deviceId) { + return Context.getIdentityManager().lookupAttributeBoolean( + deviceId, getProtocolName() + ".hbm", hbm, true); + } + public void setIncludeAdc(boolean includeAdc) { this.includeAdc = includeAdc; } + public boolean isIncludeAdc(long deviceId) { + return Context.getIdentityManager().lookupAttributeBoolean( + deviceId, getProtocolName() + ".includeAdc", includeAdc, true); + } + public void setIncludeTemp(boolean includeTemp) { this.includeTemp = includeTemp; } + public boolean isIncludeTemp(long deviceId) { + return Context.getIdentityManager().lookupAttributeBoolean( + deviceId, getProtocolName() + ".includeTemp", includeTemp, true); + } + private Position decode9( Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { int index = 1; @@ -86,7 +101,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } - if (!type.equals("Alert") || protocolType == 0) { + if (!type.equals("Alert") || getProtocolType(deviceSession.getDeviceId()) == 0) { position.set(Position.KEY_VERSION_FW, values[index++]); } @@ -94,7 +109,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); position.setTime(dateFormat.parse(values[index++] + values[index++])); - if (protocolType == 1) { + if (getProtocolType(deviceSession.getDeviceId()) == 1) { index += 1; // cell } @@ -105,7 +120,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setValid(values[index++].equals("1")); - if (protocolType == 1) { + if (getProtocolType(deviceSession.getDeviceId()) == 1) { position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++])); } @@ -302,7 +317,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { break; } - if (hbm) { + if (isHbm(deviceSession.getDeviceId())) { if (index < values.length) { position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(Integer.parseInt(values[index++]))); @@ -316,7 +331,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - if (includeAdc) { + if (isIncludeAdc(deviceSession.getDeviceId())) { for (int i = 1; i <= 3; i++) { if (!values[index++].isEmpty()) { position.set(Position.PREFIX_ADC + i, Double.parseDouble(values[index - 1])); @@ -331,7 +346,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { } } - if (includeTemp) { + if (isIncludeTemp(deviceSession.getDeviceId())) { for (int i = 1; i <= 3; i++) { String temperature = values[index++]; String value = temperature.substring(temperature.indexOf(':') + 1); |