Search in sources :

Example 26 with DataType

use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.

the class RhinoScriptTestData method getPointValuesBetween.

public static List<PointValueTime> getPointValuesBetween(DataType dataType, int id, long from, long to) {
    switch(dataType) {
        case ALPHANUMERIC:
        case BINARY:
        case MULTISTATE:
        default:
            throw new ShouldNeverHappenException("Unimplemented");
        case NUMERIC:
            List<PointValueTime> values = new ArrayList<PointValueTime>();
            List<PointValueTime> pvts = numericPvts.get(id);
            for (PointValueTime pvt : pvts) {
                if ((pvt.getTime() > from) || (pvt.getTime() <= to))
                    values.add(pvt);
            }
            return values;
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Example 27 with DataType

use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.

the class AbstractPointLocatorVO method readDataType.

protected DataType readDataType(JsonObject json) throws JsonException {
    String text = json.getString("dataType");
    if (text == null) {
        throw new TranslatableJsonException("emport.error.missing", "dataType", DataType.formatNames());
    }
    DataType dataType;
    try {
        dataType = DataType.valueOf(text);
    } catch (IllegalArgumentException e) {
        throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataType.formatNames());
    }
    return dataType;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) DataType(com.serotonin.m2m2.DataType)

Example 28 with DataType

use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.

the class BaseTextRenderer method getImplementation.

public static List<ImplDefinition> getImplementation(DataType dataType) {
    ensureDefinitions();
    List<ImplDefinition> impls = new ArrayList<ImplDefinition>(definitions.size());
    for (ImplDefinition def : definitions) {
        if (def.supports(dataType))
            impls.add(def);
    }
    return impls;
}
Also used : ImplDefinition(com.serotonin.m2m2.view.ImplDefinition) ArrayList(java.util.ArrayList)

Example 29 with DataType

use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.

the class PointValueTimeDeserializer method deserialize.

@Override
public PointValueTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    ObjectCodec codec = jsonParser.getCodec();
    JsonNode node = codec.readTree(jsonParser);
    JsonNode dataTypeNode = node.get("dataType");
    if (dataTypeNode == null) {
        throw JsonMappingException.from(jsonParser, "Missing dataType");
    }
    JsonNode valueNode = node.get("value");
    if (valueNode == null) {
        throw JsonMappingException.from(jsonParser, "Missing value");
    }
    JsonNode timestampNode = node.get("timestamp");
    if (timestampNode == null) {
        throw JsonMappingException.from(jsonParser, "Missing timestamp");
    }
    long timestamp = timestampNode.asLong();
    String dataTypeStr = dataTypeNode.asText();
    DataType dataType = DataType.fromName(dataTypeStr);
    if (dataType == null) {
        throw JsonMappingException.from(jsonParser, "Unknown dataType: " + dataTypeStr);
    }
    DataValue dataValue;
    switch(dataType) {
        case ALPHANUMERIC:
            dataValue = new AlphanumericValue(valueNode.asText());
            break;
        case BINARY:
            dataValue = new BinaryValue(valueNode.asBoolean());
            break;
        case MULTISTATE:
            dataValue = new MultistateValue(valueNode.asInt());
            break;
        case NUMERIC:
            dataValue = new NumericValue(valueNode.asDouble());
            break;
        default:
            throw JsonMappingException.from(jsonParser, "Unsupported dataType " + dataType);
    }
    JsonNode annotationNode = node.get("serializedAnnotation");
    if (annotationNode != null && !annotationNode.isNull()) {
        try {
            return new AnnotatedPointValueTime(dataValue, timestamp, TranslatableMessage.deserialize(annotationNode.asText()));
        } catch (TranslatableMessageParseException e) {
            throw JsonMappingException.from(jsonParser, "Can't deserialize annotation", e);
        }
    }
    return new PointValueTime(dataValue, timestamp);
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) JsonNode(com.fasterxml.jackson.databind.JsonNode) TranslatableMessageParseException(com.serotonin.m2m2.i18n.TranslatableMessageParseException) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataType(com.serotonin.m2m2.DataType) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 30 with DataType

use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.

the class PointValueTimeSerializer method serialize.

@Override
public void serialize(PointValueTime pointValueTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();
    DataValue value = pointValueTime.getValue();
    switch(value.getDataType()) {
        case ALPHANUMERIC:
            jsonGenerator.writeStringField("dataType", "ALPHANUMERIC");
            jsonGenerator.writeStringField("value", value.getStringValue());
            break;
        case BINARY:
            jsonGenerator.writeStringField("dataType", "BINARY");
            jsonGenerator.writeBooleanField("value", value.getBooleanValue());
            break;
        case MULTISTATE:
            jsonGenerator.writeStringField("dataType", "MULTISTATE");
            jsonGenerator.writeNumberField("value", value.getIntegerValue());
            break;
        case NUMERIC:
            jsonGenerator.writeStringField("dataType", "NUMERIC");
            jsonGenerator.writeNumberField("value", value.getDoubleValue());
            break;
    }
    jsonGenerator.writeNumberField("timestamp", pointValueTime.getTime());
    if (pointValueTime instanceof IAnnotated) {
        jsonGenerator.writeStringField("serializedAnnotation", ((IAnnotated) pointValueTime).getSourceMessage().serialize());
    }
    jsonGenerator.writeEndObject();
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IAnnotated(com.serotonin.m2m2.rt.dataImage.IAnnotated)

Aggregations

ArrayList (java.util.ArrayList)27 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)23 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)17 DataType (com.serotonin.m2m2.DataType)14 HashMap (java.util.HashMap)14 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)13 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)11 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)10 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)10 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)10 IOException (java.io.IOException)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)9 DataImplementation (org.osate.aadl2.DataImplementation)9 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8 DataType (net.opengis.swe.v20.DataType)8 File (java.io.File)7 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6