error counting
This commit is contained in:
parent
53ac161489
commit
1ca935742a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user