error counting

This commit is contained in:
Wolfgang Hottgenroth 2020-09-07 19:46:25 +02:00
parent 53ac161489
commit 1ca935742a
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
5 changed files with 33 additions and 3 deletions

View File

@ -6,14 +6,16 @@ public class ElectricEnergyDataObject extends ADataObject {
private static final long serialVersionUID = 1L;
static final String ENERGY_KEY = "energy";
static final String POWER_KEY = "power";
static final String ERROR_RATIO_KEY = "errorRatio";
static final String TABLE_NAME = "ElectricEnergy";
static final String KIND_NAME = "ElectricEnergy";
public ElectricEnergyDataObject(String name, double energy, double power) {
public ElectricEnergyDataObject(String name, double energy, double power, double errorRatio) {
super(name, KIND_NAME);
HashMap<String, Object> values = new HashMap<String, Object>();
values.put(ENERGY_KEY, energy);
values.put(POWER_KEY, power);
values.put(ERROR_RATIO_KEY, errorRatio);
setValues(values);
}

View File

@ -11,6 +11,6 @@ public class FinderOnePhasePowerMeter extends MbusDevice {
}
public ADataObject getDataObject() throws MbusException {
return new ElectricEnergyDataObject(this.getName(), this.getValue("energy"), this.getValue("activePower"));
return new ElectricEnergyDataObject(this.getName(), this.getValue("energy"), this.getValue("activePower"), this.getErrorRatio());
}
}

View File

@ -21,6 +21,6 @@ public class FinderThreePhasePowerMeter extends MbusDevice {
}
public ADataObject getDataObject() throws MbusException {
return new ElectricEnergyDataObject(this.getName(), this.getValue("energy"), this.getValue("activePowerTotal"));
return new ElectricEnergyDataObject(this.getName(), this.getValue("energy"), this.getValue("activePowerTotal"), this.getErrorRatio());
}
}

View File

@ -21,6 +21,9 @@ abstract public class MbusDevice {
private byte address;
private int queryPeriod; // in seconds
private int successCnt;
private int errorCnt;
protected List<DataRecord> dataRecords;
protected boolean validlyParsed;
@ -41,9 +44,31 @@ abstract public class MbusDevice {
this.address = address;
this.queryPeriod = queryPeriod;
this.validlyParsed = false;
this.successCnt = 0;
this.errorCnt = 0;
this.dataPoints = new ArrayList<>();
}
public void incSuccessCnt() {
this.successCnt++;
}
public void incErrorCnt() {
this.errorCnt++;
}
public void resetSuccessCnt() {
this.successCnt = 0;
}
public void resetErrorCnt() {
this.errorCnt = 0;
}
public double getErrorRatio() {
return this.errorCnt / this.successCnt;
}
public void parse(byte[] frame) throws MbusException {
try {
MBusMessage mbusMsg = MBusMessage.decode(frame, frame.length);
@ -82,6 +107,7 @@ abstract public class MbusDevice {
StringBuffer sb = new StringBuffer();
sb.append(this.getClass().getName() + " [");
sb.append("<name=" + this.getName() + "><address=" + this.getAddress() + ">");
sb.append("<successCnt=" + this.successCnt + "><errorCnt=" + this.errorCnt + ">");
if (longOutput && this.validlyParsed) {
sb.append(this.dataToString());
}

View File

@ -60,8 +60,10 @@ public class MbusScheduledQuerier extends Thread {
logger.info("Got: " + device.toString());
this.queue.add(device.getDataObject());
device.incSuccessCnt();
successCnt++;
} catch (IOException e) {
device.incErrorCnt();
errCnt++;
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device.shortString());
}