Search in sources :

Example 1 with CharacteristicProperty

use of org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty in project vorto by eclipse.

the class ModelTransformer method transformProperty.

private void transformProperty(Service service, Property property) {
    IMapped<Property> map = this.context.getMappedElement(property, "source");
    if (map.hasAttribute("uuid")) {
        String uuid = map.getAttributeValue("uuid", "");
        Characteristic characteristic = null;
        for (Characteristic ch : service.getCharacteristics()) {
            if (ch.getUuid().equals(uuid)) {
                characteristic = ch;
                break;
            }
        }
        if (characteristic == null) {
            characteristic = this.factory.createCharacteristic();
            characteristic.setUuid(uuid);
            if (map.hasAttribute("name")) {
                characteristic.setName(map.getAttributeValue("name", ""));
            } else {
                characteristic.setName(((FunctionblockModel) (property.eContainer().eContainer().eContainer())).getName() + property.getName());
            }
            service.getCharacteristics().add(characteristic);
        }
        if (Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")) > characteristic.getLength()) {
            characteristic.setLength(Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")));
        }
        if (Utils.isReadable(property)) {
            characteristic.setIsReadable(true);
        }
        if (Utils.isWritable(property)) {
            characteristic.setIsWritable(true);
        }
        if (Utils.isEventable(property)) {
            characteristic.setIsEventable(true);
        }
        if (map.hasAttribute("length") && map.hasAttribute("offset") && map.hasAttribute("datatype")) {
            CharacteristicProperty cp = this.factory.createCharacteristicProperty();
            cp.setDatatype(map.getAttributeValue("datatype", ""));
            cp.setLength(Integer.parseInt(map.getAttributeValue("length", "0")));
            cp.setOffset(Integer.parseInt(map.getAttributeValue("offset", "0")));
            cp.setProperty(property);
            characteristic.getProperties().add(cp);
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) Characteristic(org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic) CharacteristicProperty(org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Aggregations

Characteristic (org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic)1 CharacteristicProperty (org.eclipse.vorto.codegen.ble.model.blegatt.CharacteristicProperty)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)1