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);
}
}
}
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;
}
Aggregations