Skip to content

Commit

Permalink
Support Suntech per device config
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Nov 29, 2018
1 parent 021728a commit 347880d
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/org/traccar/protocol/SuntechProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -86,15 +101,15 @@ private Position decode9(
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++]);
}

DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
position.setTime(dateFormat.parse(values[index++] + values[index++]));

if (protocolType == 1) {
if (getProtocolType(deviceSession.getDeviceId()) == 1) {
index += 1; // cell
}

Expand All @@ -105,7 +120,7 @@ private Position decode9(

position.setValid(values[index++].equals("1"));

if (protocolType == 1) {
if (getProtocolType(deviceSession.getDeviceId()) == 1) {
position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++]));
}

Expand Down Expand Up @@ -302,7 +317,7 @@ private Position decode2356(
break;
}

if (hbm) {
if (isHbm(deviceSession.getDeviceId())) {

if (index < values.length) {
position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(Integer.parseInt(values[index++])));
Expand All @@ -316,7 +331,7 @@ private Position decode2356(
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]));
Expand All @@ -331,7 +346,7 @@ private Position decode2356(
}
}

if (includeTemp) {
if (isIncludeTemp(deviceSession.getDeviceId())) {
for (int i = 1; i <= 3; i++) {
String temperature = values[index++];
String value = temperature.substring(temperature.indexOf(':') + 1);
Expand Down

0 comments on commit 347880d

Please sign in to comment.