Search in sources :

Example 26 with DataPointRT

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;
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DateTime(org.joda.time.DateTime)

Example 27 with DataPointRT

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()));
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MatchCallback(com.infiniteautomation.mango.regex.MatchCallback) IOException(java.io.IOException) AsciiFilePointLocatorVO(com.infiniteautomation.asciifile.vo.AsciiFilePointLocatorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) BufferedReader(java.io.BufferedReader) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) FileReader(java.io.FileReader) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ParseException(java.text.ParseException)

Example 28 with DataPointRT

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;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 29 with DataPointRT

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();
    }
}
Also used : PointComponent(com.serotonin.m2m2.gviews.component.PointComponent) SimplePointComponent(com.serotonin.m2m2.gviews.component.SimplePointComponent) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Example 30 with DataPointRT

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));
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) LongMonitor(com.infiniteautomation.mango.monitor.LongMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) DoubleMonitor(com.infiniteautomation.mango.monitor.DoubleMonitor)

Aggregations

DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)47 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)28 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)23 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)19 HashMap (java.util.HashMap)12 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)11 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)9 IOException (java.io.IOException)8 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)7 ArrayList (java.util.ArrayList)7 ScriptException (javax.script.ScriptException)7 ScriptLog (com.serotonin.m2m2.rt.script.ScriptLog)6 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)5 SerialPortException (com.infiniteautomation.mango.io.serial.SerialPortException)4 SerialPointLocatorVO (com.infiniteautomation.serial.vo.SerialPointLocatorVO)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 DataPointListener (com.serotonin.m2m2.rt.dataImage.DataPointListener)4 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)4 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4