Search in sources :

Example 1 with Characteristic

use of org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic 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)

Example 2 with Characteristic

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

the class ModelTransformer method transform.

public Device transform() {
    this.factory = ModelFactoryImpl.init();
    this.device = this.factory.createDevice();
    this.device.setName(this.infomodel.getName());
    this.device.setInfomodel(this.infomodel);
    IMapped<InformationModel> map = this.context.getMappedElement(infomodel, "DeviceInfoProfile");
    if (map.hasAttribute("modelNumber")) {
        String modelNumber = map.getAttributeValue("modelNumber", "0");
        Service service = this.factory.createService();
        service.setName("DeviceInformation");
        service.setUuid("0000180a-0000-1000-8000-00805f9b34fb");
        Characteristic characteristic = this.factory.createCharacteristic();
        characteristic.setName("ModelNumber");
        characteristic.setUuid("00002a24-0000-1000-8000-00805f9b34fb");
        characteristic.setLength(modelNumber.length() / 2);
        StringBuffer mnBuf = new StringBuffer();
        mnBuf.append("{");
        for (int i = 0; i < modelNumber.length(); i += 2) {
            mnBuf.append("0x" + modelNumber.substring(i, i + 2));
            if (i < modelNumber.length() - 2) {
                mnBuf.append(", ");
            }
        }
        mnBuf.append("}");
        characteristic.setValue(mnBuf.toString());
        service.getCharacteristics().add(characteristic);
        this.device.getServices().add(service);
    }
    for (FunctionblockProperty property : infomodel.getProperties()) {
        transformFunctionblock(property.getType());
    }
    return this.device;
}
Also used : Characteristic(org.eclipse.vorto.codegen.ble.model.blegatt.Characteristic) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Service(org.eclipse.vorto.codegen.ble.model.blegatt.Service) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)

Aggregations

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