use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class EnvCanDataSourceRT method doPoll.
@Override
protected void doPoll(long time) {
if (nextValueTime == -1) {
// Determine when we should start from
nextValueTime = System.currentTimeMillis();
for (DataPointRT dp : dataPoints) {
PointValueTime pvt = dp.getPointValue();
if (pvt == null) {
nextValueTime = 0;
break;
}
if (nextValueTime > pvt.getTime())
nextValueTime = pvt.getTime();
}
if (nextValueTime == 0)
nextValueTime = vo.getDataStartTime();
else
nextValueTime += 1000 * 60 * 60;
}
long previousValueTime = nextValueTime;
doPollImpl(time);
if (nextValueTime == previousValueTime)
raiseEvent(NO_DATA_RETRIEVED_EVENT, time, true, new TranslatableMessage("envcands.event.noTemperatureData"));
else
returnToNormal(NO_DATA_RETRIEVED_EVENT, time);
while (nextValueTime != previousValueTime) {
// Something was changed.
DateTime prev = new DateTime(previousValueTime);
DateTime now = new DateTime(System.currentTimeMillis());
if (prev.getYear() < now.getYear() || prev.getMonthOfYear() < now.getMonthOfYear()) {
previousValueTime = nextValueTime;
doPollImpl(time);
} else
break;
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class AsciiFileDataSourceRT method fileEvent.
private void fileEvent(List<DataPointRT> dataPoints) {
// Should never happen
if (this.file == null) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailedFileNotSetup"));
return;
}
if (restrictedPath) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("dsEdit.file.pathRestrictedBy", vo.getFilePath()));
return;
}
// The file is modified or we've just started, so read it.
try {
BufferedReader reader = new BufferedReader(new FileReader(this.file));
String msg;
if (!dataPoints.isEmpty()) {
// TODO optimize to be better than numLines*numPoints
while ((msg = reader.readLine()) != null) {
// Give all points the chance to find their data
for (final DataPointRT dp : dataPoints) {
AsciiFilePointLocatorRT pl = dp.getPointLocator();
final AsciiFilePointLocatorVO plVo = pl.getVo();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
if (!plVo.getHasTimestamp())
dp.updatePointValue(value);
else
dp.savePointValueDirectToCache(value, null, true, true);
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
// N/A
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
// N/A
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), false, new TranslatableMessage("file.event.insufficientGroups", dp.getVO().getExtendedName()));
}
@Override
public void matchGeneralFailure(Exception e) {
if (e instanceof ParseException)
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.dateParseFailed", e.getMessage()));
else if (e instanceof NumberFormatException) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
} else
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
}
};
matchPointValueTime(msg, pl.getValuePattern(), plVo.getPointIdentifier(), plVo.getPointIdentifierIndex(), plVo.getDataTypeId(), plVo.getValueIndex(), plVo.getHasTimestamp(), plVo.getTimestampIndex(), plVo.getTimestampFormat(), callback);
}
}
reader.close();
returnToNormal(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis());
}
} catch (FileNotFoundException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound", e.getMessage()));
} catch (IOException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", e.getMessage()));
} catch (NumberFormatException e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber", e.getMessage()));
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method preparePointComponentState.
/**
* Shared convenience method for creating a populated view component state.
*/
private ViewComponentState preparePointComponentState(PointComponent pointComponent, boolean update, User user, DataPointRT point, Map<String, Object> model, HttpServletRequest request) {
ViewComponentState state = new ViewComponentState();
state.setId(pointComponent.getId());
PointValueTime pointValue = prepareBasePointState(pointComponent.getId(), state, pointComponent.tgetDataPoint(), point, model);
model.put("pointComponent", pointComponent);
if (pointComponent.isValid()) {
if (!update && pointComponent.getCachedContent(MODEL_ATTR_EVENTS) != null)
model.put(MODEL_ATTR_EVENTS, pointComponent.getCachedContent(MODEL_ATTR_EVENTS));
else {
setEvents(pointComponent.tgetDataPoint(), user, model, pointEventsLimit);
pointComponent.putCachedContent(MODEL_ATTR_EVENTS, model.get(MODEL_ATTR_EVENTS));
}
}
pointComponent.addDataToModel(model, pointValue);
if (!pointComponent.isValid())
model.put("invalid", "true");
else {
// Add the rendered text as a convenience to the snippets.
model.put("text", pointComponent.tgetDataPoint().getTextRenderer().getText(pointValue, TextRenderer.HINT_FULL));
state.setContent(generateViewContent(pointComponent, update, request, pointComponent.snippetName() + ".jsp", model));
pointComponent.tgetDataPoint().updateLastValue(pointValue);
}
state.setInfo(generateViewContent(pointComponent, update, request, "infoContent.jsp", model));
// TODO Cache this
setMessages(state, request, getFullSnippetName("warningContent.jsp"), model);
return state;
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method addPointComponentState.
private void addPointComponentState(ViewComponent viewComponent, boolean update, RuntimeManager rtm, Map<String, Object> model, HttpServletRequest request, GraphicalView view, User user, List<ViewComponentState> states, boolean edit, boolean add) {
if (viewComponent.isPointComponent() && (edit || viewComponent.isVisible())) {
PointComponent pointComponent = (PointComponent) viewComponent;
DataPointRT dataPointRT = null;
if (pointComponent.tgetDataPoint() != null)
dataPointRT = rtm.getDataPoint(pointComponent.tgetDataPoint().getId());
ViewComponentState state = preparePointComponentState(pointComponent, update, user, dataPointRT, model, request);
if (!edit) {
if (pointComponent.isSettable()) {
if (view.isEditor(user) || view.isSetter(user))
setChange(pointComponent.tgetDataPoint(), state, dataPointRT, request, model);
}
if (pointComponent.tgetDataPoint() != null)
setChart(pointComponent.tgetDataPoint(), state, request, model);
}
if (add)
states.add(state);
model.clear();
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class InternalDataSourceRT method doPoll.
@Override
public void doPoll(long time) {
if (createsPoints) {
for (ValueMonitor<?> m : Common.MONITORED_VALUES.getMonitors()) {
if (createPointsPattern.matcher(m.getId()).matches() && !monitorMap.containsKey(m.getId()))
createMonitorPoint(m);
}
}
for (DataPointRT dataPoint : dataPoints) {
InternalPointLocatorRT locator = dataPoint.getPointLocator();
ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
if (m != null) {
if (m instanceof IntegerMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), time));
else if (m instanceof LongMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), time));
else if (m instanceof DoubleMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), time));
else if (m instanceof AtomicIntegerMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), time));
}
}
}
Aggregations