Search in sources :

Example 36 with DataPointRT

use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.

the class VMStatDataSourceRT method readParts.

private void readParts(String[] parts) {
    TranslatableMessage error = null;
    long time = System.currentTimeMillis();
    pointListChangeLock.readLock().lock();
    try {
        for (DataPointRT dp : dataPoints) {
            VMStatPointLocatorVO locator = ((VMStatPointLocatorRT) dp.getPointLocator()).getVo();
            Integer position = attributePositions.get(locator.getAttributeId());
            if (position == null) {
                if (error != null)
                    error = new TranslatableMessage("event.vmstat.attributeNotFound", locator.getConfigurationDescription());
            } else {
                try {
                    String data = parts[position];
                    Double value = new Double(data);
                    dp.updatePointValue(new PointValueTime(value, time));
                } catch (NumberFormatException e) {
                    log.error("Weird. We couldn't parse the value " + parts[position] + " into a double. attribute=" + locator.getAttributeId());
                } catch (ArrayIndexOutOfBoundsException e) {
                    log.error("Weird. We need element " + position + " but the vmstat data is only " + parts.length + " elements long. The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output.");
                    raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.vmstat.process", "The statistic " + Common.translate(VMStatPointLocatorVO.ATTRIBUTE_CODES.getKey(locator.getAttributeId())) + " is missing from the vmstat output."));
                }
            }
        }
    } finally {
        pointListChangeLock.readLock().unlock();
    }
    if (error == null)
        returnToNormal(PARSE_EXCEPTION_EVENT, time);
    else
        raiseEvent(PARSE_EXCEPTION_EVENT, time, true, error);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 37 with DataPointRT

use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.

the class SerialDataSourceRT method setPointValueImpl.

@Override
public void setPointValueImpl(DataPointRT dataPoint, PointValueTime valueTime, SetPointSource source) {
    // Are we connected?
    if (this.port == null && !connect()) {
        raiseEvent(POINT_WRITE_EXCEPTION_EVENT, Common.timer.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailedPortNotSetup"));
        return;
    }
    try {
        setPointValueImplTransport(dataPoint, valueTime);
        returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis());
    } catch (IOException e) {
        if (vo.getRetries() == 0)
            LOG.error("Failed setting serial point " + dataPoint.getVO().getExtendedName() + ": " + e.getMessage(), e);
        // Try and reset the connection
        Exception ex = e;
        int retries = vo.getRetries();
        while (retries > 0) {
            try {
                retries -= 1;
                if (this.port != null)
                    Common.serialPortManager.close(this.port);
                if (this.connect()) {
                    setPointValueImplTransport(dataPoint, valueTime);
                    returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis());
                    return;
                }
            } catch (Exception e2) {
                ex = e2;
            }
        }
        if (ex != null) {
            raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailed", e.getMessage()));
            LOG.error("Error re-connecting to serial port.", ex);
        }
    }
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) IOException(java.io.IOException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) IOException(java.io.IOException)

Example 38 with DataPointRT

use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.

the class SerialDataSourceRT method setPointValueImplTransport.

private void setPointValueImplTransport(DataPointRT dataPoint, PointValueTime valueTime) throws IOException {
    OutputStream os = this.port.getOutputStream();
    if (os == null)
        throw new IOException("Port is closed.");
    // Create Message from Message Start
    SerialPointLocatorRT pl = dataPoint.getPointLocator();
    byte[] data;
    if (this.vo.isHex()) {
        // Convert to Hex
        try {
            switch(dataPoint.getDataTypeId()) {
                case DataTypes.ALPHANUMERIC:
                    data = convertToHex(valueTime.getStringValue());
                    break;
                case DataTypes.BINARY:
                    if (valueTime.getBooleanValue())
                        data = convertToHex("00");
                    else
                        data = convertToHex("01");
                    break;
                case DataTypes.MULTISTATE:
                    String intValue = Integer.toString(valueTime.getIntegerValue());
                    if (intValue.length() % 2 != 0)
                        intValue = "0" + intValue;
                    data = convertToHex(intValue);
                    break;
                case DataTypes.NUMERIC:
                    String numValue = Integer.toString(valueTime.getIntegerValue());
                    if (numValue.length() % 2 != 0)
                        numValue = "0" + numValue;
                    data = convertToHex(numValue);
                    break;
                default:
                    throw new ShouldNeverHappenException("Unsupported data type" + dataPoint.getDataTypeId());
            }
            if (this.vo.isLogIO())
                this.ioLog.log(false, data);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.notHex"));
            return;
        }
    } else {
        // Pin the terminator on the end
        String messageTerminator = ((SerialDataSourceVO) this.getVo()).getMessageTerminator();
        // Do we need to or is it already on the end?
        String identifier = pl.getVo().getPointIdentifier();
        String fullMsg = identifier + valueTime.getStringValue();
        if (!fullMsg.endsWith(messageTerminator)) {
            fullMsg += messageTerminator;
        }
        // String output = newValue.getStringValue();
        data = fullMsg.getBytes();
        if (vo.isLogIO())
            this.ioLog.log("O: " + fullMsg);
    }
    for (byte b : data) {
        os.write(b);
    }
    os.flush();
}
Also used : SerialDataSourceVO(com.infiniteautomation.serial.vo.SerialDataSourceVO) OutputStream(java.io.OutputStream) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) IOException(java.io.IOException)

Example 39 with DataPointRT

use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.

the class BaseDwr method prepareBasePointState.

/**
 * Base method for preparing information in a state object and returning a
 * point value.
 *
 * @param componentId
 *            a unique id for the browser side component. Required for set
 *            point snippets.
 * @param state
 * @param point
 * @param status
 * @param model
 * @return
 */
protected static PointValueTime prepareBasePointState(String componentId, BasePointState state, DataPointVO pointVO, DataPointRT point, Map<String, Object> model) {
    model.clear();
    model.put("componentId", componentId);
    model.put("point", pointVO);
    model.put("pointRT", point);
    model.put(MODEL_ATTR_TRANSLATIONS, getTranslations());
    PointValueTime pointValue = null;
    if (point == null)
        model.put("disabled", "true");
    else {
        pointValue = point.getPointValue();
        if (pointValue != null)
            model.put("pointValue", pointValue);
    }
    return pointValue;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 40 with DataPointRT

use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.

the class DataPointDetailsDwr method getPointData.

public static PointDetailsState getPointData() {
    // Get the point from the user's session. It should have been set by the controller.
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    User user = Common.getUser(request);
    DataPointVO pointVO = user.getEditPoint();
    // Create the watch list state.
    Map<String, Object> model = new HashMap<String, Object>();
    // Get the data point status from the data image.
    DataPointRT pointRT = Common.runtimeManager.getDataPoint(pointVO.getId());
    PointDetailsState state = new PointDetailsState();
    state.setId(Integer.toString(pointVO.getId()));
    PointValueTime pointValue = prepareBasePointState(Integer.toString(pointVO.getId()), state, pointVO, pointRT, model);
    setPrettyText(request, state, pointVO, model, pointValue);
    setChange(pointVO, state, pointRT, request, model, user);
    setEvents(pointVO, user, model, pointEventsLimit);
    setMessages(state, request, "dataPointMessages.jsp", model);
    return state;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) RenderedPointValueTime(com.serotonin.m2m2.web.dwr.beans.RenderedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) PointDetailsState(com.serotonin.m2m2.web.dwr.beans.PointDetailsState)

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