Skip to content

Commit

Permalink
#2755 signaling the data source that has a problem:
Browse files Browse the repository at this point in the history
- DataPointUnreliableUtilsTest.java;
- use methods returnToNormal and raiseEvent from DataSourceRT;
- added methods: LoggingUtils.info, LoggingUtils.dataPointInfo, LoggingUtils.dataPointRtInfo, PollingDataSource.getDataPoints, EventDataSource.getDataPoints, DataSourceRT.getDataPoints;
  • Loading branch information
Limraj committed Feb 9, 2024
1 parent eb8b857 commit 7ced950
Show file tree
Hide file tree
Showing 43 changed files with 544 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ protected void doPoll(long time) {
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
vo.getName(), e.getMessage()), dataPoint);
timestamp = time;
}

}

dataPoint.updatePointValue(new PointValueTime(value,
timestamp));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2", vo
.getName(), e.getMessage()));
.getName(), e.getMessage()), dataPoint);
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected void doPoll(long time) {
new LocalizableMessage("event.exception2",
vo.getName(), "Sem dados disponíveis !"));
} else if (getInSerialStream().available() > 0) {
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, time);
byte[] readBuffer = new byte[vo.getBufferSize()];
try {

Expand Down Expand Up @@ -176,18 +177,19 @@ protected void doPoll(long time) {
new LocalizableMessage(
"event.exception2", vo
.getName(), e
.getMessage()));
.getMessage()), dataPoint);
timestamp = time;
}

}

dataPoint.updatePointValue(new PointValueTime(
value, timestamp));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
vo.getName(), e.getMessage()), dataPoint);
// e.printStackTrace();
}

Expand Down
14 changes: 6 additions & 8 deletions src/br/org/scadabr/rt/dataSource/dnp3/Dnp3DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import com.serotonin.messaging.TimeoutException;
import com.serotonin.web.i18n.LocalizableMessage;

import static com.serotonin.mango.rt.dataSource.DataPointUnreliableUtils.*;

public class Dnp3DataSource extends PollingDataSource {

private final Log LOG = LogFactory.getLog(Dnp3DataSource.class);

public static final int POINT_READ_EXCEPTION_EVENT = 1;
public static final int DATA_SOURCE_EXCEPTION_EVENT = 2;
public static final int POINT_WRITE_EXCEPTION_EVENT = 3;

private DNP3Master dnp3Master;
private final Dnp3DataSourceVO<?> vo;
Expand All @@ -46,9 +45,7 @@ protected void doPoll(long time) {
try {
dnp3Master.doPoll();
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, time);
resetUnreliableDataPoints(dataPoints);
} catch (Exception e) {
setUnreliableDataPoints(dataPoints);
LOG.warn(e.getMessage(), e);
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2", vo.getName(), e
Expand Down Expand Up @@ -86,9 +83,8 @@ public void terminate() {
super.terminate();
try {
dnp3Master.terminate();
resetUnreliableDataPoints(dataPoints);
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (Exception e) {
setUnreliableDataPoints(dataPoints);
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
Expand All @@ -114,9 +110,11 @@ public void setPointValue(DataPointRT dataPoint, PointValueTime valueTime,
dnp3Master
.sendAnalogCommand(index, valueTime.getIntegerValue());
}
resetUnreliableDataPoint(dataPoint);
returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), dataPoint);
} catch (Exception e) {
setUnreliableDataPoint(dataPoint);
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, new Date().getTime(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()), dataPoint);
LOG.error(e.getMessage(), e);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/br/org/scadabr/rt/dataSource/dnp3/Dnp3IpDataSource.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package br.org.scadabr.rt.dataSource.dnp3;

import java.util.Date;

import br.org.scadabr.vo.dataSource.dnp3.Dnp3IpDataSourceVO;

import com.serotonin.web.i18n.LocalizableMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import static com.serotonin.mango.rt.dataSource.DataPointUnreliableUtils.*;

public class Dnp3IpDataSource extends Dnp3DataSource {

private static final Log LOG = LogFactory.getLog(Dnp3IpDataSource.class);
Expand All @@ -29,11 +26,10 @@ public void initialize() {
configuration.getSlaveAddress(), configuration.getHost(),
configuration.getPort(), configuration
.getStaticPollPeriods());
resetUnreliableDataPoints(dataPoints);
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (Exception e) {
setUnreliableDataPoints(dataPoints);
LOG.error(e.getMessage(), e);
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true,
new LocalizableMessage("event.exception2", configuration
.getName(), e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import static com.serotonin.mango.rt.dataSource.DataPointUnreliableUtils.resetUnreliableDataPoints;
import static com.serotonin.mango.rt.dataSource.DataPointUnreliableUtils.setUnreliableDataPoints;

public class Dnp3SerialDataSource extends Dnp3DataSource {

private static final Log LOG = LogFactory.getLog(Dnp3SerialDataSource.class);
Expand All @@ -33,9 +30,8 @@ public void initialize() {
configuration.getSlaveAddress(), configuration
.getCommPortId(), configuration.getBaudRate(),
configuration.getStaticPollPeriods());
resetUnreliableDataPoints(dataPoints);
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (Exception e) {
setUnreliableDataPoints(dataPoints);
LOG.error(e.getMessage(), e);
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
new LocalizableMessage("event.exception2", configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.org.scadabr.rt.dataSource.drStorageHt5b;

import com.serotonin.mango.util.LoggingUtils;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

Expand Down Expand Up @@ -89,12 +90,12 @@ protected void doPoll(long time) {
dataPoint.updatePointValue(new PointValueTime(
hum, System.currentTimeMillis()));
}

returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
e.printStackTrace();
vo.getName(), e.getMessage()), dataPoint);
LOG.error(LoggingUtils.exceptionInfo(e) + " - " + LoggingUtils.dataSourceInfo(this), e);
}

}
Expand Down
16 changes: 9 additions & 7 deletions src/br/org/scadabr/rt/dataSource/iec101/IEC101DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Date;
import java.util.List;

import com.serotonin.mango.util.LoggingUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -40,10 +41,10 @@ protected void doPoll(long time) {
try {
iec101Master.doPoll();
} catch (Exception e) {
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
e.printStackTrace();
LOG.error(LoggingUtils.info(e, this), e);
}

for (DataPointRT dataPoint : dataPoints) {
Expand Down Expand Up @@ -85,11 +86,12 @@ public void setPointValue(DataPointRT dataPoint, PointValueTime valueTime,
iec101Master.setPointCommand(ioa, select, qualifier, valueTime
.getIntegerValue());
}
returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), dataPoint);
} catch (Exception e) {
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, new Date().getTime(), true,
raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
e.printStackTrace();
.getMessage()), dataPoint);
LOG.error(LoggingUtils.info(e, this, dataPoint), e);
}
}

Expand All @@ -116,7 +118,7 @@ protected void initialize(IEC101Master iec101Master) {
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
e.printStackTrace();
LOG.error(LoggingUtils.info(e, this), e);
}
super.initialize();
}
Expand All @@ -130,7 +132,7 @@ public void terminate() {
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, new Date().getTime(), true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
e.printStackTrace();
LOG.error(LoggingUtils.info(e, this), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.serotonin.mango.util.LoggingUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -66,22 +67,23 @@ protected void doPoll(long time) {
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
vo.getName(), e.getMessage()), dataPoint);
timestamp = time;
}

}

dataPoint.updatePointValue(new PointValueTime(value,
timestamp));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
raiseEvent(
POINT_READ_EXCEPTION_EVENT,
time,
true,
new LocalizableMessage("event.exception2", vo
.getName(), e.getMessage()));
e.printStackTrace();
.getName(), e.getMessage()), dataPoint);
LOG.error(LoggingUtils.info(e, this, dataPoint), e);
}

}
Expand Down
12 changes: 7 additions & 5 deletions src/br/org/scadabr/rt/dataSource/opc/OPCDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.logging.Level;

import com.serotonin.mango.util.LoggingUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jinterop.dcom.common.JISystem;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected void doPoll(long time) {
try {

if (timeoutCount >= timeoutsToReconnect) {
System.out.println("[OPC] Trying to reconnect !");
LOG.error("[OPC] Trying to reconnect ! :" + LoggingUtils.dataSourceInfo(this));
timeoutCount = 0;
initialize();
} else {
Expand All @@ -70,7 +71,7 @@ protected void doPoll(long time) {
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
timeoutCount++;
System.out.println("[OPC] Poll Failed !");
LOG.error("[OPC] Poll Failed ! :" + LoggingUtils.info(e, this));
}

for (DataPointRT dataPoint : dataPoints) {
Expand All @@ -85,10 +86,11 @@ protected void doPoll(long time) {
dataPointVO.getDataTypeId());
dataPoint
.updatePointValue(new PointValueTime(mangoValue, time));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
vo.getName(), e.getMessage()), dataPoint);
}
}
}
Expand Down Expand Up @@ -116,8 +118,8 @@ else if (dataPoint.getDataTypeId() == DataTypes.MULTISTATE)
System.currentTimeMillis(),
true,
new LocalizableMessage("event.exception2", vo.getName(), e
.getMessage()));
e.printStackTrace();
.getMessage()), dataPoint);
LOG.error(LoggingUtils.info(e, this, dataPoint), e);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/br/org/scadabr/vo/dataSource/dnp3/Dnp3DataSourceVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected void addEventTypes(List<EventTypeVO> eventTypes) {
eventTypes.add(createEventType(
Dnp3DataSource.DATA_SOURCE_EXCEPTION_EVENT,
new LocalizableMessage("event.ds.dataSource")));
eventTypes.add(createEventType(
Dnp3DataSource.POINT_WRITE_EXCEPTION_EVENT,
new LocalizableMessage("event.ds.pointWrite")));
}

private static final ExportCodes EVENT_CODES = new ExportCodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,15 @@ private void pacoteRecebido() {
.parsePacoteRadiuino(time, pacote, dataPointVO);
if (pointValueTime != null)
dataPoint.updatePointValue(pointValueTime);
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
LOG.error("Erro ao fazer o parse dos dados.", e);
raiseEvent(
POINT_READ_EXCEPTION_EVENT,
time,
true,
new LocalizableMessage("event.exception2", vo
.getName(), e.getMessage()));
.getName(), e.getMessage()), dataPoint);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,15 @@ private void pacoteRecebido() {
.parsePacoteRadiuino(time, pacote, dataPointVO);
if (pointValueTime != null)
dataPoint.updatePointValue(pointValueTime);
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
LOG.error("Erro ao fazer o parse dos dados.", e);
raiseEvent(
POINT_READ_EXCEPTION_EVENT,
time,
true,
new LocalizableMessage("event.exception2", vo
.getName(), e.getMessage()));
.getName(), e.getMessage()), dataPoint);
}

}
Expand Down
Loading

0 comments on commit 7ced950

Please sign in to comment.