Search in sources :

Example 16 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel in project vorto by eclipse.

the class BleGattDeviceBuilder method build.

public BleGattDevice build() {
    this.device = new BleGattDevice();
    for (ModelProperty fbprop : infomodel.getFunctionblocks()) {
        FunctionblockModel fb = mappingSpec.getFunctionBlock(fbprop.getName());
        if ("blegatt".equals(fb.getTargetPlatformKey())) {
            BleGattService service = new BleGattService();
            Optional<Stereotype> stereotype = fb.getStereotype("source");
            if (stereotype.isPresent()) {
                String uuid = stereotype.get().getAttributes().get("uuid");
                if (uuid != null) {
                    service.setUuid(UUID.fromString(uuid));
                }
            }
            for (ModelProperty prop : fb.getConfigurationProperties()) {
                BleGattCharacteristic ch = buildCharacteristic(prop);
                if (ch.getUuid() != null) {
                    service.addCharacteristics(ch);
                }
            }
            for (ModelProperty prop : fb.getStatusProperties()) {
                BleGattCharacteristic ch = buildCharacteristic(prop);
                if (ch.getUuid() != null) {
                    service.addCharacteristics(ch);
                }
            }
            device.addService(service);
        }
    }
    return device;
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype)

Example 17 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel in project vorto by eclipse.

the class SpecGattConverter method createFBSpec.

@Override
protected void createFBSpec() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("sensor_value");
    digitalInputStateProperty.setType(PrimitiveType.STRING);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithXpath("button:convertSensorValue(conversion:byteArrayToInt(characteristics[@uuid='23-D1-13-EF-5F-78-23-15-DE-EF-12-12-0D-F0-00-00']/data, 3, 0, 0, 3))"));
    buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
    addFunctionblockProperty("button", buttonModel);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Example 18 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel in project vorto by eclipse.

the class SpecWithByteArrayConverter method createFBSpec.

@Override
protected void createFBSpec() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("sensor_value");
    digitalInputStateProperty.setType(PrimitiveType.STRING);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithXpath("button:convertSensorValue(conversion:byteArrayToInt(/data, 3, 0, 0, 3))"));
    buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
    addFunctionblockProperty("button", buttonModel);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Example 19 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel in project vorto by eclipse.

the class SpecWithCondition method createFBSpec.

@Override
protected void createFBSpec() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("sensor_value");
    digitalInputStateProperty.setType(PrimitiveType.FLOAT);
    ModelProperty digitalInputStateProperty2 = new ModelProperty();
    digitalInputStateProperty2.setMandatory(true);
    digitalInputStateProperty2.setName("sensor_value2");
    digitalInputStateProperty2.setType(PrimitiveType.FLOAT);
    digitalInputStateProperty.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty.addStereotype(Stereotype.createWithConditionalXpath("count == 0", "/count"));
    digitalInputStateProperty2.setTargetPlatformKey("iotbutton");
    digitalInputStateProperty2.addStereotype(Stereotype.createWithConditionalXpath("count > 1", "/count"));
    buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty, digitalInputStateProperty2 }));
    addFunctionblockProperty("button", buttonModel);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Example 20 with FunctionblockModel

use of org.eclipse.vorto.repository.api.content.FunctionblockModel in project vorto by eclipse.

the class SpecWithConditionedRules method createFBSpec.

@Override
protected void createFBSpec() {
    FunctionblockModel doorState = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty = new ModelProperty();
    digitalInputStateProperty.setMandatory(true);
    digitalInputStateProperty.setName("sensor_value");
    digitalInputStateProperty.setType(PrimitiveType.STRING);
    digitalInputStateProperty.setTargetPlatformKey("homeconnect");
    digitalInputStateProperty.addStereotype(Stereotype.createWithConditionalXpath("data.key == 'DoorState'", "data/value"));
    doorState.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
    FunctionblockModel operationState = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb.PushButton:1.0.0"), ModelType.Functionblock);
    ModelProperty digitalInputStateProperty1 = new ModelProperty();
    digitalInputStateProperty1.setMandatory(true);
    digitalInputStateProperty1.setName("sensor_value");
    digitalInputStateProperty1.setType(PrimitiveType.STRING);
    digitalInputStateProperty1.setTargetPlatformKey("homeconnect");
    digitalInputStateProperty1.addStereotype(Stereotype.createWithConditionalXpath("data.key == 'OperationState'", "data/value"));
    operationState.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty1 }));
    addFunctionblockProperty("doorState", doorState);
    addFunctionblockProperty("operationState", operationState);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty)

Aggregations

FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)21 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)18 Test (org.junit.Test)4 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)2 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)2 ArrayList (java.util.ArrayList)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 ModelId (org.eclipse.vorto.repository.api.ModelId)1 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)1 JavascriptFunctions (org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)1 DefaultMappingSpecification (org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1