Search in sources :

Example 1 with Service

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

the class ModelTransformer method transformFunctionblock.

private void transformFunctionblock(FunctionblockModel fbm) {
    IMapped<FunctionblockModel> map = this.context.getMappedElement(fbm, "Service");
    if (map.hasAttribute("uuid")) {
        String uuid = map.getAttributeValue("uuid", "");
        Service service = null;
        for (Service s : this.device.getServices()) {
            if (s.getUuid().equals(uuid)) {
                service = s;
                break;
            }
        }
        if (service == null) {
            service = this.factory.createService();
            service.setUuid(uuid);
            if (map.hasAttribute("serviceName")) {
                service.setName(map.getAttributeValue("serviceName", ""));
            } else {
                service.setName(fbm.getName());
            }
            this.device.getServices().add(service);
        }
        service.getFunctionblocks().add(fbm);
        FunctionBlock fb = fbm.getFunctionblock();
        if (fb.getStatus() != null) {
            for (Property property : fb.getStatus().getProperties()) {
                transformProperty(service, property);
            }
        }
        if (fb.getConfiguration() != null) {
            for (Property property : fb.getConfiguration().getProperties()) {
                transformProperty(service, property);
            }
        }
        if (fb.getFault() != null) {
            for (Property property : fb.getFault().getProperties()) {
                transformProperty(service, property);
            }
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Service(org.eclipse.vorto.codegen.ble.model.blegatt.Service) 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) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Example 2 with Service

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

Service (org.eclipse.vorto.codegen.ble.model.blegatt.Service)2 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 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 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1