diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.classpath new file mode 100644 index 00000000000..7f457fa4138 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.project new file mode 100644 index 00000000000..196e42d373a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.binding.bluetooth.bluegiga + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/i18n/ble.bluegiga_xx_XX.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/i18n/ble.bluegiga_xx_XX.properties new file mode 100644 index 00000000000..204a65a57b9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/i18n/ble.bluegiga_xx_XX.properties @@ -0,0 +1,13 @@ +# FIXME: please substitute the xx_XX with a proper locale, ie. de_DE +# FIXME: please do not add the file to the repo if you add or change no content +# binding +binding.ble.bluegiga.name = +binding.ble.bluegiga.description = + +# thing types +thing-type.ble.bluegiga.sample.label = +thing-type.ble.bluegiga.sample.description = + +# channel types +channel-type.ble.bluegiga.sample-channel.label = +channel-type.ble.bluegiga.sample-channel.description = \ No newline at end of file diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/thing/bluegiga.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/thing/bluegiga.xml new file mode 100644 index 00000000000..4b5b950b02f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/ESH-INF/thing/bluegiga.xml @@ -0,0 +1,25 @@ + + + + + + Serial interface to the BlueGiga dongle + + + + + serial-port + Serial Port + + + + Whether this adapter actively participates in Bluetooth device discovery + true + true + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..5d51b453915 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: BlueGiga Bluetooth Adapter +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.bluegiga +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: gnu.io, + org.eclipse.jdt.annotation;resolution:=optional, + org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.bluegiga, + org.eclipse.smarthome.binding.bluetooth.bluegiga.handler, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.type, + org.eclipse.smarthome.core.types, + org.osgi.framework, + org.slf4j +Service-Component: OSGI-INF/*.xml +Export-Package: org.eclipse.smarthome.binding.bluetooth.bluegiga, + org.eclipse.smarthome.binding.bluetooth.bluegiga.handler +Bundle-ActivationPolicy: lazy diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/NOTICE new file mode 100644 index 00000000000..b8675cd02e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/NOTICE @@ -0,0 +1,19 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/OSGI-INF/.gitignore b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/OSGI-INF/.gitignore new file mode 100644 index 00000000000..b878e882aca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/README.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/README.md new file mode 100644 index 00000000000..c5e10cab543 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/README.md @@ -0,0 +1,52 @@ +# Ble.BlueGiga Binding + +_Give some details about what this binding is meant for - a protocol, system, specific device._ + +_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._ + +## Supported Things + +_Please describe the different supported things / devices within this section._ +_Which different types are supported, which models were tested etc.?_ +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Discovery + +_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._ + +## Binding Configuration + +_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_ + +``` +# Configuration for the Philips Hue Binding +# +# Default secret key for the pairing of the Philips Hue Bridge. +# It has to be between 10-40 (alphanumeric) characters +# This may be changed by the user for security reasons. +secret=EclipseSmartHome +``` + +_Note that it is planned to generate some part of this based on the information that is available within ```ESH-INF/binding``` of your binding._ + +_If your binding does not offer any generic configurations, you can remove this section completely._ + +## Thing Configuration + +_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Channels + +_Here you should provide information about available channel types, what their meaning is and how they can be used._ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Full Example + +_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._ + +## Any custom content here! + +_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/build.properties new file mode 100644 index 00000000000..d3ebb210cc8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/build.properties @@ -0,0 +1,7 @@ +source..=src/main/java/ +output..=target/classes +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + NOTICE diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/cfg/ble.bluegiga.cfg b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/cfg/ble.bluegiga.cfg new file mode 100644 index 00000000000..8ccc12ede7c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/cfg/ble.bluegiga.cfg @@ -0,0 +1 @@ +# Ble.BlueGiga Binding Default Configuration diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/pom.xml new file mode 100644 index 00000000000..f5e7912eb97 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth.bluegiga + + Eclipse SmartHome BlueGiga Bluetooth Adapter + eclipse-plugin + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaAdapterConstants.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaAdapterConstants.java new file mode 100644 index 00000000000..b00c724580d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaAdapterConstants.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.core.thing.ThingTypeUID; + +/** + * The {@link BlueGigaAdapterConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Chris Jackson - Initial contribution + */ +public class BlueGigaAdapterConstants { + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_BLUEGIGA = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, + "bluegiga"); + + public static final String CONFIGURATION_PORT = "port"; + public static final String PROPERTY_LINKLAYER = "linklayer"; + public static final String PROPERTY_PROTOCOL = "protocol"; + public static final String PROPERTY_DISCOVERY = "discovery"; +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java new file mode 100644 index 00000000000..d07bd1b7a8b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java @@ -0,0 +1,434 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothAddress; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCompletionStatus; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.BluetoothService; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.handler.BlueGigaBridgeHandler; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaEventListener; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeValueEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationFoundEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaGroupFoundEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaProcedureCompletedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir.EirDataType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir.EirPacket; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ScanResponseType; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification.BluetoothBeaconType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * An extended {@link BluetoothDevice} class to handle BlueGiga specific information + * + * @author Chris Jackson - Initial contribution + */ +public class BlueGigaBluetoothDevice extends BluetoothDevice implements BlueGigaEventListener { + private final Logger logger = LoggerFactory.getLogger(BlueGigaBluetoothDevice.class); + + // BlueGiga needs to know the address type when connecting + private BluetoothAddressType addressType; + + // Used to correlate the scans so we get as much information as possible before calling the device "discovered" + private final Set scanResponses = new HashSet(); + + // The dongle handler + private final BlueGigaBridgeHandler bgHandler; + + // An enum to use in the state machine for interacting with the device + private enum BlueGigaProcedure { + NONE, + GET_SERVICES, + GET_CHARACTERISTICS, + CHARACTERISTIC_READ, + CHARACTERISTIC_WRITE; + } + + private BlueGigaProcedure procedureProgress = BlueGigaProcedure.NONE; + + // Somewhere to remember what characteristic we're working on + private BluetoothCharacteristic procedureCharacteristic = null; + + // The connection handle if the device is connected + private int connection = -1; + + /** + * Creates a new {@link BlueGigaBluetoothDevice} which extends {@link BluetoothDevice} for the BlueGiga + * implementation + * + * @param bgHandler the {@link BlueGigaBridgeHandler} that provides the link to the dongle + * @param address the {@link BluetoothAddress} for this device + * @param addressType the {@link BluetoothAddressType} of this device + */ + public BlueGigaBluetoothDevice(BlueGigaBridgeHandler bgHandler, BluetoothAddress address, + BluetoothAddressType addressType) { + super(bgHandler, address); + + logger.debug("Creating new BlueGiga device {}", address); + + this.bgHandler = bgHandler; + this.addressType = addressType; + + bgHandler.addEventListener(this); + } + + @Override + public boolean connect() { + if (connection != -1) { + // We're already connected + return false; + } + + if (bgHandler.bgConnect(address, addressType)) { + connectionState = ConnectionState.CONNECTING; + return true; + } else { + connectionState = ConnectionState.DISCONNECTED; + return false; + } + } + + @Override + public boolean disconnect() { + if (connection == -1) { + // We're already disconnected + return false; + } + + return bgHandler.bgDisconnect(connection); + } + + @Override + public boolean discoverServices() { + // Start by requesting all the services + procedureProgress = BlueGigaProcedure.GET_SERVICES; + return bgHandler.bgFindPrimaryServices(connection); + } + + @Override + public boolean readCharacteristic(BluetoothCharacteristic characteristic) { + if (characteristic == null || characteristic.getHandle() == 0) { + return false; + } + + if (!bgHandler.bgReadCharacteristic(connection, characteristic.getHandle())) { + return false; + } + + if (procedureProgress != BlueGigaProcedure.NONE) { + return false; + } + + procedureProgress = BlueGigaProcedure.CHARACTERISTIC_READ; + procedureCharacteristic = characteristic; + + return true; + } + + @Override + public boolean writeCharacteristic(BluetoothCharacteristic characteristic) { + if (characteristic == null || characteristic.getHandle() == 0) { + return false; + } + + if (procedureProgress != BlueGigaProcedure.NONE) { + return false; + } + + if (!bgHandler.bgWriteCharacteristic(connection, characteristic.getHandle(), characteristic.getValue())) { + return false; + } + + procedureProgress = BlueGigaProcedure.CHARACTERISTIC_WRITE; + procedureCharacteristic = characteristic; + + return true; + } + + @Override + public void bluegigaEventReceived(BlueGigaResponse event) { + if (event instanceof BlueGigaScanResponseEvent) { + BlueGigaScanResponseEvent scanEvent = (BlueGigaScanResponseEvent) event; + + // Check if this is addressed to this device + if (!address.equals(new BluetoothAddress(scanEvent.getSender()))) { + return; + } + + // Set device properties + rssi = scanEvent.getRssi(); + addressType = scanEvent.getAddressType(); + + byte[] manufacturerData = null; + + // If the packet contains data, then process it and add anything relevant to the device... + if (scanEvent.getData() != null) { + EirPacket eir = new EirPacket(scanEvent.getData()); + for (EirDataType record : eir.getRecords().keySet()) { + switch (record) { + case EIR_FLAGS: + break; + case EIR_MANUFACTURER_SPECIFIC: + manufacturerData = (byte[]) eir.getRecord(EirDataType.EIR_MANUFACTURER_SPECIFIC); + if (manufacturerData.length > 2) { + int id = manufacturerData[0] + (manufacturerData[1] << 8); + manufacturer = id; + } + break; + case EIR_NAME_LONG: + case EIR_NAME_SHORT: + name = (String) eir.getRecord(record); + break; + case EIR_SLAVEINTERVALRANGE: + break; + case EIR_SVC_DATA_UUID128: + break; + case EIR_SVC_DATA_UUID16: + break; + case EIR_SVC_DATA_UUID32: + break; + case EIR_SVC_UUID128_INCOMPLETE: + case EIR_SVC_UUID16_COMPLETE: + case EIR_SVC_UUID16_INCOMPLETE: + case EIR_SVC_UUID32_COMPLETE: + case EIR_SVC_UUID32_INCOMPLETE: + case EIR_SVC_UUID128_COMPLETE: + // addServices((List) eir.getRecord(record)); + break; + case EIR_TXPOWER: + txPower = (int) eir.getRecord(EirDataType.EIR_TXPOWER); + break; + default: + break; + } + } + } + + if (connectionState == ConnectionState.DISCOVERING) { + // We want to wait for an advertisement and a scan response before we call this discovered. + // The intention is to gather a reasonable amount of data about the device given devices send + // different data in different packets... + // Note that this is possible a bit arbitrary and may be refined later. + scanResponses.add(scanEvent.getPacketType()); + + if ((scanResponses.contains(ScanResponseType.CONNECTABLE_ADVERTISEMENT) + || scanResponses.contains(ScanResponseType.DISCOVERABLE_ADVERTISEMENT) + || scanResponses.contains(ScanResponseType.NON_CONNECTABLE_ADVERTISEMENT)) + && scanResponses.contains(ScanResponseType.SCAN_RESPONSE)) { + // Set our state to disconnected + connectionState = ConnectionState.DISCONNECTED; + connection = -1; + + // But notify listeners that the state is now DISCOVERED + notifyListeners(BluetoothEventType.CONNECTION_STATE, + new BluetoothConnectionStatusNotification(ConnectionState.DISCOVERED)); + + // Notify the bridge - for inbox notifications + bgHandler.deviceDiscovered(this); + } + } + + // Notify listeners of all scan records - for RSSI, beacon processing (etc) + BluetoothScanNotification scanNotification = new BluetoothScanNotification(); + scanNotification.setRssi(scanEvent.getRssi()); + + switch (scanEvent.getPacketType()) { + case CONNECTABLE_ADVERTISEMENT: + case DISCOVERABLE_ADVERTISEMENT: + case NON_CONNECTABLE_ADVERTISEMENT: + scanNotification.setBeaconType(BluetoothBeaconType.BEACON_ADVERTISEMENT); + break; + case SCAN_RESPONSE: + scanNotification.setBeaconType(BluetoothBeaconType.BEACON_SCANRESPONSE); + break; + default: + break; + } + + if (manufacturerData != null) { + + scanNotification.setManufacturerData(manufacturerData); + } + + notifyListeners(BluetoothEventType.SCAN_RECORD, scanNotification); + + return; + } + + if (event instanceof BlueGigaGroupFoundEvent) { + // A Service has been discovered + BlueGigaGroupFoundEvent serviceEvent = (BlueGigaGroupFoundEvent) event; + + // If this is not our connection handle then ignore. + if (connection != serviceEvent.getConnection()) { + return; + } + + logger.trace("BlueGiga Group: {} svcs={}", this, supportedServices); + + BluetoothService service = new BluetoothService(serviceEvent.getUuid(), true, serviceEvent.getStart(), + serviceEvent.getEnd()); + addService(service); + + return; + } + + if (event instanceof BlueGigaFindInformationFoundEvent) { + // A Characteristic has been discovered + BlueGigaFindInformationFoundEvent infoEvent = (BlueGigaFindInformationFoundEvent) event; + + // If this is not our connection handle then ignore. + if (connection != infoEvent.getConnection()) { + return; + } + + logger.trace("BlueGiga FindInfo: {} svcs={}", this, supportedServices); + + BluetoothCharacteristic characteristic = new BluetoothCharacteristic(infoEvent.getUuid(), + infoEvent.getChrHandle()); + + BluetoothService service = getServiceByHandle(characteristic.getHandle()); + if (service == null) { + logger.debug("BlueGiga: Unable to find service for handle {}", characteristic.getHandle()); + return; + } + characteristic.setService(service); + service.addCharacteristic(characteristic); + + return; + } + + if (event instanceof BlueGigaProcedureCompletedEvent) { + BlueGigaProcedureCompletedEvent completedEvent = (BlueGigaProcedureCompletedEvent) event; + + // If this is not our connection handle then ignore. + if (connection != completedEvent.getConnection()) { + return; + } + + if (procedureProgress == null) { + logger.debug("BlueGiga procedure completed but procedure is null with connection {}, address {}", + connection, address); + return; + } + + // The current procedure is now complete - move on... + switch (procedureProgress) { + case GET_SERVICES: + // We've downloaded all services, now get the characteristics + procedureProgress = BlueGigaProcedure.GET_CHARACTERISTICS; + bgHandler.bgFindCharacteristics(connection); + break; + case GET_CHARACTERISTICS: + // We've downloaded all characteristics + procedureProgress = BlueGigaProcedure.NONE; + notifyListeners(BluetoothEventType.SERVICES_DISCOVERED); + break; + case CHARACTERISTIC_READ: + // The read failed + notifyListeners(BluetoothEventType.CHARACTERISTIC_READ_COMPLETE, procedureCharacteristic, + BluetoothCompletionStatus.ERROR); + procedureProgress = BlueGigaProcedure.NONE; + procedureCharacteristic = null; + break; + case CHARACTERISTIC_WRITE: + // The write completed - failure or success + BluetoothCompletionStatus result = completedEvent.getResult() == BgApiResponse.SUCCESS + ? BluetoothCompletionStatus.SUCCESS + : BluetoothCompletionStatus.ERROR; + notifyListeners(BluetoothEventType.CHARACTERISTIC_WRITE_COMPLETE, procedureCharacteristic, result); + procedureProgress = BlueGigaProcedure.NONE; + procedureCharacteristic = null; + break; + default: + break; + } + + return; + } + + if (event instanceof BlueGigaConnectionStatusEvent) { + BlueGigaConnectionStatusEvent connectionEvent = (BlueGigaConnectionStatusEvent) event; + + // Check if this is addressed to this device + if (!address.equals(new BluetoothAddress(connectionEvent.getAddress()))) { + return; + } + + // If we're connected, then remember the connection handle + if (connectionEvent.getFlags().contains(ConnectionStatusFlag.CONNECTION_CONNECTED)) { + connectionState = ConnectionState.CONNECTED; + connection = connectionEvent.getConnection(); + } + + if (connectionEvent.getFlags().contains(ConnectionStatusFlag.CONNECTION_CONNECTED)) { + notifyListeners(BluetoothEventType.CONNECTION_STATE, + new BluetoothConnectionStatusNotification(connectionState)); + } + + return; + } + + if (event instanceof BlueGigaDisconnectedEvent) { + BlueGigaDisconnectedEvent disconnectedEvent = (BlueGigaDisconnectedEvent) event; + + // If this is not our connection handle then ignore. + if (connection != disconnectedEvent.getConnection()) { + return; + } + + connectionState = ConnectionState.DISCONNECTED; + connection = -1; + notifyListeners(BluetoothEventType.CONNECTION_STATE, + new BluetoothConnectionStatusNotification(connectionState)); + + return; + } + + if (event instanceof BlueGigaAttributeValueEvent) { + // A read request has completed - update the characteristic + BlueGigaAttributeValueEvent valueEvent = (BlueGigaAttributeValueEvent) event; + + BluetoothCharacteristic characteristic = getCharacteristicByHandle(valueEvent.getAttHandle()); + if (characteristic == null) { + logger.debug("BlueGiga didn't find characteristic for event {}", event); + } else { + // If this is the characteristic we were reading, then send a read completion + if (procedureProgress == BlueGigaProcedure.CHARACTERISTIC_READ && procedureCharacteristic != null + && procedureCharacteristic.getHandle() == valueEvent.getAttHandle()) { + procedureProgress = BlueGigaProcedure.NONE; + procedureCharacteristic = null; + notifyListeners(BluetoothEventType.CHARACTERISTIC_READ_COMPLETE, characteristic, + BluetoothCompletionStatus.SUCCESS); + } + + // Notify the user of the updated value + notifyListeners(BluetoothEventType.CHARACTERISTIC_UPDATED, procedureCharacteristic); + } + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java new file mode 100644 index 00000000000..ff4aac2e5a5 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java @@ -0,0 +1,612 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.handler; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; + +import org.eclipse.jdt.annotation.DefaultLocation; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothAdapter; +import org.eclipse.smarthome.binding.bluetooth.BluetoothAddress; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDeviceListener; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDiscoveryListener; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.BlueGigaAdapterConstants; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.BlueGigaBluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaEventListener; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaHandlerListener; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaSerialHandler; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaDiscoverCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetScanParametersCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode; +import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.ThingStatusDetail; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler; +import org.eclipse.smarthome.core.types.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import gnu.io.CommPort; +import gnu.io.CommPortIdentifier; +import gnu.io.NoSuchPortException; +import gnu.io.PortInUseException; +import gnu.io.SerialPort; +import gnu.io.UnsupportedCommOperationException; + +/** + * The {@link BlueGigaBridgeHandler} is responsible for interfacing to the BlueGiga Bluetooth adapter. + * It provides a private interface for {@link BlueGigaBluetoothDevice}s to access the dongle and provides top + * level adaptor functionality for scanning and arbitration. + *

+ * The handler provides the serial interface to the dongle via the BlueGiga BG-API library. + *

+ * In the BlueGiga dongle, we leave scanning enabled most of the time. Normally, it's just passive scanning, and active + * scanning is enabled when we want to include new devices. Passive scanning is enough for us to receive beacons etc + * that are transmitted periodically, and active scanning will get more information which may be useful when we are + * including new devices. + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Made handler implement BlueGigaHandlerListener + */ +@NonNullByDefault({ DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.ARRAY_CONTENTS, + DefaultLocation.TYPE_ARGUMENT, DefaultLocation.TYPE_BOUND, DefaultLocation.TYPE_PARAMETER }) +public class BlueGigaBridgeHandler extends BaseBridgeHandler + implements BluetoothAdapter, BlueGigaEventListener, BlueGigaHandlerListener { + + private final Logger logger = LoggerFactory.getLogger(BlueGigaBridgeHandler.class); + + // The serial port. + private SerialPort serialPort; + + // The serial port input stream. + private InputStream inputStream; + + // The serial port output stream. + private OutputStream outputStream; + + // The BlueGiga API handler + private BlueGigaSerialHandler bgHandler; + + // The maximum number of connections this interface supports + private int maxConnections = 0; + + private final int passiveScanInterval = 0x40; + private final int passiveScanWindow = 0x08; + + private final int activeScanInterval = 0x40; + private final int activeScanWindow = 0x20; + + // Our BT address + private BluetoothAddress address; + + // internal flag for the discovery configuration + private boolean discoveryActive = true; + + // Map of Bluetooth devices known to this bridge. + // This is all devices we have heard on the network - not just things bound to the bridge + private final Map devices = new ConcurrentHashMap<>(); + + // Map of open connections + private final Map connections = new ConcurrentHashMap<>(); + + // Set of discovery listeners + protected final Set discoveryListeners = new CopyOnWriteArraySet<>(); + + // List of device listeners + protected final ConcurrentHashMap deviceListeners = new ConcurrentHashMap<>(); + + public BlueGigaBridgeHandler(Bridge bridge) { + super(bridge); + } + + @Override + public ThingUID getUID() { + // being a BluetoothAdapter, we use the UID of our bridge + return getThing().getUID(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + // No commands supported for the bridge + } + + @Override + public void initialize() { + Object discovery = getConfig().get(BlueGigaAdapterConstants.PROPERTY_DISCOVERY); + if (discovery != null && discovery.toString().equalsIgnoreCase(Boolean.FALSE.toString())) { + discoveryActive = false; + logger.debug("Deactivated discovery participation."); + } + + final String portId = (String) getConfig().get(BlueGigaAdapterConstants.CONFIGURATION_PORT); + + if (portId == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Serial port must be configured!"); + return; + } + if (openSerialPort(portId, 115200)) { + bgHandler = new BlueGigaSerialHandler(inputStream, outputStream); + // Create and send the reset command to the dongle + bgHandler.addEventListener(this); + bgHandler.addHandlerListener(this); + + updateStatus(ThingStatus.UNKNOWN); + + scheduler.submit(() -> { + // Stop any procedures that are running + bgStopProcedure(); + + // Close all transactions + BlueGigaCommand command; // = new BlueGigaResetCommand(); + command = new BlueGigaGetConnectionsCommand(); + BlueGigaGetConnectionsResponse connectionsResponse = (BlueGigaGetConnectionsResponse) bgHandler + .sendTransaction(command); + if (connectionsResponse != null) { + maxConnections = connectionsResponse.getMaxconn(); + } + + // Close all connections so we start from a known position + for (int connection = 0; connection < maxConnections; connection++) { + bgDisconnect(connection); + } + + // Get our Bluetooth address + command = new BlueGigaAddressGetCommand(); + BlueGigaAddressGetResponse addressResponse = (BlueGigaAddressGetResponse) bgHandler + .sendTransaction(command); + if (addressResponse != null) { + address = new BluetoothAddress(addressResponse.getAddress()); + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE); + } + + command = new BlueGigaGetInfoCommand(); + BlueGigaGetInfoResponse infoResponse = (BlueGigaGetInfoResponse) bgHandler.sendTransaction(command); + + // Set mode to non-discoverable etc. + // Not doing this will cause connection failures later + bgSetMode(); + + // Start passive scan + bgStartScanning(false, passiveScanInterval, passiveScanWindow); + + Map properties = editProperties(); + properties.put(BluetoothBindingConstants.PROPERTY_MAXCONNECTIONS, Integer.toString(maxConnections)); + properties.put(Thing.PROPERTY_FIRMWARE_VERSION, + String.format("%d.%d", infoResponse.getMajor(), infoResponse.getMinor())); + properties.put(Thing.PROPERTY_HARDWARE_VERSION, Integer.toString(infoResponse.getHardware())); + properties.put(BlueGigaAdapterConstants.PROPERTY_PROTOCOL, + Integer.toString(infoResponse.getProtocolVersion())); + properties.put(BlueGigaAdapterConstants.PROPERTY_LINKLAYER, + Integer.toString(infoResponse.getLlVersion())); + updateProperties(properties); + }); + } + } + + @Override + public void dispose() { + if (bgHandler != null) { + bgHandler.removeEventListener(this); + bgHandler.removeHandlerListener(this); + bgHandler.close(); + } + closeSerialPort(); + } + + private boolean openSerialPort(final String serialPortName, int baudRate) { + logger.debug("Connecting to serial port '{}'", serialPortName); + try { + CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName); + CommPort commPort = portIdentifier.open("org.openhab.binding.zigbee", 2000); + serialPort = (gnu.io.SerialPort) commPort; + serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, + gnu.io.SerialPort.PARITY_NONE); + serialPort.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_RTSCTS_OUT); + + ((CommPort) serialPort).enableReceiveThreshold(1); + serialPort.enableReceiveTimeout(2000); + + // RXTX serial port library causes high CPU load + // Start event listener, which will just sleep and slow down event loop + serialPort.notifyOnDataAvailable(true); + + logger.info("Connected to serial port '{}'.", serialPortName); + } catch (NoSuchPortException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Port does not exist"); + return false; + } catch (PortInUseException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, + "Serial Error: Port in use"); + return false; + } catch (UnsupportedCommOperationException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, + "Serial Error: Unsupported operation"); + return false; + } + + try { + inputStream = new BufferedInputStream(serialPort.getInputStream()); + outputStream = serialPort.getOutputStream(); + } catch (IOException e) { + logger.error("Error getting serial streams", e); + return false; + } + + return true; + } + + private void closeSerialPort() { + if (serialPort != null) { + try { + serialPort.disableReceiveTimeout(); + serialPort.removeEventListener(); + outputStream.flush(); + outputStream.close(); + inputStream.close(); + } catch (Exception e) { + logger.error("Error closing serial port.", e); + } finally { + serialPort.close(); + logger.debug("Closed serial port {}.", serialPort.getName()); + serialPort = null; + inputStream = null; + outputStream = null; + } + } + + } + + @SuppressWarnings({ "unused", "null" }) + @Override + public void bluegigaEventReceived(@Nullable BlueGigaResponse event) { + if (event instanceof BlueGigaScanResponseEvent) { + BlueGigaScanResponseEvent scanEvent = (BlueGigaScanResponseEvent) event; + + // We use the scan event to add any devices we hear to the devices list + // The device gets created, and then manages itself for discovery etc. + BluetoothAddress sender = new BluetoothAddress(scanEvent.getSender()); + BlueGigaBluetoothDevice device; + if (devices.get(sender) == null) { + logger.debug("BlueGiga adding new device to adaptor {}: {}", address, sender); + device = new BlueGigaBluetoothDevice(this, new BluetoothAddress(scanEvent.getSender()), + scanEvent.getAddressType()); + devices.put(sender, device); + deviceDiscovered(device); + } + + return; + } + + if (event instanceof BlueGigaConnectionStatusEvent) { + BlueGigaConnectionStatusEvent connectionEvent = (BlueGigaConnectionStatusEvent) event; + + connections.put(connectionEvent.getConnection(), new BluetoothAddress(connectionEvent.getAddress())); + } + + if (event instanceof BlueGigaDisconnectedEvent) { + BlueGigaDisconnectedEvent disconnectedEvent = (BlueGigaDisconnectedEvent) event; + + connections.remove(disconnectedEvent.getConnection()); + } + } + + @Override + public void scanStart() { + // Stop the passive scan + bgStopProcedure(); + + // Start a active scan + bgStartScanning(true, activeScanInterval, activeScanWindow); + + for (BluetoothDevice device : devices.values()) { + deviceDiscovered(device); + } + } + + @Override + public void scanStop() { + // Stop the active scan + bgStopProcedure(); + + // Start a passive scan + bgStartScanning(false, passiveScanInterval, passiveScanWindow); + } + + @Override + public BluetoothAddress getAddress() { + if (address != null) { + return address; + } else { + throw new IllegalStateException("Adapter has not been initialized yet!"); + } + } + + @SuppressWarnings({ "null", "unused" }) + @Override + public BluetoothDevice getDevice(BluetoothAddress address) { + BluetoothDevice device = devices.get(address); + if (device == null) { + // This method always needs to return a device, even if we don't currently know about it. + device = new BlueGigaBluetoothDevice(this, address, BluetoothAddressType.UNKNOWN); + devices.put(address, device); + } + return device; + } + + /* + * The following methods provide adaptor level functions for the BlueGiga interface. Typically these methods + * are used by the device but are provided in the adapter to allow common knowledge and to support conflict + * resolution. + */ + + /** + * Connects to a device. + *

+ * If the device is already connected, or the attempt to connect failed, then we return false. If we have reached + * the maximum number of connections supported by this dongle, then we return false. + * + * @param address the device {@link BluetoothAddress} to connect to + * @param addressType the {@link BluetoothAddressType} of the device + * @return true if the connection was started + */ + public boolean bgConnect(BluetoothAddress address, BluetoothAddressType addressType) { + // Check the connection to make sure we're not already connected to this device + if (connections.containsValue(address)) { + return false; + } + + // FIXME: When getting here, I always found all connections to be already taken and thus the code never + // proceeded. Relaxing this condition did not do any obvious harm, but now guaranteed that the services are + // queried from the device. + if (connections.size() == maxConnections + 1) { + logger.debug("BlueGiga: Attempt to connect to {} but no connections available.", address); + return false; + } + + bgSetMode(); + + // Connect... + int connIntervalMin = 60; + int connIntervalMax = 100; + int latency = 0; + int timeout = 100; + + BlueGigaConnectDirectCommand connect = new BlueGigaConnectDirectCommand(); + connect.setAddress(address.toString()); + connect.setAddrType(addressType); + connect.setConnIntervalMin(connIntervalMin); + connect.setConnIntervalMax(connIntervalMax); + connect.setLatency(latency); + connect.setTimeout(timeout); + BlueGigaConnectDirectResponse connectResponse = (BlueGigaConnectDirectResponse) bgHandler + .sendTransaction(connect); + if (connectResponse.getResult() != BgApiResponse.SUCCESS) { + return false; + } + + return true; + } + + /** + * Close a connection using {@link BlueGigaDisconnectCommand} + * + * @param connectionHandle + * @return + */ + public boolean bgDisconnect(int connectionHandle) { + BlueGigaDisconnectCommand command = new BlueGigaDisconnectCommand(); + command.setConnection(connectionHandle); + BlueGigaDisconnectResponse response = (BlueGigaDisconnectResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + /** + * Device discovered. This simply passes the discover information to the discovery service for processing. + */ + public void deviceDiscovered(BluetoothDevice device) { + if (discoveryActive) { + for (BluetoothDiscoveryListener listener : discoveryListeners) { + listener.deviceDiscovered(device); + } + } + } + + /** + * Start a read of all primary services using {@link BlueGigaReadByGroupTypeCommand} + * + * @param connectionHandle + * @return true if successful + */ + public boolean bgFindPrimaryServices(int connectionHandle) { + logger.debug("BlueGiga FindPrimary: connection {}", connectionHandle); + BlueGigaReadByGroupTypeCommand command = new BlueGigaReadByGroupTypeCommand(); + command.setConnection(connectionHandle); + command.setStart(1); + command.setEnd(65535); + command.setUuid(UUID.fromString("00002800-0000-0000-0000-000000000000")); + BlueGigaReadByGroupTypeResponse response = (BlueGigaReadByGroupTypeResponse) bgHandler.sendTransaction(command); + return response.getResult() == BgApiResponse.SUCCESS; + } + + /** + * Start a read of all characteristics using {@link BlueGigaFindInformationCommand} + * + * @param connectionHandle + * @return true if successful + */ + public boolean bgFindCharacteristics(int connectionHandle) { + logger.debug("BlueGiga Find: connection {}", connectionHandle); + BlueGigaFindInformationCommand command = new BlueGigaFindInformationCommand(); + command.setConnection(connectionHandle); + command.setStart(1); + command.setEnd(65535); + BlueGigaFindInformationResponse response = (BlueGigaFindInformationResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + /** + * Read a characteristic using {@link BlueGigaReadByHandleCommand} + * + * @param connectionHandle + * @param handle + * @return true if successful + */ + public boolean bgReadCharacteristic(int connectionHandle, int handle) { + logger.debug("BlueGiga Read: connection {}, handle {}", connectionHandle, handle); + BlueGigaReadByHandleCommand command = new BlueGigaReadByHandleCommand(); + command.setConnection(connectionHandle); + command.setChrHandle(handle); + BlueGigaReadByHandleResponse response = (BlueGigaReadByHandleResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + /** + * Write a characteristic using {@link BlueGigaAttributeWriteCommand} + * + * @param connectionHandle + * @param handle + * @param value + * @return true if successful + */ + public boolean bgWriteCharacteristic(int connectionHandle, int handle, int[] value) { + logger.debug("BlueGiga Write: connection {}, handle {}", connectionHandle, handle); + BlueGigaAttributeWriteCommand command = new BlueGigaAttributeWriteCommand(); + command.setConnection(connectionHandle); + command.setAttHandle(handle); + command.setData(value); + BlueGigaAttributeWriteResponse response = (BlueGigaAttributeWriteResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + /* + * The following methods are private methods for handling the BlueGiga protocol + */ + private boolean bgStopProcedure() { + BlueGigaCommand command = new BlueGigaEndProcedureCommand(); + BlueGigaEndProcedureResponse response = (BlueGigaEndProcedureResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + private boolean bgSetMode() { + BlueGigaSetModeCommand command = new BlueGigaSetModeCommand(); + command.setConnect(GapConnectableMode.GAP_NON_CONNECTABLE); + command.setDiscover(GapDiscoverableMode.GAP_NON_DISCOVERABLE); + BlueGigaSetModeResponse response = (BlueGigaSetModeResponse) bgHandler.sendTransaction(command); + + return response.getResult() == BgApiResponse.SUCCESS; + } + + /** + * Starts scanning on the dongle + * + * @param active true for active scanning + */ + private void bgStartScanning(boolean active, int interval, int window) { + BlueGigaSetScanParametersCommand scanCommand = new BlueGigaSetScanParametersCommand(); + scanCommand.setActiveScanning(active); + scanCommand.setScanInterval(interval); + scanCommand.setScanWindow(window); + bgHandler.sendTransaction(scanCommand); + + BlueGigaDiscoverCommand discoverCommand = new BlueGigaDiscoverCommand(); + discoverCommand.setMode(GapDiscoverMode.GAP_DISCOVER_OBSERVATION); + bgHandler.sendTransaction(discoverCommand); + } + + /** + * Add an event listener for the BlueGiga events + * + * @param listener the {@link BlueGigaEventListener} to add + */ + public void addEventListener(BlueGigaEventListener listener) { + bgHandler.addEventListener(listener); + } + + /** + * Remove an event listener for the BlueGiga events + * + * @param listener the {@link BlueGigaEventListener} to remove + */ + public void removeEventListener(BlueGigaEventListener listener) { + bgHandler.removeEventListener(listener); + } + + @Override + public void addDiscoveryListener(@NonNull BluetoothDiscoveryListener listener) { + discoveryListeners.add(listener); + } + + @Override + public void removeDiscoveryListener(@Nullable BluetoothDiscoveryListener listener) { + discoveryListeners.remove(listener); + } + + @Override + public void bluegigaClosed(Exception reason) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, reason.getMessage()); + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaCommand.java new file mode 100644 index 00000000000..75dc9c7654c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaCommand.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +import java.util.Arrays; +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.SmpIoCapabilities; + +/** + * Abstract base class for all commands. This provides the serialisation methods for converting parameters from Java + * classes to wire data. + * + * @author Chris Jackson + * + */ +public abstract class BlueGigaCommand extends BlueGigaPacket { + protected int[] buffer = new int[131]; + protected int length = 0; + + protected void serializeHeader(int classId, int commandId) { + // Octet 0 7 1 bit Message Type (MT) 0: Command + // -------6:3 4 bits Technology Type (TT) 0000: Smart Bluetooth + // -------2:0 3 bits Length High (LH) Payload length (high bits) + buffer[length++] = 0; + + // Octet 1 7:0 8 bits Length Low (LL) Payload length (low bits) + buffer[length++] = 0; + + // Octet 2 7:0 8 bits Class ID (CID) Command class ID + buffer[length++] = classId; + + // Octet 3 7:0 8 bits Command ID (CMD) Command ID + buffer[length++] = commandId; + } + + /** + * Adds a uint8 into the output stream + * + * @param val + */ + protected void serializeUInt8(int val) { + buffer[length++] = val & 0xFF; + } + + protected void serializeBoolean(boolean val) { + buffer[length++] = val ? 1 : 0; + } + + /** + * Adds a uint16 into the output stream + * + * @param val + */ + protected void serializeUInt16(int val) { + buffer[length++] = val & 0xFF; + buffer[length++] = (val >> 8) & 0xFF; + } + + /** + * Adds a uint32 into the output stream + * + * @param passkey + */ + protected void serializeUInt32(long passkey) { + buffer[length++] = (int) (passkey & 0xFF); + buffer[length++] = (int) ((passkey >> 8) & 0xFF); + buffer[length++] = (int) ((passkey >> 16) & 0xFF); + buffer[length++] = (int) ((passkey >> 24) & 0xFF); + } + + protected void serializeUInt8Array(int[] array) { + serializeUInt8(array.length); + + for (int val : array) { + serializeUInt8(val); + } + } + + protected void serializeUuid(UUID uuid) { + // TODO this probably needs to support longer UUIDs? + buffer[length++] = 2; + long high = uuid.getMostSignificantBits(); + + buffer[length++] = (int) ((high >> 32) & 0xff); + buffer[length++] = (int) ((high >> 40) & 0xff); + } + + protected void serializeAddress(String address) { + String[] bytes = address.split(":"); + if (bytes.length == 0) { + serializeUInt8(0); + serializeUInt8(0); + serializeUInt8(0); + serializeUInt8(0); + serializeUInt8(0); + serializeUInt8(0); + + return; + } + + for (int cnt = 5; cnt >= 0; cnt--) { + serializeUInt8(Integer.parseInt(bytes[cnt], 16)); + } + } + + protected void serializeSmpIoCapabilities(SmpIoCapabilities capabilities) { + serializeUInt8(capabilities.getKey()); + } + + protected void serializeBluetoothAddressType(BluetoothAddressType addrType) { + serializeUInt8(addrType.getKey()); + } + + protected void serializeGapDiscoverableMode(GapDiscoverableMode mode) { + serializeUInt8(mode.getKey()); + } + + protected void serializeGapConnectableMode(GapConnectableMode mode) { + serializeUInt8(mode.getKey()); + } + + protected void serializeGapDiscoverMode(GapDiscoverMode mode) { + serializeUInt8(mode.getKey()); + } + + protected int[] getPayload() { + buffer[1] = length - 4; + return Arrays.copyOfRange(buffer, 0, length); + } + + public abstract int[] serialize(); +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaEventListener.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaEventListener.java new file mode 100644 index 00000000000..c570db4172d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaEventListener.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +/** + * + * @author Chris Jackson + * + */ +public interface BlueGigaEventListener { + /** + * Called when an event is received + * + * @param event the {@link BlueGigaResponse} just received + */ + void bluegigaEventReceived(BlueGigaResponse event); +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaHandlerListener.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaHandlerListener.java new file mode 100644 index 00000000000..a3cc6ae1584 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaHandlerListener.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * A listener to track {@link BlueGigaSerialHandler} life cycle events. + * + * @author Chris Jackson - Initial contribution and API + */ +@NonNullByDefault +public interface BlueGigaHandlerListener { + + /** + * Notifies when the handler gets closed because of the reason specified as an argument. + * + * @param reason a reason caused to be closed + */ + void bluegigaClosed(Exception reason); + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaPacket.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaPacket.java new file mode 100644 index 00000000000..b766471e6fe --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaPacket.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +/** + * Base class from which both commands and responses (and events) are derived. + * + * @author Chris Jackson + * + */ +public class BlueGigaPacket { + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponse.java new file mode 100644 index 00000000000..0775a5ae0b8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponse.java @@ -0,0 +1,185 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.AttributeChangeReason; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.AttributeValueType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ScanResponseType; + +/** + * Abstract class for response and event packets. This provides the deserialization methods to convert wire data to Java + * classes. + * + * @author Chris Jackson + * + */ +public class BlueGigaResponse extends BlueGigaPacket { + private int[] buffer = new int[131]; + private int position = 0; + protected boolean event = false; + + protected BlueGigaResponse(int[] inputBuffer) { + // TODO Auto-generated constructor stub + buffer = inputBuffer; + position = 4; + } + + /** + * Returns true if this response is an event, or false if it is a response to a command + * + * @return true if this is an event + */ + public boolean isEvent() { + return event; + } + + /** + * Reads a int8 from the output stream + * + * @return value read from input + */ + protected int deserializeInt8() { + if (buffer[position] >= 128) { + return buffer[position++] - 256; + } else { + return buffer[position++]; + } + } + + /** + * Reads a uint8 from the output stream + * + * @return value read from input + */ + protected int deserializeUInt8() { + return buffer[position++]; + } + + protected boolean deserializeBoolean() { + return buffer[position++] != 0; + } + + /** + * Reads a uint16 from the output stream + * + * @return value read from input + */ + protected int deserializeUInt16() { + return buffer[position++] + (buffer[position++] << 8); + } + + protected UUID deserializeUuid() { + long low; + long high; + + // This is a uint8array type so first byte is the length + int length = buffer[position++]; + switch (length) { + case 2: + low = 0; + high = ((long) buffer[position++] << 32) + ((long) buffer[position++] << 40); + break; + case 4: + low = 0; + high = ((long) buffer[position++] << 32) + ((long) buffer[position++] << 40) + + ((long) buffer[position++] << 48) + ((long) buffer[position++] << 56); + break; + case 16: + low = (buffer[position++]) + ((long) buffer[position++] << 8) + ((long) buffer[position++] << 16) + + ((long) buffer[position++] << 24) + ((long) buffer[position++] << 32) + + ((long) buffer[position++] << 40) + ((long) buffer[position++] << 48) + + ((long) buffer[position++] << 56); + high = (buffer[position++]) + ((long) buffer[position++] << 8) + ((long) buffer[position++] << 16) + + ((long) buffer[position++] << 24) + ((long) buffer[position++] << 32) + + ((long) buffer[position++] << 40) + ((long) buffer[position++] << 48) + + ((long) buffer[position++] << 56); + break; + default: + low = 0; + high = 0; + position += length; + break; + } + return new UUID(high, low); + } + + protected BgApiResponse deserializeBgApiResponse() { + return BgApiResponse.getBgApiResponse(deserializeUInt16()); + } + + public Set deserializeConnectionStatusFlag() { + int val = deserializeUInt8(); + Set options = new HashSet(); + for (ConnectionStatusFlag option : ConnectionStatusFlag.values()) { + if (option == ConnectionStatusFlag.UNKNOWN) { + continue; + } + if ((option.getKey() & val) != 0) { + options.add(option); + } + } + return options; + } + + protected AttributeValueType deserializeAttributeValueType() { + return AttributeValueType.getAttributeValueType(deserializeUInt8()); + } + + protected BluetoothAddressType deserializeBluetoothAddressType() { + return BluetoothAddressType.getBluetoothAddressType(deserializeUInt8()); + } + + protected AttributeChangeReason deserializeAttributeChangeReason() { + return AttributeChangeReason.getAttributeChangeReason(deserializeUInt8()); + } + + protected ScanResponseType deserializeScanResponseType() { + return ScanResponseType.getScanResponseType(deserializeUInt8()); + } + + protected long deserializeUInt32() { + return buffer[position++] + (buffer[position++] << 8) + (buffer[position++] << 16) + (buffer[position++] << 24); + } + + protected int[] deserializeUInt8Array() { + int length = buffer[position++]; + int[] val = new int[length]; + + for (int cnt = 0; cnt < length; cnt++) { + val[cnt] = deserializeUInt8(); + } + + return val; + } + + protected String deserializeAddress() { + StringBuilder builder = new StringBuilder(); + + for (int cnt = 5; cnt >= 0; cnt--) { + if (cnt < 5) { + builder.append(':'); + } + builder.append(String.format("%02X", buffer[position + cnt])); + } + position += 6; + + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponsePackets.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponsePackets.java new file mode 100644 index 00000000000..7fdbf069284 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaResponsePackets.java @@ -0,0 +1,204 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeValueEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaExecuteWriteResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindByTypeValueResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationFoundEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaGroupFoundEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaIndicateConfirmResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaIndicatedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaPrepareWriteResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaProcedureCompletedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByTypeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadLongResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadMultipleResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadMultipleResponseEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaWriteCommandResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaAttributeStatusEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaReadResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaReadTypeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaSendAttributesResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserReadRequestEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserReadResponseResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserWriteResponseResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaValueEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaWriteResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaChannelMapGetResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaFeatureIndEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaGetRssiResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaGetStatusResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaUpdateResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaVersionIndEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectSelectiveResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaDiscoverResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetAdvDataResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetAdvParametersResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetScanParametersResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaBondStatusEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaBondingFailEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaDeleteBondingResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaEncryptStartResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaGetBondsResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPassKeyResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPasskeyDisplayEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPasskeyRequestEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaSetBondableModeResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaSetParametersResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security.BlueGigaWhitelistBondsResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaBootEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaEndpointWatermarkRxEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaEndpointWatermarkTxEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetCountersResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaHelloResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaNoLicenseKeyEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaProtocolErrorEvent; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaResetResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaWhitelistAppendResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaWhitelistClearResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system.BlueGigaWhitelistRemoveResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class to create BlueGiga BLE Response and Event packets (ie packets that we will receive). + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +class BlueGigaResponsePackets { + + private static Logger logger = LoggerFactory.getLogger(BlueGigaResponsePackets.class); + + final private static Map> packetMap = new HashMap>(); + + static { + packetMap.put(Objects.hash(0x00, 0x06, true), BlueGigaProtocolErrorEvent.class); + packetMap.put(Objects.hash(0x00, 0x02, true), BlueGigaEndpointWatermarkRxEvent.class); + packetMap.put(Objects.hash(0x00, 0x03, true), BlueGigaEndpointWatermarkTxEvent.class); + packetMap.put(Objects.hash(0x00, 0x05, true), BlueGigaNoLicenseKeyEvent.class); + packetMap.put(Objects.hash(0x04, 0x05, false), BlueGigaAttributeWriteResponse.class); + packetMap.put(Objects.hash(0x04, 0x0A, false), BlueGigaExecuteWriteResponse.class); + packetMap.put(Objects.hash(0x04, 0x00, false), BlueGigaFindByTypeValueResponse.class); + packetMap.put(Objects.hash(0x04, 0x03, false), BlueGigaFindInformationResponse.class); + packetMap.put(Objects.hash(0x04, 0x07, false), BlueGigaIndicateConfirmResponse.class); + packetMap.put(Objects.hash(0x04, 0x09, false), BlueGigaPrepareWriteResponse.class); + packetMap.put(Objects.hash(0x04, 0x01, false), BlueGigaReadByGroupTypeResponse.class); + packetMap.put(Objects.hash(0x04, 0x04, false), BlueGigaReadByHandleResponse.class); + packetMap.put(Objects.hash(0x04, 0x02, false), BlueGigaReadByTypeResponse.class); + packetMap.put(Objects.hash(0x04, 0x08, false), BlueGigaReadLongResponse.class); + packetMap.put(Objects.hash(0x04, 0x0B, false), BlueGigaReadMultipleResponse.class); + packetMap.put(Objects.hash(0x04, 0x06, false), BlueGigaWriteCommandResponse.class); + packetMap.put(Objects.hash(0x04, 0x01, true), BlueGigaProcedureCompletedEvent.class); + packetMap.put(Objects.hash(0x04, 0x05, true), BlueGigaAttributeValueEvent.class); + packetMap.put(Objects.hash(0x04, 0x04, true), BlueGigaFindInformationFoundEvent.class); + packetMap.put(Objects.hash(0x04, 0x02, true), BlueGigaGroupFoundEvent.class); + packetMap.put(Objects.hash(0x04, 0x00, true), BlueGigaIndicatedEvent.class); + packetMap.put(Objects.hash(0x04, 0x00, true), BlueGigaReadMultipleResponseEvent.class); + packetMap.put(Objects.hash(0x02, 0x01, false), BlueGigaReadResponse.class); + packetMap.put(Objects.hash(0x02, 0x02, false), BlueGigaReadTypeResponse.class); + packetMap.put(Objects.hash(0x02, 0x02, false), BlueGigaSendAttributesResponse.class); + packetMap.put(Objects.hash(0x02, 0x03, false), BlueGigaUserReadResponseResponse.class); + packetMap.put(Objects.hash(0x02, 0x04, false), BlueGigaUserWriteResponseResponse.class); + packetMap.put(Objects.hash(0x02, 0x00, false), BlueGigaWriteResponse.class); + packetMap.put(Objects.hash(0x02, 0x02, true), BlueGigaAttributeStatusEvent.class); + packetMap.put(Objects.hash(0x02, 0x01, true), BlueGigaUserReadRequestEvent.class); + packetMap.put(Objects.hash(0x02, 0x00, true), BlueGigaValueEvent.class); + packetMap.put(Objects.hash(0x03, 0x04, false), BlueGigaChannelMapGetResponse.class); + packetMap.put(Objects.hash(0x03, 0x00, false), BlueGigaDisconnectResponse.class); + packetMap.put(Objects.hash(0x03, 0x01, false), BlueGigaGetRssiResponse.class); + packetMap.put(Objects.hash(0x03, 0x07, false), BlueGigaGetStatusResponse.class); + packetMap.put(Objects.hash(0x03, 0x02, false), BlueGigaUpdateResponse.class); + packetMap.put(Objects.hash(0x03, 0x04, true), BlueGigaDisconnectedEvent.class); + packetMap.put(Objects.hash(0x03, 0x02, true), BlueGigaFeatureIndEvent.class); + packetMap.put(Objects.hash(0x03, 0x00, true), BlueGigaConnectionStatusEvent.class); + packetMap.put(Objects.hash(0x03, 0x01, true), BlueGigaVersionIndEvent.class); + packetMap.put(Objects.hash(0x06, 0x07, false), BlueGigaSetScanParametersResponse.class); + packetMap.put(Objects.hash(0x06, 0x03, false), BlueGigaConnectDirectResponse.class); + packetMap.put(Objects.hash(0x06, 0x05, false), BlueGigaConnectSelectiveResponse.class); + packetMap.put(Objects.hash(0x06, 0x02, false), BlueGigaDiscoverResponse.class); + packetMap.put(Objects.hash(0x06, 0x08, false), BlueGigaSetAdvParametersResponse.class); + packetMap.put(Objects.hash(0x06, 0x09, false), BlueGigaSetAdvDataResponse.class); + packetMap.put(Objects.hash(0x06, 0x04, false), BlueGigaEndProcedureResponse.class); + packetMap.put(Objects.hash(0x06, 0x01, false), BlueGigaSetModeResponse.class); + packetMap.put(Objects.hash(0x06, 0x00, true), BlueGigaScanResponseEvent.class); + packetMap.put(Objects.hash(0x05, 0x02, false), BlueGigaDeleteBondingResponse.class); + packetMap.put(Objects.hash(0x05, 0x00, false), BlueGigaEncryptStartResponse.class); + packetMap.put(Objects.hash(0x05, 0x05, false), BlueGigaGetBondsResponse.class); + packetMap.put(Objects.hash(0x05, 0x04, false), BlueGigaPassKeyResponse.class); + packetMap.put(Objects.hash(0x05, 0x01, false), BlueGigaSetBondableModeResponse.class); + packetMap.put(Objects.hash(0x05, 0x03, false), BlueGigaSetParametersResponse.class); + packetMap.put(Objects.hash(0x05, 0x07, false), BlueGigaWhitelistBondsResponse.class); + packetMap.put(Objects.hash(0x00, 0x0A, false), BlueGigaWhitelistAppendResponse.class); + packetMap.put(Objects.hash(0x00, 0x0B, false), BlueGigaWhitelistRemoveResponse.class); + packetMap.put(Objects.hash(0x00, 0x0C, false), BlueGigaWhitelistClearResponse.class); + packetMap.put(Objects.hash(0x05, 0x01, true), BlueGigaBondingFailEvent.class); + packetMap.put(Objects.hash(0x05, 0x04, true), BlueGigaBondStatusEvent.class); + packetMap.put(Objects.hash(0x05, 0x02, true), BlueGigaPasskeyDisplayEvent.class); + packetMap.put(Objects.hash(0x05, 0x03, true), BlueGigaPasskeyRequestEvent.class); + packetMap.put(Objects.hash(0x00, 0x02, false), BlueGigaAddressGetResponse.class); + packetMap.put(Objects.hash(0x00, 0x01, false), BlueGigaHelloResponse.class); + packetMap.put(Objects.hash(0x00, 0x00, false), BlueGigaResetResponse.class); + packetMap.put(Objects.hash(0x00, 0x06, false), BlueGigaGetConnectionsResponse.class); + packetMap.put(Objects.hash(0x00, 0x05, false), BlueGigaGetCountersResponse.class); + packetMap.put(Objects.hash(0x00, 0x08, false), BlueGigaGetInfoResponse.class); + packetMap.put(Objects.hash(0x00, 0x00, true), BlueGigaBootEvent.class); + } + + public static BlueGigaResponse getPacket(int[] data) { + int cmdClass = data[2]; + int cmdMethod = data[3]; + boolean isEvent = (data[0] & 0x80) != 0; + + Class bleClass = packetMap.get(Objects.hash(cmdClass, cmdMethod, isEvent)); + + if (bleClass == null) { + return null; + } + + Constructor ctor; + + try { + ctor = bleClass.getConstructor(int[].class); + BlueGigaResponse bleFrame = (BlueGigaResponse) ctor.newInstance(data); + return bleFrame; + } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + logger.error("Error instantiating BLE class", e); + } + + return null; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaSerialHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaSerialHandler.java new file mode 100644 index 00000000000..192c0c16567 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/BlueGigaSerialHandler.java @@ -0,0 +1,460 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.Callable; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import org.eclipse.smarthome.core.common.ThreadPoolManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The main handler class for interacting with the BlueGiga serial API. This class provides transaction management and + * queuing of of data, and conversion of packets from the serial stream into command and response classes. + * + * @author Chris Jackson - Initial contribution and API + * + */ +public class BlueGigaSerialHandler { + + private static final int BLE_MAX_LENGTH = 64; + private static final int TRANSACTION_TIMEOUT_PERIOD = 50; + + private final Logger logger = LoggerFactory.getLogger(BlueGigaSerialHandler.class); + + /** + * The portName portName output stream. + */ + private final OutputStream outputStream; + private final Queue sendQueue = new LinkedList(); + private final Timer timer = new Timer(); + private TimerTask timerTask = null; + private Thread parserThread = null; + private final ExecutorService executor = ThreadPoolManager.getPool("bluegiga"); + + /** + * Transaction listeners are used internally to correlate the commands and responses + */ + private final List transactionListeners = new CopyOnWriteArrayList(); + + /** + * The event listeners will be notified of any asynchronous events + */ + private final Set eventListeners = new CopyOnWriteArraySet<>(); + + /** + * The event listeners will be notified of any life-cycle events of the handler. + */ + private final Set handlerListeners = new CopyOnWriteArraySet<>(); + + /** + * Flag reflecting that parser has been closed and parser parserThread + * should exit. + */ + private boolean close = false; + + public BlueGigaSerialHandler(final InputStream inputStream, final OutputStream outputStream) { + this.outputStream = outputStream; + + final int framecheckParams[] = new int[] { 0x00, 0x7F, 0xC0, 0xF8, 0xE0 }; + + parserThread = new Thread("BlueGigaBLEHandler") { + @Override + public void run() { + int exceptionCnt = 0; + logger.trace("BlueGiga BLE thread started"); + int[] inputBuffer = new int[BLE_MAX_LENGTH]; + int inputCount = 0; + int inputLength = 0; + + while (!close) { + try { + int val = inputStream.read(); + if (val == -1) { + continue; + } + // logger.debug("BLE RX: " + String.format("%02X", val)); + + inputBuffer[inputCount++] = val; + + if (inputCount < 4) { + // The BGAPI protocol has no packet framing, and no error detection, so we do a few + // sanity checks on the header to try and allow resyncronisation should there be an + // error. + // Byte 0: Check technology type is bluetooth and high length is 0 + // Byte 1: Check length is less than 64 bytes + // Byte 2: Check class ID is less than 8 + // Byte 3: Check command ID is less than 16 + if ((val & framecheckParams[inputCount]) != 0) { + logger.debug("BlueGiga framing error byte {} = {}", inputCount, val); + inputCount = 0; + continue; + } + } else if (inputCount == 4) { + // Process the header to get the length + inputLength = inputBuffer[1] + (inputBuffer[0] & 0x02 << 8) + 4; + if (inputLength > 64) { + logger.error("BLE length larger than 64 bytes ({})", inputLength); + } + } + if (inputCount == inputLength) { + // End of packet reached - process + BlueGigaResponse responsePacket = BlueGigaResponsePackets.getPacket(inputBuffer); + + logger.trace("BLE RX: {}", printHex(inputBuffer, inputLength)); + logger.trace("BLE RX: {}", responsePacket); + if (responsePacket != null) { + if (responsePacket.isEvent()) { + notifyEventListeners(responsePacket); + } else { + notifyTransactionComplete(responsePacket); + } + } + + inputCount = 0; + } + + } catch (final IOException e) { + logger.error("BlueGiga BLE IOException: ", e); + + if (exceptionCnt++ > 10) { + logger.error("BlueGiga BLE exception count exceeded"); + // if (!close) { + // frameHandler.error(e); + close = true; + notifyClosed(e); + } + } + } + logger.debug("BlueGiga BLE exited."); + } + }; + + parserThread.setDaemon(true); + parserThread.start(); + } + + /** + * Requests parser thread to shutdown. + */ + public void close() { + this.close = true; + try { + parserThread.interrupt(); + parserThread.join(); + } catch (InterruptedException e) { + logger.warn("Interrupted in packet parser thread shutdown join."); + } + } + + /** + * Checks if parser thread is alive. + * + * @return true if parser thread is alive. + */ + public boolean isAlive() { + return parserThread != null && parserThread.isAlive() && !close; + } + + // Synchronize this method to ensure a packet gets sent as a block + private synchronized void sendFrame(BlueGigaCommand bleFrame) { + // Send the data + try { + int[] payload = bleFrame.serialize(); + logger.trace("TX BLE frame: {}", printHex(payload, payload.length)); + for (int b : payload) { + outputStream.write(b); + } + } catch (IOException e) { + logger.debug(e.getMessage()); + } + + logger.trace("--> TX BLE frame: {}", bleFrame); + } + + // Synchronize this method so we can do the window check without interruption. + // Otherwise this method could be called twice from different threads that could end up with + // more than the TX_WINDOW number of frames sent. + private synchronized void sendNextFrame() { + BlueGigaCommand nextFrame = sendQueue.poll(); + if (nextFrame == null) { + // Nothing to send + return; + } + + sendFrame(nextFrame); + } + + /** + * Add a {@link BlueGigaCommand} frame to the send queue. The sendQueue is a + * FIFO queue. This method queues a {@link BlueGigaCommand} frame without + * waiting for a response. + * + * @param transaction + * {@link BlueGigaCommand} + */ + public void queueFrame(BlueGigaCommand request) { + logger.trace("TX BLE frame: {}", request); + checkIfAlive(); + sendQueue.add(request); + logger.trace("TX BLE queue: {}", sendQueue.size()); + sendNextFrame(); + } + + /** + * Notify any transaction listeners when we receive a response. + * + * @param response + * the response data received + * @return true if the response was processed + */ + private boolean notifyTransactionComplete(final BlueGigaResponse response) { + boolean processed = false; + + // logger.debug("NODE {}: notifyTransactionResponse {}", + // transaction.getNodeId(), transaction.getTransactionId()); + synchronized (transactionListeners) { + for (BluetoothListener listener : transactionListeners) { + if (listener.transactionEvent(response)) { + processed = true; + } + } + } + + return processed; + } + + private void addTransactionListener(BluetoothListener listener) { + synchronized (transactionListeners) { + if (transactionListeners.contains(listener)) { + return; + } + + transactionListeners.add(listener); + } + } + + private void removeTransactionListener(BluetoothListener listener) { + synchronized (transactionListeners) { + transactionListeners.remove(listener); + } + } + + /** + * Sends an BlueGiga request without waiting for the response. + * + * @param bleCommand + * Request {@link BlueGigaCommand} + * @return response {@link Future} {@link BlueGigaResponse} + */ + public Future sendBleRequestAsync(final BlueGigaCommand bleCommand) { + checkIfAlive(); + class TransactionWaiter implements Callable, BluetoothListener { + private boolean complete = false; + private BlueGigaResponse response = null; + + @Override + public BlueGigaResponse call() { + // Register a listener + addTransactionListener(this); + + // Send the transaction + queueFrame(bleCommand); + + // Wait for the transaction to complete + synchronized (this) { + while (!complete) { + try { + wait(); + } catch (InterruptedException e) { + complete = true; + } + } + } + + // Remove the listener + removeTransactionListener(this); + + return response; + } + + @Override + public boolean transactionEvent(BlueGigaResponse bleResponse) { + // Check if this response completes our transaction + if (bleCommand.hashCode() == bleResponse.hashCode()) { + return false; + } + + response = bleResponse; + complete = true; + synchronized (this) { + notify(); + } + + return true; + } + } + + Callable worker = new TransactionWaiter(); + return executor.submit(worker); + } + + /** + * Sends a {@link BlueGigaCommand} request to the NCP and waits for the response. The response is correlated with + * the request and the returned {@link BlueGigaResponse} contains the request and response data. + * + * @param bleRequest + * Request {@link BlueGigaCommand} + * @return response {@link BlueGigaResponse} + */ + public BlueGigaResponse sendTransaction(BlueGigaCommand bleCommand) { + checkIfAlive(); + Future futureResponse = sendBleRequestAsync(bleCommand); + if (futureResponse == null) { + logger.debug("Error sending BLE transaction: Future is null"); + return null; + } + + try { + return futureResponse.get(); + // return bleCommand; + } catch (InterruptedException | ExecutionException e) { + logger.debug("Error sending BLE transaction to listeners: ", e); + } + + return null; + } + + // TODO: Add a timeout mechanism + @SuppressWarnings("unused") + private synchronized void startTransactionTimer() { + // Stop any existing timer + resetTransactionTimer(); + + // Create the timer task + timerTask = new TransactionTimer(); + timer.schedule(timerTask, TRANSACTION_TIMEOUT_PERIOD); + } + + private synchronized void resetTransactionTimer() { + // Stop any existing timer + if (timerTask != null) { + timerTask.cancel(); + timerTask = null; + } + } + + private class TransactionTimer extends TimerTask { + // private final Logger logger = + // LoggerFactory.getLogger(ZWaveTransactionTimer.class); + + @Override + public void run() { + + } + } + + /** + * Notify any transaction listeners when we receive a response. + * This uses a separate thread to separate the processing of the event. + * + * @param response + * the response data received + * @return true if the response was processed + */ + private void notifyEventListeners(final BlueGigaResponse response) { + synchronized (this) { + // Notify the listeners + for (final BlueGigaEventListener listener : eventListeners) { + executor.submit(() -> listener.bluegigaEventReceived(response)); + } + } + } + + public void addEventListener(BlueGigaEventListener listener) { + synchronized (eventListeners) { + eventListeners.add(listener); + } + } + + /** + * Adds a handler listener. + * + * @param listener a new handler listener + */ + public void addHandlerListener(BlueGigaHandlerListener listener) { + handlerListeners.add(listener); + } + + public void removeEventListener(BlueGigaEventListener listener) { + eventListeners.remove(listener); + } + + public void removeHandlerListener(BlueGigaHandlerListener listener) { + handlerListeners.remove(listener); + } + + private String printHex(int[] data, int len) { + StringBuilder builder = new StringBuilder(); + + for (int cnt = 0; cnt < len; cnt++) { + builder.append(String.format("%02X ", data[cnt])); + } + + return builder.toString(); + } + + private void checkIfAlive() { + if (!isAlive()) { + throw new IllegalStateException("Bluegiga handler is dead. Most likely because of IO errors. " + + "Re-initialization of the BlueGigaSerialHandler is required."); + } + } + + /** + * Notify handler event listeners that the handler was bluegigaClosed due to an error specified as an argument. + * + * @param reason the reason to bluegigaClosed + */ + private void notifyClosed(Exception reason) { + // It should be safe enough not to use the NotificationService as this is a fatal error, no any further actions + // can be done with the handler, a new handler should be re-created + // There is another reason why NotificationService can't be used - the listeners should be notified immidiately + for (BlueGigaHandlerListener listener : handlerListeners) { + try { + listener.bluegigaClosed(reason); + } catch (Exception ex) { + logger.warn("Execution error of a BlueGigaHandlerListener listener.", ex); + } + } + } + + interface BluetoothListener { + boolean transactionEvent(BlueGigaResponse bleResponse); + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeValueEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeValueEvent.java new file mode 100644 index 00000000000..f2248933508 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeValueEvent.java @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.AttributeValueType; + +/** + * Class to implement the BlueGiga command attributeValueEvent. + *

+ * This event is produced at the GATT client side when an attribute value is passed from the GATT + * server to the GATT client. This event is for example produced after a successful Read by + * Handle operation or when an attribute is indicated or notified by the remote device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAttributeValueEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x05; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int attHandle; + + /** + * Attribute type + *

+ * BlueGiga API type is AttributeValueType - Java type is {@link AttributeValueType} + */ + private AttributeValueType type; + + /** + * Attribute value (data) + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Event constructor + */ + public BlueGigaAttributeValueEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + attHandle = deserializeUInt16(); + type = deserializeAttributeValueType(); + value = deserializeUInt8Array(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current att_handle as {@link int} + */ + public int getAttHandle() { + return attHandle; + } + /** + * Attribute type + *

+ * BlueGiga API type is AttributeValueType - Java type is {@link AttributeValueType} + * + * @return the current type as {@link AttributeValueType} + */ + public AttributeValueType getType() { + return type; + } + /** + * Attribute value (data) + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaAttributeValueEvent [connection="); + builder.append(connection); + builder.append(", attHandle="); + builder.append(attHandle); + builder.append(", type="); + builder.append(type); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteCommand.java new file mode 100644 index 00000000000..3a13d3fa728 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteCommand.java @@ -0,0 +1,110 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command attributeWrite. + *

+ * This command can be used to write an attributes value on a remote device. In order to write the + * value of an attribute a connection must exists and you need to know the handle of the attribute + * you want to write + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAttributeWriteCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x05; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle to write to + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int attHandle; + + /** + * Attribute value + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] data; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle to write to + * + * @param attHandle the attHandle to set as {@link int} + */ + public void setAttHandle(int attHandle) { + this.attHandle = attHandle; + } + /** + * Attribute value + * + * @param data the data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(attHandle); + serializeUInt8Array(data); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaAttributeWriteCommand [connection="); + builder.append(connection); + builder.append(", attHandle="); + builder.append(attHandle); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteResponse.java new file mode 100644 index 00000000000..7c4f9a53a11 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaAttributeWriteResponse.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command attributeWrite. + *

+ * This command can be used to write an attributes value on a remote device. In order to write the + * value of an attribute a connection must exists and you need to know the handle of the attribute + * you want to write + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAttributeWriteResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x05; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : write was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaAttributeWriteResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : write was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaAttributeWriteResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteCommand.java new file mode 100644 index 00000000000..4c737aac841 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteCommand.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command executeWrite. + *

+ * This command can be used to execute or cancel a previously queued prepare_write command on a + * remote device + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaExecuteWriteCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x0A; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 1: commits queued writes, 0: cancels queued writes + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int commit; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * 1: commits queued writes, 0: cancels queued writes + * + * @param commit the commit to set as {@link int} + */ + public void setCommit(int commit) { + this.commit = commit; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt8(commit); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaExecuteWriteCommand [connection="); + builder.append(connection); + builder.append(", commit="); + builder.append(commit); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteResponse.java new file mode 100644 index 00000000000..0e6f24d4820 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaExecuteWriteResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command executeWrite. + *

+ * This command can be used to execute or cancel a previously queued prepare_write command on a + * remote device + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaExecuteWriteResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x0A; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : write was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaExecuteWriteResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : write was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaExecuteWriteResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueCommand.java new file mode 100644 index 00000000000..5f7c9458ea1 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueCommand.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command findByTypeValue. + *

+ * This command can be used to find specific attributes on a remote device based on their 16-bit + * UUID value and value. The search can be limited by a starting and ending handle values. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFindByTypeValueCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * First requested handle number + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int start; + + /** + * Last requested handle number + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int end; + + /** + * 2 octet UUID to find + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + */ + private UUID uuid; + + /** + * Attribute value to find + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * First requested handle number + * + * @param start the start to set as {@link int} + */ + public void setStart(int start) { + this.start = start; + } + /** + * Last requested handle number + * + * @param end the end to set as {@link int} + */ + public void setEnd(int end) { + this.end = end; + } + /** + * 2 octet UUID to find + * + * @param uuid the uuid to set as {@link UUID} + */ + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + /** + * Attribute value to find + * + * @param value the value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(start); + serializeUInt16(end); + serializeUuid(uuid); + serializeUInt8Array(value); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFindByTypeValueCommand [connection="); + builder.append(connection); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); + builder.append(", uuid="); + builder.append(uuid); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueResponse.java new file mode 100644 index 00000000000..8e476308cd8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindByTypeValueResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command findByTypeValue. + *

+ * This command can be used to find specific attributes on a remote device based on their 16-bit + * UUID value and value. The search can be limited by a starting and ending handle values. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFindByTypeValueResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the operation was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaFindByTypeValueResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the operation was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFindByTypeValueResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationCommand.java new file mode 100644 index 00000000000..82fb3ee51b9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationCommand.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command findInformation. + *

+ * This command can be used to find specific attributes on a remote device based on their 16-bit + * UUID value and value. The search can be limited by a starting and ending handle values. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFindInformationCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x03; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * First attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int start; + + /** + * Last attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int end; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * First attribute handle + * + * @param start the start to set as {@link int} + */ + public void setStart(int start) { + this.start = start; + } + /** + * Last attribute handle + * + * @param end the end to set as {@link int} + */ + public void setEnd(int end) { + this.end = end; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(start); + serializeUInt16(end); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFindInformationCommand [connection="); + builder.append(connection); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationFoundEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationFoundEvent.java new file mode 100644 index 00000000000..758b00ce02e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationFoundEvent.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command findInformationFoundEvent. + *

+ * This event is generated when characteristics type mappings are found. This happens + * typically after Find Information command has been issued to discover all attributes of a + * service. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFindInformationFoundEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Characteristics handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int chrHandle; + + /** + * Characteristics type (UUID) + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + */ + private UUID uuid; + + /** + * Event constructor + */ + public BlueGigaFindInformationFoundEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + chrHandle = deserializeUInt16(); + uuid = deserializeUuid(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Characteristics handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current chr_handle as {@link int} + */ + public int getChrHandle() { + return chrHandle; + } + /** + * Characteristics type (UUID) + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + * + * @return the current uuid as {@link UUID} + */ + public UUID getUuid() { + return uuid; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFindInformationFoundEvent [connection="); + builder.append(connection); + builder.append(", chrHandle="); + builder.append(chrHandle); + builder.append(", uuid="); + builder.append(uuid); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationResponse.java new file mode 100644 index 00000000000..bdb298a0b45 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaFindInformationResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command findInformation. + *

+ * This command can be used to find specific attributes on a remote device based on their 16-bit + * UUID value and value. The search can be limited by a starting and ending handle values. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFindInformationResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x03; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the operation was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaFindInformationResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the operation was successful. Otherwise error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFindInformationResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaGroupFoundEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaGroupFoundEvent.java new file mode 100644 index 00000000000..8379a3d2a36 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaGroupFoundEvent.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command groupFoundEvent. + *

+ * This event is produced when an attribute group (a service) is found. Typically this event is + * produced after Read by Group Type command. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGroupFoundEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Starting handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int start; + + /** + * Ending handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int end; + + /** + * UUID of a service. Length is 0 if no services are found. + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + */ + private UUID uuid; + + /** + * Event constructor + */ + public BlueGigaGroupFoundEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + start = deserializeUInt16(); + end = deserializeUInt16(); + uuid = deserializeUuid(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Starting handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current start as {@link int} + */ + public int getStart() { + return start; + } + /** + * Ending handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current end as {@link int} + */ + public int getEnd() { + return end; + } + /** + * UUID of a service. Length is 0 if no services are found. + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + * + * @return the current uuid as {@link UUID} + */ + public UUID getUuid() { + return uuid; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGroupFoundEvent [connection="); + builder.append(connection); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); + builder.append(", uuid="); + builder.append(uuid); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmCommand.java new file mode 100644 index 00000000000..5cd83fd5c8e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmCommand.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command indicateConfirm. + *

+ * This command can be used to send a acknowledge a received indication from a remote device. + * This function allows the application to manually confirm the indicated values instead of + * the smart stack Bluetooth automatically doing it. The benefit of this is extra reliability + * since the application can for example store the received value on the flash memory before + * confirming the indication to the remote device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaIndicateConfirmCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x07; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaIndicateConfirmCommand [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmResponse.java new file mode 100644 index 00000000000..474f49ba27b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicateConfirmResponse.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command indicateConfirm. + *

+ * This command can be used to send a acknowledge a received indication from a remote device. + * This function allows the application to manually confirm the indicated values instead of + * the smart stack Bluetooth automatically doing it. The benefit of this is extra reliability + * since the application can for example store the received value on the flash memory before + * confirming the indication to the remote device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaIndicateConfirmResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x07; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaIndicateConfirmResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaIndicateConfirmResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicatedEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicatedEvent.java new file mode 100644 index 00000000000..ab6f088d383 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaIndicatedEvent.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command indicatedEvent. + *

+ * This event is produced at the GATT server side when an attribute is successfully indicated to + * the GATT client. This means the event is only produced at the GATT server if the indication is + * acknowledged by the GATT client (the remote device). + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaIndicatedEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int attrhandle; + + /** + * Event constructor + */ + public BlueGigaIndicatedEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + attrhandle = deserializeUInt16(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current attrhandle as {@link int} + */ + public int getAttrhandle() { + return attrhandle; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaIndicatedEvent [connection="); + builder.append(connection); + builder.append(", attrhandle="); + builder.append(attrhandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteCommand.java new file mode 100644 index 00000000000..5165076a908 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteCommand.java @@ -0,0 +1,130 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command prepareWrite. + *

+ * This command will send a prepare write request to a remote device for queued writes. Queued + * writes can for example be used to write large attribute values by transmitting the data in + * chunks using prepare write command. Once the data has been transmitted with multiple + * prepare write commands the write must then be executed or canceled with Execute Write + * command, which if acknowledged by the remote device triggers a Procedure Completed event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPrepareWriteCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x09; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int attHandle; + + /** + * Offset to write to + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int offset; + + /** + * Data to write. Maximum amount of data that can be sent in single command is 18 bytes. + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] data; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle + * + * @param attHandle the attHandle to set as {@link int} + */ + public void setAttHandle(int attHandle) { + this.attHandle = attHandle; + } + /** + * Offset to write to + * + * @param offset the offset to set as {@link int} + */ + public void setOffset(int offset) { + this.offset = offset; + } + /** + * Data to write. Maximum amount of data that can be sent in single command is 18 bytes. + * + * @param data the data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(attHandle); + serializeUInt16(offset); + serializeUInt8Array(data); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPrepareWriteCommand [connection="); + builder.append(connection); + builder.append(", attHandle="); + builder.append(attHandle); + builder.append(", offset="); + builder.append(offset); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteResponse.java new file mode 100644 index 00000000000..5bcd7ee53ff --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaPrepareWriteResponse.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command prepareWrite. + *

+ * This command will send a prepare write request to a remote device for queued writes. Queued + * writes can for example be used to write large attribute values by transmitting the data in + * chunks using prepare write command. Once the data has been transmitted with multiple + * prepare write commands the write must then be executed or canceled with Execute Write + * command, which if acknowledged by the remote device triggers a Procedure Completed event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPrepareWriteResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x09; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaPrepareWriteResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPrepareWriteResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaProcedureCompletedEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaProcedureCompletedEvent.java new file mode 100644 index 00000000000..5b7bf5c3980 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaProcedureCompletedEvent.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command procedureCompletedEvent. + *

+ * This event is produced at the GATT client when an attribute protocol event is completed a and + * new operation can be issued + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaProcedureCompletedEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0: The operation was successful. Otherwise: attribute protocol error code returned by + * remote device + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Characteristic handle at which the event ended + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int chrHandle; + + /** + * Event constructor + */ + public BlueGigaProcedureCompletedEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + chrHandle = deserializeUInt16(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0: The operation was successful. Otherwise: attribute protocol error code returned by + * remote device + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Characteristic handle at which the event ended + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current chr_handle as {@link int} + */ + public int getChrHandle() { + return chrHandle; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaProcedureCompletedEvent [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(", chrHandle="); + builder.append(chrHandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeCommand.java new file mode 100644 index 00000000000..6fe79b8a918 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeCommand.java @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readByGroupType. + *

+ * This command reads the value of each attribute of a given type and in a given handle range. The + * command is typically used for primary (UUID: 0x2800) and secondary (UUID: 0x2801) service + * discovery. Discovered services are reported by Group Found event. Finally when the + * procedure is completed a Procedure Completed event is generated. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByGroupTypeCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * First requested handle number + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int start; + + /** + * Last requested handle number + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int end; + + /** + * Group UUID to find + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + */ + private UUID uuid; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * First requested handle number + * + * @param start the start to set as {@link int} + */ + public void setStart(int start) { + this.start = start; + } + /** + * Last requested handle number + * + * @param end the end to set as {@link int} + */ + public void setEnd(int end) { + this.end = end; + } + /** + * Group UUID to find + * + * @param uuid the uuid to set as {@link UUID} + */ + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(start); + serializeUInt16(end); + serializeUuid(uuid); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByGroupTypeCommand [connection="); + builder.append(connection); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); + builder.append(", uuid="); + builder.append(uuid); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeResponse.java new file mode 100644 index 00000000000..b80c7a92dff --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByGroupTypeResponse.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readByGroupType. + *

+ * This command reads the value of each attribute of a given type and in a given handle range. The + * command is typically used for primary (UUID: 0x2800) and secondary (UUID: 0x2801) service + * discovery. Discovered services are reported by Group Found event. Finally when the + * procedure is completed a Procedure Completed event is generated. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByGroupTypeResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaReadByGroupTypeResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Command result. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByGroupTypeResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleCommand.java new file mode 100644 index 00000000000..e111d2dbc29 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleCommand.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readByHandle. + *

+ * This command reads a remote attribute's value with the given handle. Read by handle can be + * used to read attributes up to 22 bytes long. For longer attributes command must be used. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByHandleCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int chrHandle; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle + * + * @param chrHandle the chrHandle to set as {@link int} + */ + public void setChrHandle(int chrHandle) { + this.chrHandle = chrHandle; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(chrHandle); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByHandleCommand [connection="); + builder.append(connection); + builder.append(", chrHandle="); + builder.append(chrHandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleResponse.java new file mode 100644 index 00000000000..e7f93f86f0c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByHandleResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readByHandle. + *

+ * This command reads a remote attribute's value with the given handle. Read by handle can be + * used to read attributes up to 22 bytes long. For longer attributes command must be used. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByHandleResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaReadByHandleResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByHandleResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeCommand.java new file mode 100644 index 00000000000..6e57ec2d976 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeCommand.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readByType. + *

+ * The command reads the value of each attribute of a given type (UUID) and in a given attribute + * handle range. The command can for example be used to discover the characteristic + * declarations (UUID: 0x2803) within a service. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByTypeCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * First attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int start; + + /** + * Last attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int end; + + /** + * Attribute type (UUID) + *

+ * BlueGiga API type is uuid - Java type is {@link UUID} + */ + private UUID uuid; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * First attribute handle + * + * @param start the start to set as {@link int} + */ + public void setStart(int start) { + this.start = start; + } + /** + * Last attribute handle + * + * @param end the end to set as {@link int} + */ + public void setEnd(int end) { + this.end = end; + } + /** + * Attribute type (UUID) + * + * @param uuid the uuid to set as {@link UUID} + */ + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(start); + serializeUInt16(end); + serializeUuid(uuid); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByTypeCommand [connection="); + builder.append(connection); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); + builder.append(", uuid="); + builder.append(uuid); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeResponse.java new file mode 100644 index 00000000000..234537c64eb --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadByTypeResponse.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readByType. + *

+ * The command reads the value of each attribute of a given type (UUID) and in a given attribute + * handle range. The command can for example be used to discover the characteristic + * declarations (UUID: 0x2803) within a service. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadByTypeResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaReadByTypeResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadByTypeResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongCommand.java new file mode 100644 index 00000000000..dd1ea3650b4 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongCommand.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readLong. + *

+ * This command can be used to read long attribute values, which are longer than 22 bytes and + * cannot be read with a simple Read by Handle command. The command starts a procedure, where the + * client first sends a normal read command to the server and if the returned attribute value + * length is equal to MTU, the client will send further read long read requests until rest of the + * attribute is read. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadLongCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x08; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int chrHandle; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle + * + * @param chrHandle the chrHandle to set as {@link int} + */ + public void setChrHandle(int chrHandle) { + this.chrHandle = chrHandle; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(chrHandle); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadLongCommand [connection="); + builder.append(connection); + builder.append(", chrHandle="); + builder.append(chrHandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongResponse.java new file mode 100644 index 00000000000..47a5439557e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadLongResponse.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readLong. + *

+ * This command can be used to read long attribute values, which are longer than 22 bytes and + * cannot be read with a simple Read by Handle command. The command starts a procedure, where the + * client first sends a normal read command to the server and if the returned attribute value + * length is equal to MTU, the client will send further read long read requests until rest of the + * attribute is read. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadLongResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x08; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaReadLongResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadLongResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleCommand.java new file mode 100644 index 00000000000..01f4da12495 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleCommand.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readMultiple. + *

+ * This command can be used to read multiple attributes from a server. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadMultipleCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x0B; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * List of attribute handles to read from the remote device + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] handles; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * List of attribute handles to read from the remote device + * + * @param handles the handles to set as {@link int[]} + */ + public void setHandles(int[] handles) { + this.handles = handles; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt8Array(handles); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadMultipleCommand [connection="); + builder.append(connection); + builder.append(", handles="); + for (int c = 0; c < handles.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", handles[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponse.java new file mode 100644 index 00000000000..6deaa68e75f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponse.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readMultiple. + *

+ * This command can be used to read multiple attributes from a server. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadMultipleResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x0B; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaReadMultipleResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadMultipleResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponseEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponseEvent.java new file mode 100644 index 00000000000..9f8e8c70299 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaReadMultipleResponseEvent.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command readMultipleResponseEvent. + *

+ * This event is a response to a Read Multiple request. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadMultipleResponseEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * This array contains the concatenated data from the multiple attributes that have been read, + * up to 22 bytes. + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] handles; + + /** + * Event constructor + */ + public BlueGigaReadMultipleResponseEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + handles = deserializeUInt8Array(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * This array contains the concatenated data from the multiple attributes that have been read, + * up to 22 bytes. + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current handles as {@link int[]} + */ + public int[] getHandles() { + return handles; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadMultipleResponseEvent [connection="); + builder.append(connection); + builder.append(", handles="); + for (int c = 0; c < handles.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", handles[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandCommand.java new file mode 100644 index 00000000000..2c345e4c506 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandCommand.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command writeCommand. + *

+ * Writes the value of a remote devices attribute. The handle and the new value of the attribute + * are gives as parameters. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWriteCommandCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x06; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle to write + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int attHandle; + + /** + * Value for the attribute + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] data; + + /** + * Connection handle + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle to write + * + * @param attHandle the attHandle to set as {@link int} + */ + public void setAttHandle(int attHandle) { + this.attHandle = attHandle; + } + /** + * Value for the attribute + * + * @param data the data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(attHandle); + serializeUInt8Array(data); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWriteCommandCommand [connection="); + builder.append(connection); + builder.append(", attHandle="); + builder.append(attHandle); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandResponse.java new file mode 100644 index 00000000000..f563d31d436 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributeclient/BlueGigaWriteCommandResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributeclient; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command writeCommand. + *

+ * Writes the value of a remote devices attribute. The handle and the new value of the attribute + * are gives as parameters. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWriteCommandResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x04; + public static int COMMAND_METHOD = 0x06; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaWriteCommandResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWriteCommandResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaAttributeStatusEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaAttributeStatusEvent.java new file mode 100644 index 00000000000..7030184d874 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaAttributeStatusEvent.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command attributeStatusEvent. + *

+ * This event indicates attribute status flags have changed. For example, this even is + * generated at the module acting as the GATT Server whenever the remote GATT Client changes the + * Client Characteristic Configuration to start or stop notification or indications from the + * Server. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAttributeStatusEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x02; + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Attribute status flags. See: Attribute Status Flags + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int flags; + + /** + * Event constructor + */ + public BlueGigaAttributeStatusEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt16(); + flags = deserializeUInt8(); + } + + /** + * Attribute handle + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Attribute status flags. See: Attribute Status Flags + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current flags as {@link int} + */ + public int getFlags() { + return flags; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaAttributeStatusEvent [handle="); + builder.append(handle); + builder.append(", flags="); + builder.append(flags); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadCommand.java new file mode 100644 index 00000000000..e6f3d5fadad --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadCommand.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command read. + *

+ * The command reads the given attribute's value from the local database. There is a 32-byte + * limit in the amount of data that can be read at a time. In order to read larger values multiple + * read commands must be used with the offset properly used. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x01; + + /** + * Handle of the attribute to read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Offset to read from. Maximum of 32 bytes can be read at a time. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int offset; + + /** + * Handle of the attribute to read + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + /** + * Offset to read from. Maximum of 32 bytes can be read at a time. + * + * @param offset the offset to set as {@link int} + */ + public void setOffset(int offset) { + this.offset = offset; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(handle); + serializeUInt16(offset); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadCommand [handle="); + builder.append(handle); + builder.append(", offset="); + builder.append(offset); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadResponse.java new file mode 100644 index 00000000000..d0f45b87f10 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadResponse.java @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command read. + *

+ * The command reads the given attribute's value from the local database. There is a 32-byte + * limit in the amount of data that can be read at a time. In order to read larger values multiple + * read commands must be used with the offset properly used. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x01; + + /** + * Handle of the attribute which was read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Offset read from + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int offset; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Value of the attribute + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Response constructor + */ + public BlueGigaReadResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt16(); + offset = deserializeUInt16(); + result = deserializeBgApiResponse(); + value = deserializeUInt8Array(); + } + + /** + * Handle of the attribute which was read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Offset read from + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current offset as {@link int} + */ + public int getOffset() { + return offset; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Value of the attribute + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadResponse [handle="); + builder.append(handle); + builder.append(", offset="); + builder.append(offset); + builder.append(", result="); + builder.append(result); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeCommand.java new file mode 100644 index 00000000000..e0243ee4774 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeCommand.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command readType. + *

+ * This command reads the given attribute's type (UUID) from the local database. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadTypeCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x02; + + /** + * Handle of the attribute to read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Handle of the attribute to read + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(handle); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadTypeCommand [handle="); + builder.append(handle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeResponse.java new file mode 100644 index 00000000000..2eee68493cf --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaReadTypeResponse.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command readType. + *

+ * This command reads the given attribute's type (UUID) from the local database. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaReadTypeResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x02; + + /** + * Handle of the attribute which was read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Value of the attribute type (UUID) + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Response constructor + */ + public BlueGigaReadTypeResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt16(); + result = deserializeBgApiResponse(); + value = deserializeUInt8Array(); + } + + /** + * Handle of the attribute which was read + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Value of the attribute type (UUID) + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaReadTypeResponse [handle="); + builder.append(handle); + builder.append(", result="); + builder.append(result); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesCommand.java new file mode 100644 index 00000000000..1be271dc75d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesCommand.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command sendAttributes. + *

+ * This command will send an attribute value, identified by handle, via a notification or an + * indication to a remote device, but does not modify the current corresponding value in the + * local GATT database. If this attribute, identified by handle, does not have notification or + * indication property, or no remote device has registered for notifications or indications + * of this attribute, then an error will be returned. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSendAttributesCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle to send to. Use 0xFF to send to all connected clients which have subscribed + * to receive the notifications or indications. An error is returned as soon as the first failed + * transmission occurs. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle to send. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Data to send + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Connection handle to send to. Use 0xFF to send to all connected clients which have subscribed + * to receive the notifications or indications. An error is returned as soon as the first failed + * transmission occurs. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Attribute handle to send. + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + /** + * Data to send + * + * @param value the value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(handle); + serializeUInt8Array(value); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSendAttributesCommand [connection="); + builder.append(connection); + builder.append(", handle="); + builder.append(handle); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesResponse.java new file mode 100644 index 00000000000..c80e2e951f1 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaSendAttributesResponse.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command sendAttributes. + *

+ * This command will send an attribute value, identified by handle, via a notification or an + * indication to a remote device, but does not modify the current corresponding value in the + * local GATT database. If this attribute, identified by handle, does not have notification or + * indication property, or no remote device has registered for notifications or indications + * of this attribute, then an error will be returned. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSendAttributesResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x02; + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaSendAttributesResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0 : the command was successful. Otherwise an error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSendAttributesResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadRequestEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadRequestEvent.java new file mode 100644 index 00000000000..5c507936753 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadRequestEvent.java @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command userReadRequestEvent. + *

+ * This event is generated when a remote device tries to read an attribute which has the user + * property enabled. This event should be responded within 30 seconds with User Read Response + * command either containing the data or an error code. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUserReadRequestEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection ID which requested attribute + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Attribute handle requested + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Attribute offset to send data from + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int offset; + + /** + * Maximum data size to respond with. If more data is sent than indicated by this parameter, the + * extra bytes will be ignored. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int maxsize; + + /** + * Event constructor + */ + public BlueGigaUserReadRequestEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + handle = deserializeUInt16(); + offset = deserializeUInt16(); + maxsize = deserializeUInt8(); + } + + /** + * Connection ID which requested attribute + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Attribute handle requested + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Attribute offset to send data from + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current offset as {@link int} + */ + public int getOffset() { + return offset; + } + /** + * Maximum data size to respond with. If more data is sent than indicated by this parameter, the + * extra bytes will be ignored. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current maxsize as {@link int} + */ + public int getMaxsize() { + return maxsize; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaUserReadRequestEvent [connection="); + builder.append(connection); + builder.append(", handle="); + builder.append(handle); + builder.append(", offset="); + builder.append(offset); + builder.append(", maxsize="); + builder.append(maxsize); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseCommand.java new file mode 100644 index 00000000000..ec314072f7c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseCommand.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command userReadResponse. + *

+ * This command is used to respond to an attribute Read request by a remote device, but only for + * attributes which have been configured with the user property. Attributes which have the + * user property enabled allow the attribute value to be requested from the application + * instead of the Smart stack automatically responding with Bluetooth the data in it's local + * GATT database. This command is normally used in response to a User Read Request event, which + * is generated when a remote device tries to read an attribute with a user property enabled. The + * response to User Read Request events must happen within 30 seconds or otherwise a timeout + * will occur. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUserReadResponseCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x03; + + /** + * Connection handle to response to. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0: User Read Request is responded with data. In case of an error an application specific error + * code can be sent. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int attError; + + /** + * Data to send + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Connection handle to response to. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * 0: User Read Request is responded with data. In case of an error an application specific error + * code can be sent. + * + * @param attError the attError to set as {@link int} + */ + public void setAttError(int attError) { + this.attError = attError; + } + /** + * Data to send + * + * @param value the value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt8(attError); + serializeUInt8Array(value); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaUserReadResponseCommand [connection="); + builder.append(connection); + builder.append(", attError="); + builder.append(attError); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseResponse.java new file mode 100644 index 00000000000..0597f878786 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserReadResponseResponse.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command userReadResponse. + *

+ * This command is used to respond to an attribute Read request by a remote device, but only for + * attributes which have been configured with the user property. Attributes which have the + * user property enabled allow the attribute value to be requested from the application + * instead of the Smart stack automatically responding with Bluetooth the data in it's local + * GATT database. This command is normally used in response to a User Read Request event, which + * is generated when a remote device tries to read an attribute with a user property enabled. The + * response to User Read Request events must happen within 30 seconds or otherwise a timeout + * will occur. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUserReadResponseResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x03; + + /** + * Response constructor + */ + public BlueGigaUserReadResponseResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaUserReadResponseResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseCommand.java new file mode 100644 index 00000000000..f5c816a93dc --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseCommand.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command userWriteResponse. + *

+ * This command is used by the GATT server to acknowledge to the remote device that the + * attribute's value was written. This feature again allows the user application to + * acknowledged the attribute write operations instead of the Smart stack doing it + * automatically. Bluetooth The command should be used when a event is received where the + * reason why value has changed Value corresponds to + * attributes_attribute_change_reason_write_request_user. This response must be sent + * within 30 seconds or otherwise a timeout will occur. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUserWriteResponseCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle to response to. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0: User Read Request is responded with data. In case of an error an application specific error + * code can be sent. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int attError; + + /** + * Connection handle to response to. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * 0: User Read Request is responded with data. In case of an error an application specific error + * code can be sent. + * + * @param attError the attError to set as {@link int} + */ + public void setAttError(int attError) { + this.attError = attError; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt8(attError); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaUserWriteResponseCommand [connection="); + builder.append(connection); + builder.append(", attError="); + builder.append(attError); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseResponse.java new file mode 100644 index 00000000000..72289f6228e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaUserWriteResponseResponse.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command userWriteResponse. + *

+ * This command is used by the GATT server to acknowledge to the remote device that the + * attribute's value was written. This feature again allows the user application to + * acknowledged the attribute write operations instead of the Smart stack doing it + * automatically. Bluetooth The command should be used when a event is received where the + * reason why value has changed Value corresponds to + * attributes_attribute_change_reason_write_request_user. This response must be sent + * within 30 seconds or otherwise a timeout will occur. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUserWriteResponseResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x04; + + /** + * Response constructor + */ + public BlueGigaUserWriteResponseResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaUserWriteResponseResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaValueEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaValueEvent.java new file mode 100644 index 00000000000..95d02396786 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaValueEvent.java @@ -0,0 +1,158 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.AttributeChangeReason; + +/** + * Class to implement the BlueGiga command valueEvent. + *

+ * This event is produced at the GATT server when a local attribute value was written by a remote + * device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaValueEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Reason why value has changed see: enum Attribute Change Reason + *

+ * BlueGiga API type is AttributeChangeReason - Java type is {@link AttributeChangeReason} + */ + private AttributeChangeReason reason; + + /** + * Attribute handle, which was changed + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Offset into attribute value where data starts + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int offset; + + /** + * Attribute value + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Event constructor + */ + public BlueGigaValueEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + reason = deserializeAttributeChangeReason(); + handle = deserializeUInt16(); + offset = deserializeUInt16(); + value = deserializeUInt8Array(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Reason why value has changed see: enum Attribute Change Reason + *

+ * BlueGiga API type is AttributeChangeReason - Java type is {@link AttributeChangeReason} + * + * @return the current reason as {@link AttributeChangeReason} + */ + public AttributeChangeReason getReason() { + return reason; + } + /** + * Attribute handle, which was changed + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Offset into attribute value where data starts + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current offset as {@link int} + */ + public int getOffset() { + return offset; + } + /** + * Attribute value + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaValueEvent [connection="); + builder.append(connection); + builder.append(", reason="); + builder.append(reason); + builder.append(", handle="); + builder.append(handle); + builder.append(", offset="); + builder.append(offset); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteCommand.java new file mode 100644 index 00000000000..865211ce1d4 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteCommand.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command write. + *

+ * This command writes an attribute's value to the local database. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWriteCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x00; + + /** + * Handle of the attribute to write. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int handle; + + /** + * Attribute offset to write data + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int offset; + + /** + * Value of the attribute to write + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] value; + + /** + * Handle of the attribute to write. + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + /** + * Attribute offset to write data + * + * @param offset the offset to set as {@link int} + */ + public void setOffset(int offset) { + this.offset = offset; + } + /** + * Value of the attribute to write + * + * @param value the value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(handle); + serializeUInt8(offset); + serializeUInt8Array(value); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWriteCommand [handle="); + builder.append(handle); + builder.append(", offset="); + builder.append(offset); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteResponse.java new file mode 100644 index 00000000000..719ac56d984 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/attributedb/BlueGigaWriteResponse.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.attributedb; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command write. + *

+ * This command writes an attribute's value to the local database. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWriteResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x02; + public static int COMMAND_METHOD = 0x00; + + /** + * 0: the write was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaWriteResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: the write was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWriteResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetCommand.java new file mode 100644 index 00000000000..aea6ab44252 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetCommand.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command channelMapGet. + *

+ * This command can be used to read the current Channel Map. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaChannelMapGetCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection handle. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaChannelMapGetCommand [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetResponse.java new file mode 100644 index 00000000000..1f9c2462838 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaChannelMapGetResponse.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command channelMapGet. + *

+ * This command can be used to read the current Channel Map. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaChannelMapGetResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Current Channel Map. Each bit corresponds to one channel. 0-bit corresponds to 0 channel. + * Size of Channel Map is 5 bytes. Channel range: 0-36 + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] map; + + /** + * Response constructor + */ + public BlueGigaChannelMapGetResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + map = deserializeUInt8Array(); + } + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Current Channel Map. Each bit corresponds to one channel. 0-bit corresponds to 0 channel. + * Size of Channel Map is 5 bytes. Channel range: 0-36 + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current map as {@link int[]} + */ + public int[] getMap() { + return map; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaChannelMapGetResponse [connection="); + builder.append(connection); + builder.append(", map="); + for (int c = 0; c < map.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", map[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaConnectionStatusEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaConnectionStatusEvent.java new file mode 100644 index 00000000000..029669d1cba --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaConnectionStatusEvent.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag; + +/** + * Class to implement the BlueGiga command connectionStatusEvent. + *

+ * This event indicates the connection status and parameters. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaConnectionStatusEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection status flags use connstatus-enumerator + *

+ * BlueGiga API type is ConnectionStatusFlag - Java type is {@link ConnectionStatusFlag} + * Parameter allows multiple options so implemented as a {@link Set}. + */ + private Set flags = new HashSet(); + + /** + * Remote devices Bluetooth address + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String address; + + /** + * Remote address type see: Bluetooth Address Types--gap + *

+ * BlueGiga API type is BluetoothAddressType - Java type is {@link BluetoothAddressType} + */ + private BluetoothAddressType addressType; + + /** + * Current connection interval (units of 1.25ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int connInterval; + + /** + * Current supervision timeout (units of 10ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int timeout; + + /** + * Slave latency which tells how many connection intervals the slave may skip. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int latency; + + /** + * Bonding handle if the device has been bonded with. Otherwise: 0xFF + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int bonding; + + /** + * Event constructor + */ + public BlueGigaConnectionStatusEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + flags = deserializeConnectionStatusFlag(); + address = deserializeAddress(); + addressType = deserializeBluetoothAddressType(); + connInterval = deserializeUInt16(); + timeout = deserializeUInt16(); + latency = deserializeUInt16(); + bonding = deserializeUInt8(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Connection status flags use connstatus-enumerator + *

+ * BlueGiga API type is ConnectionStatusFlag - Java type is {@link ConnectionStatusFlag} + * + * @return the current flags as {@link Set} of {@link ConnectionStatusFlag} + */ + public Set getFlags() { + return flags; + } + /** + * Remote devices Bluetooth address + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + * + * @return the current address as {@link String} + */ + public String getAddress() { + return address; + } + /** + * Remote address type see: Bluetooth Address Types--gap + *

+ * BlueGiga API type is BluetoothAddressType - Java type is {@link BluetoothAddressType} + * + * @return the current address_type as {@link BluetoothAddressType} + */ + public BluetoothAddressType getAddressType() { + return addressType; + } + /** + * Current connection interval (units of 1.25ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current conn_interval as {@link int} + */ + public int getConnInterval() { + return connInterval; + } + /** + * Current supervision timeout (units of 10ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current timeout as {@link int} + */ + public int getTimeout() { + return timeout; + } + /** + * Slave latency which tells how many connection intervals the slave may skip. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current latency as {@link int} + */ + public int getLatency() { + return latency; + } + /** + * Bonding handle if the device has been bonded with. Otherwise: 0xFF + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current bonding as {@link int} + */ + public int getBonding() { + return bonding; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaConnectionStatusEvent [connection="); + builder.append(connection); + builder.append(", flags="); + builder.append(flags); + builder.append(", address="); + builder.append(address); + builder.append(", addressType="); + builder.append(addressType); + builder.append(", connInterval="); + builder.append(connInterval); + builder.append(", timeout="); + builder.append(timeout); + builder.append(", latency="); + builder.append(latency); + builder.append(", bonding="); + builder.append(bonding); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectCommand.java new file mode 100644 index 00000000000..3b5c2f9eb92 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectCommand.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command disconnect. + *

+ * This command disconnects an active connection. Bluetooth When link is disconnected a + * Disconnected event is produced. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDisconnectCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle to close. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection handle to close. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDisconnectCommand [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectResponse.java new file mode 100644 index 00000000000..ea994dce85b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectResponse.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command disconnect. + *

+ * This command disconnects an active connection. Bluetooth When link is disconnected a + * Disconnected event is produced. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDisconnectResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the update was successful. Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaDisconnectResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the update was successful. Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDisconnectResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectedEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectedEvent.java new file mode 100644 index 00000000000..d8771b97d1e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaDisconnectedEvent.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command disconnectedEvent. + *

+ * This event is produced when a connection is disconnected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDisconnectedEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Disconnection reason code. 0 : disconnected by local user + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse reason; + + /** + * Event constructor + */ + public BlueGigaDisconnectedEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + reason = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Disconnection reason code. 0 : disconnected by local user + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current reason as {@link BgApiResponse} + */ + public BgApiResponse getReason() { + return reason; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDisconnectedEvent [connection="); + builder.append(connection); + builder.append(", reason="); + builder.append(reason); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaFeatureIndEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaFeatureIndEvent.java new file mode 100644 index 00000000000..e56a5b4a2d5 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaFeatureIndEvent.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command featureIndEvent. + *

+ * This event indicates the remote devices features. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaFeatureIndEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * CtrData field from LL_FEATURE_RSP - packet + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] features; + + /** + * Event constructor + */ + public BlueGigaFeatureIndEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + features = deserializeUInt8Array(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * CtrData field from LL_FEATURE_RSP - packet + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current features as {@link int[]} + */ + public int[] getFeatures() { + return features; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaFeatureIndEvent [connection="); + builder.append(connection); + builder.append(", features="); + for (int c = 0; c < features.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", features[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiCommand.java new file mode 100644 index 00000000000..c866f0c195d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiCommand.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getRssi. + *

+ * This command disconnects an active connection. Bluetooth When link is disconnected a + * Disconnected event is produced. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetRssiCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle to close. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection handle to close. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetRssiCommand [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiResponse.java new file mode 100644 index 00000000000..362cb8ba0ba --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetRssiResponse.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getRssi. + *

+ * This command disconnects an active connection. Bluetooth When link is disconnected a + * Disconnected event is produced. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetRssiResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * RSSI value of the connection in dBm. Range: -103 to -38 + *

+ * BlueGiga API type is int8 - Java type is {@link int} + */ + private int rssi; + + /** + * Response constructor + */ + public BlueGigaGetRssiResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + rssi = deserializeInt8(); + } + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * RSSI value of the connection in dBm. Range: -103 to -38 + *

+ * BlueGiga API type is int8 - Java type is {@link int} + * + * @return the current rssi as {@link int} + */ + public int getRssi() { + return rssi; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetRssiResponse [connection="); + builder.append(connection); + builder.append(", rssi="); + builder.append(rssi); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusCommand.java new file mode 100644 index 00000000000..f62ac7f44db --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusCommand.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getStatus. + *

+ * This command returns the status of the given connection. Status is returned in a event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetStatusCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x07; + + /** + * Connection handle to close. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Connection handle to close. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetStatusCommand [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusResponse.java new file mode 100644 index 00000000000..03bac93da93 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaGetStatusResponse.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getStatus. + *

+ * This command returns the status of the given connection. Status is returned in a event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetStatusResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x07; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Response constructor + */ + public BlueGigaGetStatusResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + } + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetStatusResponse [connection="); + builder.append(connection); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateCommand.java new file mode 100644 index 00000000000..5adc9912d1c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateCommand.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command update. + *

+ * This command updates the connection parameters of a given connection. The parameters have + * the same meaning and follow the same rules as for the GAP class command: Connect Direct. If + * this command is issued at a master device, it will send parameter update request to the link + * layer. Bluetooth On the other hand if this command is issued at a slave device, it will send + * L2CAP connection parameter update request to the master, which may either accept or reject + * it. It will take an amount of time corresponding to at least six times the current connection + * interval before the new connection parameters will become active. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUpdateCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Minimum connection interval (units of 1.25ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int intervalMin; + + /** + * Maximum connection interval (units of 1.25ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int intervalMax; + + /** + * Slave latency which defines how many connections intervals a slave may skip. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int latency; + + /** + * Supervision timeout (units of 10ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int timeout; + + /** + * Connection handle. + * + * @param connection the connection to set as {@link int} + */ + public void setConnection(int connection) { + this.connection = connection; + } + /** + * Minimum connection interval (units of 1.25ms) + * + * @param intervalMin the intervalMin to set as {@link int} + */ + public void setIntervalMin(int intervalMin) { + this.intervalMin = intervalMin; + } + /** + * Maximum connection interval (units of 1.25ms) + * + * @param intervalMax the intervalMax to set as {@link int} + */ + public void setIntervalMax(int intervalMax) { + this.intervalMax = intervalMax; + } + /** + * Slave latency which defines how many connections intervals a slave may skip. + * + * @param latency the latency to set as {@link int} + */ + public void setLatency(int latency) { + this.latency = latency; + } + /** + * Supervision timeout (units of 10ms) + * + * @param timeout the timeout to set as {@link int} + */ + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(connection); + serializeUInt16(intervalMin); + serializeUInt16(intervalMax); + serializeUInt16(latency); + serializeUInt16(timeout); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaUpdateCommand [connection="); + builder.append(connection); + builder.append(", intervalMin="); + builder.append(intervalMin); + builder.append(", intervalMax="); + builder.append(intervalMax); + builder.append(", latency="); + builder.append(latency); + builder.append(", timeout="); + builder.append(timeout); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateResponse.java new file mode 100644 index 00000000000..a5f38582c8c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaUpdateResponse.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command update. + *

+ * This command updates the connection parameters of a given connection. The parameters have + * the same meaning and follow the same rules as for the GAP class command: Connect Direct. If + * this command is issued at a master device, it will send parameter update request to the link + * layer. Bluetooth On the other hand if this command is issued at a slave device, it will send + * L2CAP connection parameter update request to the master, which may either accept or reject + * it. It will take an amount of time corresponding to at least six times the current connection + * interval before the new connection parameters will become active. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaUpdateResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x02; + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * 0 : the update was successful. Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaUpdateResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle. + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * 0 : the update was successful. Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaUpdateResponse [connection="); + builder.append(connection); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaVersionIndEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaVersionIndEvent.java new file mode 100644 index 00000000000..3b65257a73c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/connection/BlueGigaVersionIndEvent.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.connection; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command versionIndEvent. + *

+ * This event indicates the remote devices version. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaVersionIndEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x03; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connection; + + /** + * Bluetooth controller specification version + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int versNr; + + /** + * Manufacturer of the controller + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int compId; + + /** + * Bluetooth controller version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int subVersNr; + + /** + * Event constructor + */ + public BlueGigaVersionIndEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + connection = deserializeUInt8(); + versNr = deserializeUInt8(); + compId = deserializeUInt16(); + subVersNr = deserializeUInt16(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection as {@link int} + */ + public int getConnection() { + return connection; + } + /** + * Bluetooth controller specification version + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current vers_nr as {@link int} + */ + public int getVersNr() { + return versNr; + } + /** + * Manufacturer of the controller + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current comp_id as {@link int} + */ + public int getCompId() { + return compId; + } + /** + * Bluetooth controller version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current sub_vers_nr as {@link int} + */ + public int getSubVersNr() { + return subVersNr; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaVersionIndEvent [connection="); + builder.append(connection); + builder.append(", versNr="); + builder.append(versNr); + builder.append(", compId="); + builder.append(compId); + builder.append(", subVersNr="); + builder.append(subVersNr); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectCommand.java new file mode 100644 index 00000000000..2bd80f17910 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectCommand.java @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; + +/** + * Class to implement the BlueGiga command connectDirect. + *

+ * This command will start the GAP direct connection establishment procedure to a dedicated + * Smart Bluetooth device. The module will enter a state where it continuously scans for the + * connectable advertisement packets Bluetooth from the remote device which matches the + * Bluetooth address gives as a parameter. Upon receiving the advertisement packet, the + * module will send a connection request packet to the target device to imitate a Bluetooth + * connection. A successful connection will bi indicated by a event. Status If the device is + * configured to support more than one connection, the smallest connection interval which is + * divisible by maximum_connections * 2.5ms will be selected. Thus, it is important to provide + * minimum and maximum connection intervals so that such a connection interval is available + * within the range. The connection establishment procedure can be cancelled with End + * Procedure command. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaConnectDirectCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x03; + + /** + * Bluetooth address of the target device. + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String address; + + /** + * see: Bluetooth Address Types. + *

+ * BlueGiga API type is BluetoothAddressType - Java type is {@link BluetoothAddressType} + */ + private BluetoothAddressType addrType; + + /** + * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible + * Connection Interval is 7.50ms and the largest is 4000ms. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int connIntervalMin; + + /** + * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than + * minimum Connection Interval. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int connIntervalMax; + + /** + * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the + * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for + * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the + * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) * + * conn_interval_max * 2, where conn_interval_max is given in milliseconds. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int timeout; + + /** + * This parameter configures the slave latency. Slave latency defines how many connection + * intervals a slave device can skip. Increasing slave latency will decrease the energy + * consumption of the slave in scenarios where slave does not have data to send at every + * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection + * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate + * every 100ms, but it can communicate every 10ms if needed. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int latency; + + /** + * Bluetooth address of the target device. + * + * @param address the address to set as {@link String} + */ + public void setAddress(String address) { + this.address = address; + } + /** + * see: Bluetooth Address Types. + * + * @param addrType the addrType to set as {@link BluetoothAddressType} + */ + public void setAddrType(BluetoothAddressType addrType) { + this.addrType = addrType; + } + /** + * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible + * Connection Interval is 7.50ms and the largest is 4000ms. + * + * @param connIntervalMin the connIntervalMin to set as {@link int} + */ + public void setConnIntervalMin(int connIntervalMin) { + this.connIntervalMin = connIntervalMin; + } + /** + * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than + * minimum Connection Interval. + * + * @param connIntervalMax the connIntervalMax to set as {@link int} + */ + public void setConnIntervalMax(int connIntervalMax) { + this.connIntervalMax = connIntervalMax; + } + /** + * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the + * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for + * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the + * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) * + * conn_interval_max * 2, where conn_interval_max is given in milliseconds. + * + * @param timeout the timeout to set as {@link int} + */ + public void setTimeout(int timeout) { + this.timeout = timeout; + } + /** + * This parameter configures the slave latency. Slave latency defines how many connection + * intervals a slave device can skip. Increasing slave latency will decrease the energy + * consumption of the slave in scenarios where slave does not have data to send at every + * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection + * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate + * every 100ms, but it can communicate every 10ms if needed. + * + * @param latency the latency to set as {@link int} + */ + public void setLatency(int latency) { + this.latency = latency; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeAddress(address); + serializeBluetoothAddressType(addrType); + serializeUInt16(connIntervalMin); + serializeUInt16(connIntervalMax); + serializeUInt16(timeout); + serializeUInt16(latency); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaConnectDirectCommand [address="); + builder.append(address); + builder.append(", addrType="); + builder.append(addrType); + builder.append(", connIntervalMin="); + builder.append(connIntervalMin); + builder.append(", connIntervalMax="); + builder.append(connIntervalMax); + builder.append(", timeout="); + builder.append(timeout); + builder.append(", latency="); + builder.append(latency); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectResponse.java new file mode 100644 index 00000000000..5189a20232c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectDirectResponse.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command connectDirect. + *

+ * This command will start the GAP direct connection establishment procedure to a dedicated + * Smart Bluetooth device. The module will enter a state where it continuously scans for the + * connectable advertisement packets Bluetooth from the remote device which matches the + * Bluetooth address gives as a parameter. Upon receiving the advertisement packet, the + * module will send a connection request packet to the target device to imitate a Bluetooth + * connection. A successful connection will bi indicated by a event. Status If the device is + * configured to support more than one connection, the smallest connection interval which is + * divisible by maximum_connections * 2.5ms will be selected. Thus, it is important to provide + * minimum and maximum connection intervals so that such a connection interval is available + * within the range. The connection establishment procedure can be cancelled with End + * Procedure command. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaConnectDirectResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x03; + + /** + * 0 : procedure was successfully started Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Connection handle that is reserved for new connection + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connectionHandle; + + /** + * Response constructor + */ + public BlueGigaConnectDirectResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + connectionHandle = deserializeUInt8(); + } + + /** + * 0 : procedure was successfully started Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Connection handle that is reserved for new connection + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection_handle as {@link int} + */ + public int getConnectionHandle() { + return connectionHandle; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaConnectDirectResponse [result="); + builder.append(result); + builder.append(", connectionHandle="); + builder.append(connectionHandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveCommand.java new file mode 100644 index 00000000000..2c99378dd0a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveCommand.java @@ -0,0 +1,150 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command connectSelective. + *

+ * This command will start the GAP direct connection establishment procedure to a set of + * dedicated Bluetooth Smart devices. When this command is issued the the module will enter a + * state where it scans connectable Bluetooth advertisement packets from the remote devices + * which are registered in the local white list. Upon receiving an advertisement packet from + * one of the registered devices, the module will send a connection request to this device, and a + * successful connection will produce a connection status event. The connect selective + * command can be cancelled with End Procedure command. When in Initiating State there are no + * scan response events. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaConnectSelectiveCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x05; + + /** + * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible + * Connection Interval is 7.50ms and the largest is 4000ms. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int connIntervalMin; + + /** + * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than + * minimum Connection Interval. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int connIntervalMax; + + /** + * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the + * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for + * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the + * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) * + * conn_interval_max * 2, where conn_interval_max is given in milliseconds. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int timeout; + + /** + * This parameter configures the slave latency. Slave latency defines how many connection + * intervals a slave device can skip. Increasing slave latency will decrease the energy + * consumption of the slave in scenarios where slave does not have data to send at every + * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection + * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate + * every 100ms, but it can communicate every 10ms if needed. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int latency; + + /** + * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible + * Connection Interval is 7.50ms and the largest is 4000ms. + * + * @param connIntervalMin the connIntervalMin to set as {@link int} + */ + public void setConnIntervalMin(int connIntervalMin) { + this.connIntervalMin = connIntervalMin; + } + /** + * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than + * minimum Connection Interval. + * + * @param connIntervalMax the connIntervalMax to set as {@link int} + */ + public void setConnIntervalMax(int connIntervalMax) { + this.connIntervalMax = connIntervalMax; + } + /** + * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the + * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for + * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the + * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) * + * conn_interval_max * 2, where conn_interval_max is given in milliseconds. + * + * @param timeout the timeout to set as {@link int} + */ + public void setTimeout(int timeout) { + this.timeout = timeout; + } + /** + * This parameter configures the slave latency. Slave latency defines how many connection + * intervals a slave device can skip. Increasing slave latency will decrease the energy + * consumption of the slave in scenarios where slave does not have data to send at every + * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection + * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate + * every 100ms, but it can communicate every 10ms if needed. + * + * @param latency the latency to set as {@link int} + */ + public void setLatency(int latency) { + this.latency = latency; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(connIntervalMin); + serializeUInt16(connIntervalMax); + serializeUInt16(timeout); + serializeUInt16(latency); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaConnectSelectiveCommand [connIntervalMin="); + builder.append(connIntervalMin); + builder.append(", connIntervalMax="); + builder.append(connIntervalMax); + builder.append(", timeout="); + builder.append(timeout); + builder.append(", latency="); + builder.append(latency); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveResponse.java new file mode 100644 index 00000000000..6ab1282249e --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaConnectSelectiveResponse.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command connectSelective. + *

+ * This command will start the GAP direct connection establishment procedure to a set of + * dedicated Bluetooth Smart devices. When this command is issued the the module will enter a + * state where it scans connectable Bluetooth advertisement packets from the remote devices + * which are registered in the local white list. Upon receiving an advertisement packet from + * one of the registered devices, the module will send a connection request to this device, and a + * successful connection will produce a connection status event. The connect selective + * command can be cancelled with End Procedure command. When in Initiating State there are no + * scan response events. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaConnectSelectiveResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x05; + + /** + * 0 : procedure was successfully started Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Connection handle that is reserved for new connection + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int connectionHandle; + + /** + * Response constructor + */ + public BlueGigaConnectSelectiveResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + connectionHandle = deserializeUInt8(); + } + + /** + * 0 : procedure was successfully started Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Connection handle that is reserved for new connection + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current connection_handle as {@link int} + */ + public int getConnectionHandle() { + return connectionHandle; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaConnectSelectiveResponse [result="); + builder.append(result); + builder.append(", connectionHandle="); + builder.append(connectionHandle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverCommand.java new file mode 100644 index 00000000000..e3c44bb008d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverCommand.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode; + +/** + * Class to implement the BlueGiga command discover. + *

+ * This command starts the GAP discovery procedure to scan for advertising devices i.e. to + * perform a device discovery. Scanning parameters can be configured with the Set Scan + * Parameters command before issuing this command. To cancel on an ongoing discovery process + * use the End Procedure command. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDiscoverCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x02; + + /** + * see:GAP Discover Mode. + *

+ * BlueGiga API type is GapDiscoverMode - Java type is {@link GapDiscoverMode} + */ + private GapDiscoverMode mode; + + /** + * see:GAP Discover Mode. + * + * @param mode the mode to set as {@link GapDiscoverMode} + */ + public void setMode(GapDiscoverMode mode) { + this.mode = mode; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeGapDiscoverMode(mode); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDiscoverCommand [mode="); + builder.append(mode); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverResponse.java new file mode 100644 index 00000000000..d6cc13af393 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaDiscoverResponse.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command discover. + *

+ * This command starts the GAP discovery procedure to scan for advertising devices i.e. to + * perform a device discovery. Scanning parameters can be configured with the Set Scan + * Parameters command before issuing this command. To cancel on an ongoing discovery process + * use the End Procedure command. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDiscoverResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x02; + + /** + * 0: Scan procedure was successfully started Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaDiscoverResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: Scan procedure was successfully started Non-zero: An error occurred. + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDiscoverResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureCommand.java new file mode 100644 index 00000000000..29923350404 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureCommand.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command endProcedure. + *

+ * This command ends the current GAP discovery procedure and stop the scanning of advertising + * devices. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEndProcedureCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x04; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaEndProcedureCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureResponse.java new file mode 100644 index 00000000000..93f603c1ec1 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaEndProcedureResponse.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command endProcedure. + *

+ * This command ends the current GAP discovery procedure and stop the scanning of advertising + * devices. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEndProcedureResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x04; + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaEndProcedureResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaEndProcedureResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaScanResponseEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaScanResponseEvent.java new file mode 100644 index 00000000000..72b5607e6e3 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaScanResponseEvent.java @@ -0,0 +1,181 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.ScanResponseType; + +/** + * Class to implement the BlueGiga command scanResponseEvent. + *

+ * This is a scan response event. This event is normally received by a Master which is scanning + * for advertisement and scan response packets from Slaves. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaScanResponseEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x00; + + /** + * RSSI value (dBm). Range: -103 to -38 + *

+ * BlueGiga API type is int8 - Java type is {@link int} + */ + private int rssi; + + /** + * Scan response header. 0: Connectable Advertisement packet. 2: Non Connectable + * Advertisement packet. 4: Scan response packet. 6: Discoverable advertisement packet + *

+ * BlueGiga API type is ScanResponseType - Java type is {@link ScanResponseType} + */ + private ScanResponseType packetType; + + /** + * Advertisers address + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String sender; + + /** + * Advertiser address type. 1: random address. 0: public address + *

+ * BlueGiga API type is BluetoothAddressType - Java type is {@link BluetoothAddressType} + */ + private BluetoothAddressType addressType; + + /** + * Bond handle if there is known bond for this device, 0xff otherwise + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int bond; + + /** + * Scan response data + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] data; + + /** + * Event constructor + */ + public BlueGigaScanResponseEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + rssi = deserializeInt8(); + packetType = deserializeScanResponseType(); + sender = deserializeAddress(); + addressType = deserializeBluetoothAddressType(); + bond = deserializeUInt8(); + data = deserializeUInt8Array(); + } + + /** + * RSSI value (dBm). Range: -103 to -38 + *

+ * BlueGiga API type is int8 - Java type is {@link int} + * + * @return the current rssi as {@link int} + */ + public int getRssi() { + return rssi; + } + /** + * Scan response header. 0: Connectable Advertisement packet. 2: Non Connectable + * Advertisement packet. 4: Scan response packet. 6: Discoverable advertisement packet + *

+ * BlueGiga API type is ScanResponseType - Java type is {@link ScanResponseType} + * + * @return the current packet_type as {@link ScanResponseType} + */ + public ScanResponseType getPacketType() { + return packetType; + } + /** + * Advertisers address + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + * + * @return the current sender as {@link String} + */ + public String getSender() { + return sender; + } + /** + * Advertiser address type. 1: random address. 0: public address + *

+ * BlueGiga API type is BluetoothAddressType - Java type is {@link BluetoothAddressType} + * + * @return the current address_type as {@link BluetoothAddressType} + */ + public BluetoothAddressType getAddressType() { + return addressType; + } + /** + * Bond handle if there is known bond for this device, 0xff otherwise + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current bond as {@link int} + */ + public int getBond() { + return bond; + } + /** + * Scan response data + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + * + * @return the current data as {@link int[]} + */ + public int[] getData() { + return data; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaScanResponseEvent [rssi="); + builder.append(rssi); + builder.append(", packetType="); + builder.append(packetType); + builder.append(", sender="); + builder.append(sender); + builder.append(", addressType="); + builder.append(addressType); + builder.append(", bond="); + builder.append(bond); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataCommand.java new file mode 100644 index 00000000000..96c2b066a65 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataCommand.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command setAdvData. + *

+ * This commands set advertisement or scan response data used in the advertisement and scan + * response packets. The command allows application specific data to be broadcasts either in + * advertisement or scan response packets. The data set with this command is only used when the + * GAP discoverable mode is set to gap_user_data. Notice that advertisement or scan response + * data must be formatted in accordance to the Bluetooth Core Specification. See BLUETOOTH + * SPECIFICATION Version 4.0 [Vol 3 - Part C - Chapter 11]. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetAdvDataCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x09; + + /** + * Advertisement data type. 0 : sets advertisement data. 1 : sets scan response data + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int setScanrsp; + + /** + * Advertisement data to send + *

+ * BlueGiga API type is uint8array - Java type is {@link int[]} + */ + private int[] advData; + + /** + * Advertisement data type. 0 : sets advertisement data. 1 : sets scan response data + * + * @param setScanrsp the setScanrsp to set as {@link int} + */ + public void setSetScanrsp(int setScanrsp) { + this.setScanrsp = setScanrsp; + } + /** + * Advertisement data to send + * + * @param advData the advData to set as {@link int[]} + */ + public void setAdvData(int[] advData) { + this.advData = advData; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(setScanrsp); + serializeUInt8Array(advData); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetAdvDataCommand [setScanrsp="); + builder.append(setScanrsp); + builder.append(", advData="); + for (int c = 0; c < advData.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", advData[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataResponse.java new file mode 100644 index 00000000000..9476f807463 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvDataResponse.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command setAdvData. + *

+ * This commands set advertisement or scan response data used in the advertisement and scan + * response packets. The command allows application specific data to be broadcasts either in + * advertisement or scan response packets. The data set with this command is only used when the + * GAP discoverable mode is set to gap_user_data. Notice that advertisement or scan response + * data must be formatted in accordance to the Bluetooth Core Specification. See BLUETOOTH + * SPECIFICATION Version 4.0 [Vol 3 - Part C - Chapter 11]. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetAdvDataResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x09; + + /** + * 0: Command was successfully executed. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaSetAdvDataResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: Command was successfully executed. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetAdvDataResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersCommand.java new file mode 100644 index 00000000000..d01ee607dcd --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersCommand.java @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command setAdvParameters. + *

+ * This command is used to set the advertising parameters. Example: If the minimum + * advertisement interval is 40ms and the maximum advertisement interval is 100ms then the + * real advertisement interval will be mostly the middle value (70ms) plus a randomly added + * 20ms delay, which needs to be added according to the Bluetooth specification. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetAdvParametersCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x08; + + /** + * Minimum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200 + * (320ms) Explanation: 0x200 = 512 512 * 625us = 320000us = 320ms + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int advIntervalMin; + + /** + * Maximum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200 + * (320ms) + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int advIntervalMax; + + /** + * A bit mask to identify which of the three advertisement channels are used. Examples: 0x07: + * All three channels are used 0x03: Advertisement channels 37 and 38 are used. 0x04: Only + * advertisement channel 39 is used + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int advChannels; + + /** + * Minimum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200 + * (320ms) Explanation: 0x200 = 512 512 * 625us = 320000us = 320ms + * + * @param advIntervalMin the advIntervalMin to set as {@link int} + */ + public void setAdvIntervalMin(int advIntervalMin) { + this.advIntervalMin = advIntervalMin; + } + /** + * Maximum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200 + * (320ms) + * + * @param advIntervalMax the advIntervalMax to set as {@link int} + */ + public void setAdvIntervalMax(int advIntervalMax) { + this.advIntervalMax = advIntervalMax; + } + /** + * A bit mask to identify which of the three advertisement channels are used. Examples: 0x07: + * All three channels are used 0x03: Advertisement channels 37 and 38 are used. 0x04: Only + * advertisement channel 39 is used + * + * @param advChannels the advChannels to set as {@link int} + */ + public void setAdvChannels(int advChannels) { + this.advChannels = advChannels; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(advIntervalMin); + serializeUInt16(advIntervalMax); + serializeUInt8(advChannels); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetAdvParametersCommand [advIntervalMin="); + builder.append(advIntervalMin); + builder.append(", advIntervalMax="); + builder.append(advIntervalMax); + builder.append(", advChannels="); + builder.append(advChannels); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersResponse.java new file mode 100644 index 00000000000..e02a3f5752a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetAdvParametersResponse.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command setAdvParameters. + *

+ * This command is used to set the advertising parameters. Example: If the minimum + * advertisement interval is 40ms and the maximum advertisement interval is 100ms then the + * real advertisement interval will be mostly the middle value (70ms) plus a randomly added + * 20ms delay, which needs to be added according to the Bluetooth specification. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetAdvParametersResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x08; + + /** + * 0: Command was successfully executed. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaSetAdvParametersResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: Command was successfully executed. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetAdvParametersResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeCommand.java new file mode 100644 index 00000000000..accc3c3cf16 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeCommand.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode; + +/** + * Class to implement the BlueGiga command setMode. + *

+ * This command configures the current GAP discoverability and connectability modes. It can + * be used to enable advertisements and/or allow connection. The command is also meant to fully + * stop advertising, when using gap_non_discoverable and gap_non_connectable. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetModeCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x01; + + /** + * see:GAP Discoverable Mode + *

+ * BlueGiga API type is GapDiscoverableMode - Java type is {@link GapDiscoverableMode} + */ + private GapDiscoverableMode discover; + + /** + * see:GAP Connectable Mode + *

+ * BlueGiga API type is GapConnectableMode - Java type is {@link GapConnectableMode} + */ + private GapConnectableMode connect; + + /** + * see:GAP Discoverable Mode + * + * @param discover the discover to set as {@link GapDiscoverableMode} + */ + public void setDiscover(GapDiscoverableMode discover) { + this.discover = discover; + } + /** + * see:GAP Connectable Mode + * + * @param connect the connect to set as {@link GapConnectableMode} + */ + public void setConnect(GapConnectableMode connect) { + this.connect = connect; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeGapDiscoverableMode(discover); + serializeGapConnectableMode(connect); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetModeCommand [discover="); + builder.append(discover); + builder.append(", connect="); + builder.append(connect); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeResponse.java new file mode 100644 index 00000000000..82a27c32331 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetModeResponse.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command setMode. + *

+ * This command configures the current GAP discoverability and connectability modes. It can + * be used to enable advertisements and/or allow connection. The command is also meant to fully + * stop advertising, when using gap_non_discoverable and gap_non_connectable. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetModeResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x01; + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaSetModeResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetModeResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersCommand.java new file mode 100644 index 00000000000..7c000e680e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersCommand.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command setScanParameters. + *

+ * This command sets the scan parameters which affect how other Smart devices are discovered. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetScanParametersCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x07; + + /** + * Scan interval defines the interval when scanning is re-started in units of 625us. Range: 0x4 + * - 0x4000. Default: (46,875ms) 0x4B After every scan interval the scanner will change the + * frequency it operates at at it will cycle through all the three advertisements channels in a + * round robin fashion. According to the specification all three channels must be Bluetooth + * used by a scanner. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int scanInterval; + + /** + * Scan Window defines how long time the scanner will listen on a certain frequency and try to + * pick up advertisement packets. Scan window is defined as units of 625us. Range: 0x4 - 0x4000. + * Default: 0x32 (31,25 ms). Scan windows must be equal or smaller than scan interval If scan + * window is equal to the scan interval value, then the module Bluetooth will be scanning at a + * 100% duty cycle. If scan window is half of the scan interval value, then the module Bluetooth + * will be scanning at a 50% duty cycle. + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int scanWindow; + + /** + * 1: Active scanning is used. When an advertisement packet is received the Bluetooth stack + * will send a scan request packet to the advertiser to try and read the scan response data. 0: + * Passive scanning is used. No scan request is made. + *

+ * BlueGiga API type is boolean - Java type is {@link boolean} + */ + private boolean activeScanning; + + /** + * Scan interval defines the interval when scanning is re-started in units of 625us. Range: 0x4 + * - 0x4000. Default: (46,875ms) 0x4B After every scan interval the scanner will change the + * frequency it operates at at it will cycle through all the three advertisements channels in a + * round robin fashion. According to the specification all three channels must be Bluetooth + * used by a scanner. + * + * @param scanInterval the scanInterval to set as {@link int} + */ + public void setScanInterval(int scanInterval) { + this.scanInterval = scanInterval; + } + /** + * Scan Window defines how long time the scanner will listen on a certain frequency and try to + * pick up advertisement packets. Scan window is defined as units of 625us. Range: 0x4 - 0x4000. + * Default: 0x32 (31,25 ms). Scan windows must be equal or smaller than scan interval If scan + * window is equal to the scan interval value, then the module Bluetooth will be scanning at a + * 100% duty cycle. If scan window is half of the scan interval value, then the module Bluetooth + * will be scanning at a 50% duty cycle. + * + * @param scanWindow the scanWindow to set as {@link int} + */ + public void setScanWindow(int scanWindow) { + this.scanWindow = scanWindow; + } + /** + * 1: Active scanning is used. When an advertisement packet is received the Bluetooth stack + * will send a scan request packet to the advertiser to try and read the scan response data. 0: + * Passive scanning is used. No scan request is made. + * + * @param activeScanning the activeScanning to set as {@link boolean} + */ + public void setActiveScanning(boolean activeScanning) { + this.activeScanning = activeScanning; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt16(scanInterval); + serializeUInt16(scanWindow); + serializeBoolean(activeScanning); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetScanParametersCommand [scanInterval="); + builder.append(scanInterval); + builder.append(", scanWindow="); + builder.append(scanWindow); + builder.append(", activeScanning="); + builder.append(activeScanning); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersResponse.java new file mode 100644 index 00000000000..016350c3eb2 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/gap/BlueGigaSetScanParametersResponse.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.gap; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command setScanParameters. + *

+ * This command sets the scan parameters which affect how other Smart devices are discovered. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetScanParametersResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x06; + public static int COMMAND_METHOD = 0x07; + + /** + * 0: The command was executed successfully. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaSetScanParametersResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: The command was executed successfully. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetScanParametersResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondStatusEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondStatusEvent.java new file mode 100644 index 00000000000..9ca01b967e0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondStatusEvent.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command bondStatusEvent. + *

+ * This event outputs bonding status information. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaBondStatusEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x04; + + /** + * Bonding handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int bond; + + /** + * Encryption key size used in long-term key + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int keysize; + + /** + * Was Man-in-the-Middle mode was used in pairing. 0: No MITM used. 1: MITM was used + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int mitm; + + /** + * Keys stored for bonding. See: Bonding Keys + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int keys; + + /** + * Event constructor + */ + public BlueGigaBondStatusEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + bond = deserializeUInt8(); + keysize = deserializeUInt8(); + mitm = deserializeUInt8(); + keys = deserializeUInt8(); + } + + /** + * Bonding handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current bond as {@link int} + */ + public int getBond() { + return bond; + } + /** + * Encryption key size used in long-term key + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current keysize as {@link int} + */ + public int getKeysize() { + return keysize; + } + /** + * Was Man-in-the-Middle mode was used in pairing. 0: No MITM used. 1: MITM was used + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current mitm as {@link int} + */ + public int getMitm() { + return mitm; + } + /** + * Keys stored for bonding. See: Bonding Keys + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current keys as {@link int} + */ + public int getKeys() { + return keys; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaBondStatusEvent [bond="); + builder.append(bond); + builder.append(", keysize="); + builder.append(keysize); + builder.append(", mitm="); + builder.append(mitm); + builder.append(", keys="); + builder.append(keys); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondingFailEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondingFailEvent.java new file mode 100644 index 00000000000..e511edea45d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaBondingFailEvent.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command bondingFailEvent. + *

+ * This event indicates the bonding has failed for a connection. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaBondingFailEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x01; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Encryption status, describes error that occurred during bonding. See: Security Manager + * Protocol Errors + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Event constructor + */ + public BlueGigaBondingFailEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Encryption status, describes error that occurred during bonding. See: Security Manager + * Protocol Errors + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaBondingFailEvent [handle="); + builder.append(handle); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingCommand.java new file mode 100644 index 00000000000..2691ec9bb63 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingCommand.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command deleteBonding. + *

+ * This command deletes a bonding from the local security database. There can be a maximum of 8 + * bonded devices stored at the same time, and one of them must be deleted if you need bonding with + * a 9th device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDeleteBondingCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x02; + + /** + * Bonding handle of a device. This handle can be obtained for example from events like: Scan + * Response Status - If handle is 0xFF, all bondings will be deleted + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Bonding handle of a device. This handle can be obtained for example from events like: Scan + * Response Status - If handle is 0xFF, all bondings will be deleted + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(handle); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDeleteBondingCommand [handle="); + builder.append(handle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingResponse.java new file mode 100644 index 00000000000..2c107f0d6ff --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaDeleteBondingResponse.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command deleteBonding. + *

+ * This command deletes a bonding from the local security database. There can be a maximum of 8 + * bonded devices stored at the same time, and one of them must be deleted if you need bonding with + * a 9th device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaDeleteBondingResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x02; + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaDeleteBondingResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * 0: the command was successful. Non-zero: An error occurred + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaDeleteBondingResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartCommand.java new file mode 100644 index 00000000000..31aad7abd75 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartCommand.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command encryptStart. + *

+ * This command starts the encryption for a given connection. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEncryptStartCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x00; + + /** + * Bonding handle of a device. This handle can be obtained for example from events like: Scan + * Response Status - If handle is 0xFF, all bondings will be deleted + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Create bonding if devices are not already bonded. 0: Do not create bonding. 1: Creating + * bonding + *

+ * BlueGiga API type is boolean - Java type is {@link boolean} + */ + private boolean bonding; + + /** + * Bonding handle of a device. This handle can be obtained for example from events like: Scan + * Response Status - If handle is 0xFF, all bondings will be deleted + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + /** + * Create bonding if devices are not already bonded. 0: Do not create bonding. 1: Creating + * bonding + * + * @param bonding the bonding to set as {@link boolean} + */ + public void setBonding(boolean bonding) { + this.bonding = bonding; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(handle); + serializeBoolean(bonding); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaEncryptStartCommand [handle="); + builder.append(handle); + builder.append(", bonding="); + builder.append(bonding); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartResponse.java new file mode 100644 index 00000000000..3eb391e0b97 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaEncryptStartResponse.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command encryptStart. + *

+ * This command starts the encryption for a given connection. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEncryptStartResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x00; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * 0 : the encryption was started successfully + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaEncryptStartResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt8(); + result = deserializeBgApiResponse(); + } + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * 0 : the encryption was started successfully + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaEncryptStartResponse [handle="); + builder.append(handle); + builder.append(", result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsCommand.java new file mode 100644 index 00000000000..b1ed7d0efca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsCommand.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getBonds. + *

+ * This command lists all bonded devices. There can be a maximum of 8 bonded devices. The + * information related to the bonded devices is stored in the Flash memory, so it is persistent + * across resets and power-cycles. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetBondsCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x05; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaGetBondsCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsResponse.java new file mode 100644 index 00000000000..671446afa04 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaGetBondsResponse.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getBonds. + *

+ * This command lists all bonded devices. There can be a maximum of 8 bonded devices. The + * information related to the bonded devices is stored in the Flash memory, so it is persistent + * across resets and power-cycles. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetBondsResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x05; + + /** + * Num of currently bonded devices + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int bonds; + + /** + * Response constructor + */ + public BlueGigaGetBondsResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + bonds = deserializeUInt8(); + } + + /** + * Num of currently bonded devices + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current bonds as {@link int} + */ + public int getBonds() { + return bonds; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetBondsResponse [bonds="); + builder.append(bonds); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyCommand.java new file mode 100644 index 00000000000..38890ddda48 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyCommand.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command passKey. + *

+ * This command is used to enter a passkey required for Man-in-the-Middle pairing. It should be + * sent as a response to Passkey Request event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPassKeyCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x04; + + /** + * Connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Passkey. Range: 000000-999999 + *

+ * BlueGiga API type is uint32 - Java type is {@link long} + */ + private long passkey; + + /** + * Connection handle + * + * @param handle the handle to set as {@link int} + */ + public void setHandle(int handle) { + this.handle = handle; + } + /** + * Passkey. Range: 000000-999999 + * + * @param passkey the passkey to set as {@link long} + */ + public void setPasskey(long passkey) { + this.passkey = passkey; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeUInt8(handle); + serializeUInt32(passkey); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPassKeyCommand [handle="); + builder.append(handle); + builder.append(", passkey="); + builder.append(passkey); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyResponse.java new file mode 100644 index 00000000000..9ff065eb0dd --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPassKeyResponse.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command passKey. + *

+ * This command is used to enter a passkey required for Man-in-the-Middle pairing. It should be + * sent as a response to Passkey Request event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPassKeyResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x04; + + /** + * Command Result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaPassKeyResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * Command Result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPassKeyResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyDisplayEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyDisplayEvent.java new file mode 100644 index 00000000000..83d6adfdcda --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyDisplayEvent.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command passkeyDisplayEvent. + *

+ * This event tells a passkey should be printed to the user for bonding. This passkey must be + * entered in the remote device for bonding to be successful. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPasskeyDisplayEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x02; + + /** + * Bluetooth connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Passkey range: 000000-999999 + *

+ * BlueGiga API type is uint32 - Java type is {@link long} + */ + private long passkey; + + /** + * Event constructor + */ + public BlueGigaPasskeyDisplayEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt8(); + passkey = deserializeUInt32(); + } + + /** + * Bluetooth connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + /** + * Passkey range: 000000-999999 + *

+ * BlueGiga API type is uint32 - Java type is {@link long} + * + * @return the current passkey as {@link long} + */ + public long getPasskey() { + return passkey; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPasskeyDisplayEvent [handle="); + builder.append(handle); + builder.append(", passkey="); + builder.append(passkey); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyRequestEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyRequestEvent.java new file mode 100644 index 00000000000..738c239c69c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaPasskeyRequestEvent.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command passkeyRequestEvent. + *

+ * This event indicates the Security Manager requests the user to enter passkey. The passkey + * the user needs to enter is displayed by the remote device. Use Passkey Entry command to + * respond to request + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaPasskeyRequestEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x03; + + /** + * Bluetooth connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int handle; + + /** + * Event constructor + */ + public BlueGigaPasskeyRequestEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + handle = deserializeUInt8(); + } + + /** + * Bluetooth connection handle + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current handle as {@link int} + */ + public int getHandle() { + return handle; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaPasskeyRequestEvent [handle="); + builder.append(handle); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeCommand.java new file mode 100644 index 00000000000..b5493946fbd --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeCommand.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command setBondableMode. + *

+ * This command is used to enter a passkey required for Man-in-the-Middle pairing. It should be + * sent as a response to Passkey Request event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetBondableModeCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x01; + + /** + * Enables or disables bonding mode. 0 : the device is not bondable. 1 : the device is bondable + *

+ * BlueGiga API type is boolean - Java type is {@link boolean} + */ + private boolean bondable; + + /** + * Enables or disables bonding mode. 0 : the device is not bondable. 1 : the device is bondable + * + * @param bondable the bondable to set as {@link boolean} + */ + public void setBondable(boolean bondable) { + this.bondable = bondable; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeBoolean(bondable); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetBondableModeCommand [bondable="); + builder.append(bondable); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeResponse.java new file mode 100644 index 00000000000..c69cf475875 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetBondableModeResponse.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command setBondableMode. + *

+ * This command is used to enter a passkey required for Man-in-the-Middle pairing. It should be + * sent as a response to Passkey Request event. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetBondableModeResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x01; + + /** + * Response constructor + */ + public BlueGigaSetBondableModeResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaSetBondableModeResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersCommand.java new file mode 100644 index 00000000000..8cb40799a04 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersCommand.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.SmpIoCapabilities; + +/** + * Class to implement the BlueGiga command setParameters. + *

+ * This command is used to configure the local Security Manager and its features + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetParametersCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x03; + + /** + * 1: Man-in-the-middle protection required. 0: No Man-in-the-middle protection. Default: + * 0 + *

+ * BlueGiga API type is boolean - Java type is {@link boolean} + */ + private boolean requireMitm; + + /** + * Minimum key size in Bytes. Range: 7-16. Default: 7 (56bits) + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int minKeySize; + + /** + * Configures the local devices I/O capabilities. See: SMP IO Capabilities for options. + * Default: No Input and No Output + *

+ * BlueGiga API type is SmpIoCapabilities - Java type is {@link SmpIoCapabilities} + */ + private SmpIoCapabilities ioCapabilities; + + /** + * 1: Man-in-the-middle protection required. 0: No Man-in-the-middle protection. Default: + * 0 + * + * @param requireMitm the requireMitm to set as {@link boolean} + */ + public void setRequireMitm(boolean requireMitm) { + this.requireMitm = requireMitm; + } + /** + * Minimum key size in Bytes. Range: 7-16. Default: 7 (56bits) + * + * @param minKeySize the minKeySize to set as {@link int} + */ + public void setMinKeySize(int minKeySize) { + this.minKeySize = minKeySize; + } + /** + * Configures the local devices I/O capabilities. See: SMP IO Capabilities for options. + * Default: No Input and No Output + * + * @param ioCapabilities the ioCapabilities to set as {@link SmpIoCapabilities} + */ + public void setIoCapabilities(SmpIoCapabilities ioCapabilities) { + this.ioCapabilities = ioCapabilities; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeBoolean(requireMitm); + serializeUInt8(minKeySize); + serializeSmpIoCapabilities(ioCapabilities); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaSetParametersCommand [requireMitm="); + builder.append(requireMitm); + builder.append(", minKeySize="); + builder.append(minKeySize); + builder.append(", ioCapabilities="); + builder.append(ioCapabilities); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersResponse.java new file mode 100644 index 00000000000..758718ed943 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaSetParametersResponse.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command setParameters. + *

+ * This command is used to configure the local Security Manager and its features + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaSetParametersResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x03; + + /** + * Response constructor + */ + public BlueGigaSetParametersResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaSetParametersResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsCommand.java new file mode 100644 index 00000000000..777829b6d71 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsCommand.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command whitelistBonds. + *

+ * This command will add all bonded devices with a known public or static address to the local + * devices white list. Previous entries in the white list will be first cleared. This command + * can't be used while advertising, scanning or being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistBondsCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x07; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaWhitelistBondsCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsResponse.java new file mode 100644 index 00000000000..463adf6cbd5 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/security/BlueGigaWhitelistBondsResponse.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.security; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command whitelistBonds. + *

+ * This command will add all bonded devices with a known public or static address to the local + * devices white list. Previous entries in the white list will be first cleared. This command + * can't be used while advertising, scanning or being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistBondsResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x05; + public static int COMMAND_METHOD = 0x07; + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Number of whitelisted bonds + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int count; + + /** + * Response constructor + */ + public BlueGigaWhitelistBondsResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + count = deserializeUInt8(); + } + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + /** + * Number of whitelisted bonds + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current count as {@link int} + */ + public int getCount() { + return count; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWhitelistBondsResponse [result="); + builder.append(result); + builder.append(", count="); + builder.append(count); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetCommand.java new file mode 100644 index 00000000000..8035c75f402 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetCommand.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command addressGet. + *

+ * This command reads the local device's public Bluetooth address. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAddressGetCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x02; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaAddressGetCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetResponse.java new file mode 100644 index 00000000000..250f93fb762 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaAddressGetResponse.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command addressGet. + *

+ * This command reads the local device's public Bluetooth address. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaAddressGetResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x02; + + /** + * Bluetooth address of the local device + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String address; + + /** + * Response constructor + */ + public BlueGigaAddressGetResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + address = deserializeAddress(); + } + + /** + * Bluetooth address of the local device + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + * + * @return the current address as {@link String} + */ + public String getAddress() { + return address; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaAddressGetResponse [address="); + builder.append(address); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaBootEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaBootEvent.java new file mode 100644 index 00000000000..637ffcc6f38 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaBootEvent.java @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command bootEvent. + *

+ * This event is produced when the device boots up and is ready to receive commands. This event is + * not sent over USB interface. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaBootEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x00; + + /** + * Major software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int major; + + /** + * Minor software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int minor; + + /** + * Patch ID + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int patch; + + /** + * Build version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int build; + + /** + * Link layer version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int llVersion; + + /** + * Protocol version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int protocolVersion; + + /** + * Hardware version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int hardware; + + /** + * Event constructor + */ + public BlueGigaBootEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + major = deserializeUInt16(); + minor = deserializeUInt16(); + patch = deserializeUInt16(); + build = deserializeUInt16(); + llVersion = deserializeUInt16(); + protocolVersion = deserializeUInt16(); + hardware = deserializeUInt16(); + } + + /** + * Major software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current major as {@link int} + */ + public int getMajor() { + return major; + } + /** + * Minor software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current minor as {@link int} + */ + public int getMinor() { + return minor; + } + /** + * Patch ID + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current patch as {@link int} + */ + public int getPatch() { + return patch; + } + /** + * Build version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current build as {@link int} + */ + public int getBuild() { + return build; + } + /** + * Link layer version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current ll_version as {@link int} + */ + public int getLlVersion() { + return llVersion; + } + /** + * Protocol version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current protocol_version as {@link int} + */ + public int getProtocolVersion() { + return protocolVersion; + } + /** + * Hardware version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current hardware as {@link int} + */ + public int getHardware() { + return hardware; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaBootEvent [major="); + builder.append(major); + builder.append(", minor="); + builder.append(minor); + builder.append(", patch="); + builder.append(patch); + builder.append(", build="); + builder.append(build); + builder.append(", llVersion="); + builder.append(llVersion); + builder.append(", protocolVersion="); + builder.append(protocolVersion); + builder.append(", hardware="); + builder.append(hardware); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkRxEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkRxEvent.java new file mode 100644 index 00000000000..3a7b161eb8d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkRxEvent.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command endpointWatermarkRxEvent. + *

+ * This event is generated if the receive (incoming) buffer of the endpoint has been filled with + * a number of bytes equal or higher than the value defined by the command Endpoint Set + * Watermarks. Data from the receive buffer can then be read (and consequently cleared) with + * the command Endpoint Rx + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEndpointWatermarkRxEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x02; + + /** + * Endpoint index where data was received + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int endpoint; + + /** + * Space available + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int data; + + /** + * Event constructor + */ + public BlueGigaEndpointWatermarkRxEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + endpoint = deserializeUInt8(); + data = deserializeUInt8(); + } + + /** + * Endpoint index where data was received + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current endpoint as {@link int} + */ + public int getEndpoint() { + return endpoint; + } + /** + * Space available + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current data as {@link int} + */ + public int getData() { + return data; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaEndpointWatermarkRxEvent [endpoint="); + builder.append(endpoint); + builder.append(", data="); + builder.append(data); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkTxEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkTxEvent.java new file mode 100644 index 00000000000..3320d0dd064 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaEndpointWatermarkTxEvent.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command endpointWatermarkTxEvent. + *

+ * This event is generated when the transmit (outgoing) buffer of the endpoint has free space + * for a number of bytes equal or higher than the value defined by the command Endpoint Set + * Watermarks. When there is enough free space, data can be sent out of the endpoint by the + * command Endpoint Tx. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaEndpointWatermarkTxEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x03; + + /** + * Endpoint index where data was sent + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int endpoint; + + /** + * Space available + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int data; + + /** + * Event constructor + */ + public BlueGigaEndpointWatermarkTxEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + endpoint = deserializeUInt8(); + data = deserializeUInt8(); + } + + /** + * Endpoint index where data was sent + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current endpoint as {@link int} + */ + public int getEndpoint() { + return endpoint; + } + /** + * Space available + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current data as {@link int} + */ + public int getData() { + return data; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaEndpointWatermarkTxEvent [endpoint="); + builder.append(endpoint); + builder.append(", data="); + builder.append(data); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsCommand.java new file mode 100644 index 00000000000..e5f3c86c446 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsCommand.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getConnections. + *

+ * This command reads the number of supported connections from the local device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetConnectionsCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x06; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaGetConnectionsCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsResponse.java new file mode 100644 index 00000000000..931e2d79ab2 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetConnectionsResponse.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getConnections. + *

+ * This command reads the number of supported connections from the local device. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetConnectionsResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x06; + + /** + * Max supported connections + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int maxconn; + + /** + * Response constructor + */ + public BlueGigaGetConnectionsResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + maxconn = deserializeUInt8(); + } + + /** + * Max supported connections + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current maxconn as {@link int} + */ + public int getMaxconn() { + return maxconn; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetConnectionsResponse [maxconn="); + builder.append(maxconn); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersCommand.java new file mode 100644 index 00000000000..43e3c12ed48 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersCommand.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getCounters. + *

+ * Read packet counters and resets them, also returns available packet buffers. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetCountersCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x05; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaGetCountersCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersResponse.java new file mode 100644 index 00000000000..627f24c47b0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetCountersResponse.java @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getCounters. + *

+ * Read packet counters and resets them, also returns available packet buffers. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetCountersResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x05; + + /** + * Number of transmitted packets + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int txok; + + /** + * Number of retransmitted packets + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int txretry; + + /** + * Number of received packets where CRC was OK + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int rxok; + + /** + * Number of received packets with CRC error + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int rxfail; + + /** + * Number of available packet buffers + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + */ + private int mbuf; + + /** + * Response constructor + */ + public BlueGigaGetCountersResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + txok = deserializeUInt8(); + txretry = deserializeUInt8(); + rxok = deserializeUInt8(); + rxfail = deserializeUInt8(); + mbuf = deserializeUInt8(); + } + + /** + * Number of transmitted packets + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current txok as {@link int} + */ + public int getTxok() { + return txok; + } + /** + * Number of retransmitted packets + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current txretry as {@link int} + */ + public int getTxretry() { + return txretry; + } + /** + * Number of received packets where CRC was OK + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current rxok as {@link int} + */ + public int getRxok() { + return rxok; + } + /** + * Number of received packets with CRC error + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current rxfail as {@link int} + */ + public int getRxfail() { + return rxfail; + } + /** + * Number of available packet buffers + *

+ * BlueGiga API type is uint8 - Java type is {@link int} + * + * @return the current mbuf as {@link int} + */ + public int getMbuf() { + return mbuf; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetCountersResponse [txok="); + builder.append(txok); + builder.append(", txretry="); + builder.append(txretry); + builder.append(", rxok="); + builder.append(rxok); + builder.append(", rxfail="); + builder.append(rxfail); + builder.append(", mbuf="); + builder.append(mbuf); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoCommand.java new file mode 100644 index 00000000000..e6bd8600c99 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoCommand.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command getInfo. + *

+ * This command reads the local devices software and hardware versions. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetInfoCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x08; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaGetInfoCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoResponse.java new file mode 100644 index 00000000000..068edde447d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaGetInfoResponse.java @@ -0,0 +1,191 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command getInfo. + *

+ * This command reads the local devices software and hardware versions. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaGetInfoResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x08; + + /** + * Major software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int major; + + /** + * Minor software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int minor; + + /** + * Patch ID + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int patch; + + /** + * Build version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int build; + + /** + * Link layer version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int llVersion; + + /** + * Protocol version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int protocolVersion; + + /** + * Hardware version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + */ + private int hardware; + + /** + * Response constructor + */ + public BlueGigaGetInfoResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + major = deserializeUInt16(); + minor = deserializeUInt16(); + patch = deserializeUInt16(); + build = deserializeUInt16(); + llVersion = deserializeUInt16(); + protocolVersion = deserializeUInt16(); + hardware = deserializeUInt16(); + } + + /** + * Major software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current major as {@link int} + */ + public int getMajor() { + return major; + } + /** + * Minor software version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current minor as {@link int} + */ + public int getMinor() { + return minor; + } + /** + * Patch ID + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current patch as {@link int} + */ + public int getPatch() { + return patch; + } + /** + * Build version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current build as {@link int} + */ + public int getBuild() { + return build; + } + /** + * Link layer version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current ll_version as {@link int} + */ + public int getLlVersion() { + return llVersion; + } + /** + * Protocol version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current protocol_version as {@link int} + */ + public int getProtocolVersion() { + return protocolVersion; + } + /** + * Hardware version + *

+ * BlueGiga API type is uint16 - Java type is {@link int} + * + * @return the current hardware as {@link int} + */ + public int getHardware() { + return hardware; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaGetInfoResponse [major="); + builder.append(major); + builder.append(", minor="); + builder.append(minor); + builder.append(", patch="); + builder.append(patch); + builder.append(", build="); + builder.append(build); + builder.append(", llVersion="); + builder.append(llVersion); + builder.append(", protocolVersion="); + builder.append(protocolVersion); + builder.append(", hardware="); + builder.append(hardware); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloCommand.java new file mode 100644 index 00000000000..e8b50911be0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloCommand.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command hello. + *

+ * This command can be used to test if the local device is functional. Similar to a typical "AT" -> + * "OK" test. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaHelloCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x01; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaHelloCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloResponse.java new file mode 100644 index 00000000000..b065cd0e04b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaHelloResponse.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command hello. + *

+ * This command can be used to test if the local device is functional. Similar to a typical "AT" -> + * "OK" test. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaHelloResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x01; + + /** + * Response constructor + */ + public BlueGigaHelloResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaHelloResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaNoLicenseKeyEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaNoLicenseKeyEvent.java new file mode 100644 index 00000000000..3fae3606e15 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaNoLicenseKeyEvent.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command noLicenseKeyEvent. + *

+ * This error is produced when no valid license key found form the Smart hardware. When there is + * no Bluetooth valid license key the Bluetooth radio will not be operational. A new license key + * can be requested from the Bluegiga Technical Support. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaNoLicenseKeyEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x05; + + /** + * Event constructor + */ + public BlueGigaNoLicenseKeyEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaNoLicenseKeyEvent []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaProtocolErrorEvent.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaProtocolErrorEvent.java new file mode 100644 index 00000000000..7c7acca7e10 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaProtocolErrorEvent.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command protocolErrorEvent. + *

+ * A protocol error was detected in BGAPI command parser. This event is triggered if a BGAPI + * command from the host contains syntax error(s), or if a command is only partially sent. Then + * the BGAPI parser has a 1 second command timeout and if a valid command is not transmitted + * within this timeout an error is raised and the partial or wrong command will be ignored. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaProtocolErrorEvent extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x06; + + /** + * Reason for failure + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse reason; + + /** + * Event constructor + */ + public BlueGigaProtocolErrorEvent(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + reason = deserializeBgApiResponse(); + } + + /** + * Reason for failure + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current reason as {@link BgApiResponse} + */ + public BgApiResponse getReason() { + return reason; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaProtocolErrorEvent [reason="); + builder.append(reason); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetCommand.java new file mode 100644 index 00000000000..32ba6879a9b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetCommand.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command reset. + *

+ * This command resets the local device immediately. The command does not have a response. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaResetCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x00; + + /** + * Selects the boot mode. 0 : boot to main program. 1 : boot to DFU + *

+ * BlueGiga API type is boolean - Java type is {@link boolean} + */ + private boolean bootInDfu = false; + + /** + * Selects the boot mode. 0 : boot to main program. 1 : boot to DFU + * + * @param bootInDfu the bootInDfu to set as {@link boolean} + */ + public void setBootInDfu(boolean bootInDfu) { + this.bootInDfu = bootInDfu; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeBoolean(bootInDfu); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaResetCommand [bootInDfu="); + builder.append(bootInDfu); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetResponse.java new file mode 100644 index 00000000000..8caccc5fb36 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaResetResponse.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command reset. + *

+ * This command resets the local device immediately. The command does not have a response. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaResetResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x00; + + /** + * Response constructor + */ + public BlueGigaResetResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaResetResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendCommand.java new file mode 100644 index 00000000000..fe2a56e9a1c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendCommand.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command whitelistAppend. + *

+ * Add an entry to the running white list. By the white list you can define for example the remote + * devices which are allowed to establish a connection. See also Set Filtering Connect + * Selective and (if the white list is empty they will not be active). Do not use this command + * while advertising, scanning, or while being connected. The current list is discarded upon + * reset or power-cycle. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistAppendCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0A; + + /** + * Bluetooth device address to add to the running white list. Maximum of 8 can be stored before + * you must clear or remove entries. + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String address; + + /** + * Bluetooth device address to add to the running white list. Maximum of 8 can be stored before + * you must clear or remove entries. + * + * @param address the address to set as {@link String} + */ + public void setAddress(String address) { + this.address = address; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeAddress(address); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWhitelistAppendCommand [address="); + builder.append(address); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendResponse.java new file mode 100644 index 00000000000..48859101295 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistAppendResponse.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command whitelistAppend. + *

+ * Add an entry to the running white list. By the white list you can define for example the remote + * devices which are allowed to establish a connection. See also Set Filtering Connect + * Selective and (if the white list is empty they will not be active). Do not use this command + * while advertising, scanning, or while being connected. The current list is discarded upon + * reset or power-cycle. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistAppendResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0A; + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaWhitelistAppendResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWhitelistAppendResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearCommand.java new file mode 100644 index 00000000000..7c2a34b756d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearCommand.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command whitelistClear. + *

+ * Delete all entries on the white list at once. Do not use this command while advertising or + * while being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistClearCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0C; + + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + return getPayload(); + } + + @Override + public String toString() { + return "BlueGigaWhitelistClearCommand []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearResponse.java new file mode 100644 index 00000000000..eed25898c4a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistClearResponse.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; + +/** + * Class to implement the BlueGiga command whitelistClear. + *

+ * Delete all entries on the white list at once. Do not use this command while advertising or + * while being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistClearResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0C; + + /** + * Response constructor + */ + public BlueGigaWhitelistClearResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + } + + + @Override + public String toString() { + return "BlueGigaWhitelistClearResponse []"; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveCommand.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveCommand.java new file mode 100644 index 00000000000..dc24cbb5eca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveCommand.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand; + +/** + * Class to implement the BlueGiga command whitelistRemove. + *

+ * Remove an entry from the running white list. Do not use this command while advertising or + * while being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistRemoveCommand extends BlueGigaCommand { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0B; + + /** + * Bluetooth device address to remove from the running white list. + *

+ * BlueGiga API type is bd_addr - Java type is {@link String} + */ + private String address; + + /** + * Bluetooth device address to remove from the running white list. + * + * @param address the address to set as {@link String} + */ + public void setAddress(String address) { + this.address = address; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(COMMAND_CLASS, COMMAND_METHOD); + + // Serialize the fields + serializeAddress(address); + + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWhitelistRemoveCommand [address="); + builder.append(address); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveResponse.java new file mode 100644 index 00000000000..5424475d862 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/command/system/BlueGigaWhitelistRemoveResponse.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.command.system; + +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaResponse; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse; + +/** + * Class to implement the BlueGiga command whitelistRemove. + *

+ * Remove an entry from the running white list. Do not use this command while advertising or + * while being connected. + *

+ * This class provides methods for processing BlueGiga API commands. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public class BlueGigaWhitelistRemoveResponse extends BlueGigaResponse { + public static int COMMAND_CLASS = 0x00; + public static int COMMAND_METHOD = 0x0B; + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + */ + private BgApiResponse result; + + /** + * Response constructor + */ + public BlueGigaWhitelistRemoveResponse(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + event = (inputBuffer[0] & 0x80) != 0; + + // Deserialize the fields + result = deserializeBgApiResponse(); + } + + /** + * Command result + *

+ * BlueGiga API type is BgApiResponse - Java type is {@link BgApiResponse} + * + * @return the current result as {@link BgApiResponse} + */ + public BgApiResponse getResult() { + return result; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("BlueGigaWhitelistRemoveResponse [result="); + builder.append(result); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirDataType.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirDataType.java new file mode 100644 index 00000000000..0d6cf9f6ef3 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirDataType.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir; + +import java.util.HashMap; +import java.util.Map; + +/** + * Assigned numbers are used in GAP for inquiry response, EIR data type values, manufacturer-specific data, advertising + * data, low energy UUIDs and appearance characteristics, and class of device. + * + * https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile + * + * @author Chris Jackson + * + */ +public enum EirDataType { + /** + * Default unknown value + */ + UNKNOWN(-1), + NONE(0), + + EIR_FLAGS(0x01), + EIR_SVC_UUID16_INCOMPLETE(0x02), + EIR_SVC_UUID16_COMPLETE(0x03), + EIR_SVC_UUID32_INCOMPLETE(0x04), + EIR_SVC_UUID32_COMPLETE(0x05), + EIR_SVC_UUID128_INCOMPLETE(0x06), + EIR_SVC_UUID128_COMPLETE(0x07), + EIR_NAME_SHORT(0x08), + EIR_NAME_LONG(0x09), + EIR_TXPOWER(0x0A), + EIR_DEVICE_CLASS(0x0D), + EIR_SIMPLE_PAIRING_RANDOMIZER(0x0F), + EIR_SECMAN_TK_VALUE(0x10), + EIR_SECMAN_OOB_FLAGS(0x11), + EIR_SLAVEINTERVALRANGE(0x12), + EIR_SVC_SOLICIT_UUID16(0x14), + EIR_SVC_SOLICIT_UUID128(0x15), + EIR_SVC_DATA_UUID16(0x16), + EIR_PUBLIC_TARGET_ADDR(0x17), + EIR_RANDOM_TARGET_ADDR(0x18), + EIR_APPEARANCE(0x19), + EIR_ADVERTISING_INTERVAL(0x1A), + EIR_LE_DEVICE_ADDRESS(0x1B), + EIR_LE_ROLE(0x1C), + EIR_SIMPLE_PAIRING_HASH(0x1D), + EIR_SVC_SOLICIT_UUID32(0x1F), + EIR_SVC_DATA_UUID32(0x20), + EIR_SVC_DATA_UUID128(0x21), + EIR_LE_SEC_CONFIRMATION_VALUE(0x22), + EIR_LE_CONNECTION_RANDOM_VALUE(0x23), + EIR_URI(0x24), + EIR_INDOOR_POSITIONING(0x25), + EIR_LE_SUPPORTED_FEATURES(0x27), + EIR_MANUFACTURER_SPECIFIC(0xFF); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private EirDataType(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (EirDataType s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param bluetoothAddressType + * the code to lookup + * @return enumeration value. + */ + public static EirDataType getEirPacketType(int eirDataType) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(eirDataType) == null) { + return UNKNOWN; + } + + return codeMapping.get(eirDataType); + } + + /** + * Returns the Bluetooth protocol defined value for this enum + * + * @return the EIR Data type key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirFlags.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirFlags.java new file mode 100644 index 00000000000..9637432e3b7 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirFlags.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir; + +import java.util.HashMap; +import java.util.Map; + +/** + * Definition of the EIR Flags field + * + * @author Chris Jackson + * + */ +public enum EirFlags { + UNKNOWN(-1), + LE_LIMITED_DISCOVERABLE_MODE(0), + LE_GENERAL_DISCOVERABLE_MODE(1), + BR_EDR_NOT_SUPPORTED(2), + SIMULTANEOUS_LE_BDR_CONTROLLER(3), + SIMULTANEOUS_LE_BDR_HOST(4), + BIT5(5), + BIT6(6), + BIT7(7), + BIT8(8), + BIT9(9), + BIT10(10), + BIT11(11), + BIT12(12), + BIT13(13), + BIT14(14), + BIT15(15); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private EirFlags(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (EirFlags s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param bluetoothAddressType + * the code to lookup + * @return enumeration value. + */ + public static EirFlags getEirFlag(int eirFlag) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(eirFlag) == null) { + return UNKNOWN; + } + + return codeMapping.get(eirFlag); + } + + /** + * Returns the Bluetooth protocol defined value for this enum + * + * @return the EIR Data type key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirPacket.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirPacket.java new file mode 100644 index 00000000000..8732edb94e5 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirPacket.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +/** + * This class processes the Extended Inquiry Response data used in the BLE advertisement frame + * + * @author Chris Jackson + * + */ +public class EirPacket { + private Map records = new HashMap(); + + public EirPacket(int[] data) { + if (data == null || data.length == 0) { + return; + } + + for (int cnt = 0; cnt < data.length;) { + if (data[cnt] == 0) { + break; + } + + int[] rawRecord = Arrays.copyOfRange(data, cnt + 1, cnt + data[cnt] + 1); + EirRecord record = new EirRecord(rawRecord); + + cnt += data[cnt] + 1; + + records.put(record.getType(), record.getRecord()); + } + } + + /** + * Returns a map of all records decoded in the packet + * + * @return {@link Map} of {@link EirDataType} to {@link Object} + */ + public Map getRecords() { + return records; + } + + /** + * Returns the specified record decoded in the packet or null if the record is not found + * + * @param recordType the requested {@link EirDataType} + * @return {@link Map} of to {@link Object} + */ + public Object getRecord(EirDataType recordType) { + return records.get(recordType); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("EirPacket [records="); + builder.append(records); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirRecord.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirRecord.java new file mode 100644 index 00000000000..f86539bce71 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/eir/EirRecord.java @@ -0,0 +1,189 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.eir; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Defines an EIR record used in the BLE advertisement packets. + * + * @author Chris Jackson + * + */ +public class EirRecord { + private EirDataType type; + private Object record; + + EirRecord(int[] data) { + if (data == null || data.length == 0) { + return; + } + + type = EirDataType.getEirPacketType(data[0]); + switch (type) { + case EIR_FLAGS: + record = processFlags(data); + break; + case EIR_MANUFACTURER_SPECIFIC: + record = processManufacturer(data); + break; + case EIR_SVC_UUID16_COMPLETE: + case EIR_SVC_UUID16_INCOMPLETE: + record = processUuid16(data); + break; + case EIR_SVC_UUID32_COMPLETE: + case EIR_SVC_UUID32_INCOMPLETE: + record = processUuid32(data); + break; + case EIR_SVC_UUID128_COMPLETE: + case EIR_SVC_UUID128_INCOMPLETE: + record = processUuid128(data); + break; + case EIR_NAME_LONG: + case EIR_NAME_SHORT: + record = processString(data); + break; + case EIR_TXPOWER: + record = processUInt8(data); + break; + case EIR_SLAVEINTERVALRANGE: + record = processUInt16List(data); + break; + case EIR_DEVICE_CLASS: + record = processUInt8(data); + break; + default: + record = processUnknown(data); + break; + } + } + + private byte[] processManufacturer(int[] data) { + // we have to drop the first byte/int + byte[] manufacturerData = new byte[data.length - 1]; + for (int i = 1; i < data.length; i++) { + manufacturerData[i - 1] = (byte) data[i]; + } + return manufacturerData; + } + + private List processUuid16(int[] data) { + List uuidList = new ArrayList(); + + for (int cnt = 1; cnt < data.length - 1; cnt += 2) { + long high = ((long) data[cnt] << 32) + ((long) data[cnt + 1] << 40); + uuidList.add(new UUID(high, 0)); + } + + return uuidList; + } + + private List processUuid32(int[] data) { + List uuidList = new ArrayList(); + + for (int cnt = 1; cnt < data.length - 1; cnt += 4) { + long high = ((long) data[cnt++] << 32) + ((long) data[cnt++] << 40) + ((long) data[cnt++] << 48) + + ((long) data[cnt++] << 56); + uuidList.add(new UUID(high, 0)); + } + + return uuidList; + } + + private List processUuid128(int[] data) { + List uuidList = new ArrayList(); + + for (int cnt = 1; cnt < data.length - 1; cnt += 16) { + long low = (data[cnt++]) + ((long) data[cnt++] << 8) + ((long) data[cnt++] << 16) + + ((long) data[cnt++] << 24) + ((long) data[cnt++] << 32) + ((long) data[cnt++] << 40) + + ((long) data[cnt++] << 48) + ((long) data[cnt++] << 56); + long high = (data[cnt++]) + ((long) data[cnt++] << 8) + ((long) data[cnt++] << 16) + + ((long) data[cnt++] << 24) + ((long) data[cnt++] << 32) + ((long) data[cnt++] << 40) + + ((long) data[cnt++] << 48) + ((long) data[cnt++] << 56); + + uuidList.add(new UUID(high, low)); + } + + return uuidList; + } + + private List processUInt16List(int[] data) { + List intList = new ArrayList(); + + for (int cnt = 1; cnt < data.length - 1; cnt += 2) { + intList.add(Integer.valueOf(data[cnt] + (data[cnt + 1] << 8))); + } + + return intList; + } + + private List processFlags(int[] data) { + List flags = new ArrayList(); + int flagBit = 0; + for (int cnt = 1; cnt < data.length; cnt++) { + for (int bitcnt = 0; bitcnt < 8; bitcnt++) { + if ((data[cnt] & (1 << bitcnt)) != 0) { + flags.add(EirFlags.getEirFlag(flagBit)); + } + flagBit++; + } + } + + return flags; + } + + private String processString(int[] data) { + StringBuilder builder = new StringBuilder(); + for (int cnt = 1; cnt < data.length; cnt++) { + builder.append((char) data[cnt]); + } + return builder.toString(); + } + + private int processUInt8(int[] data) { + if (data[1] > 127) { + return data[1] - 256; + } else { + return data[1]; + } + } + + private String processUnknown(int[] data) { + StringBuilder builder = new StringBuilder(); + for (int cnt = 0; cnt < data.length; cnt++) { + builder.append(String.format("%02X", data[cnt])); + } + return builder.toString(); + } + + public EirDataType getType() { + return type; + } + + public Object getRecord() { + return record; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("EirRecord [type="); + builder.append(type); + builder.append(", record="); + builder.append(record); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeChangeReason.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeChangeReason.java new file mode 100644 index 00000000000..bc9097a34aa --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeChangeReason.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration AttributeChangeReason. + *

+ * This enumeration contains the reason for an attribute value change. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum AttributeChangeReason { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Value was written by remote device using write request + */ + ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST(0x0000), + + /** + * [1] Value was written by remote device using write command + */ + ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_COMMAND(0x0001), + + /** + * [2] Local attribute value was written by the remote device, but the Smart Bluetooth stack is + * waiting for the write to be confirmed by the application. User Write Response command should + * be used to send the confirmation. For this reason to appear the attribute in the GATT database + * must have the user property enabled. See Profile Toolkit Developer Guide for more + * information how to enable the user property for an attribute. + */ + ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST_USER(0x0002); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private AttributeChangeReason(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (AttributeChangeReason s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param attributeChangeReason + * the code to lookup + * @return enumeration value. + */ + public static AttributeChangeReason getAttributeChangeReason(int attributeChangeReason) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(attributeChangeReason) == null) { + return UNKNOWN; + } + + return codeMapping.get(attributeChangeReason); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeValueType.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeValueType.java new file mode 100644 index 00000000000..c29332bb07a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/AttributeValueType.java @@ -0,0 +1,110 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration AttributeValueType. + *

+ * These enumerations are in the Attribute Client class + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum AttributeValueType { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Value was read + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ(0x0000), + + /** + * [1] Value was notified + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_NOTIFY(0x0001), + + /** + * [2] Value was indicated + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE(0x0002), + + /** + * [3] Value was read + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BY_TYPE(0x0003), + + /** + * [4] Value was part of a long attribute + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BLOB(0x0004), + + /** + * [5] Value was indicated and the remote device is waiting for a confirmation. Indicate + * Confirm command can be used to send a confirmation. + */ + ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE_RSP_REQ(0x0005); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private AttributeValueType(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (AttributeValueType s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param attributeValueType + * the code to lookup + * @return enumeration value. + */ + public static AttributeValueType getAttributeValueType(int attributeValueType) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(attributeValueType) == null) { + return UNKNOWN; + } + + return codeMapping.get(attributeValueType); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BgApiResponse.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BgApiResponse.java new file mode 100644 index 00000000000..e7dc259407f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BgApiResponse.java @@ -0,0 +1,478 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration BgApiResponse. + *

+ * Response codes + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum BgApiResponse { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Completed successfully. + */ + SUCCESS(0x0000), + + /** + * [257] Invalid GATT connection handle. + */ + INVALID_CONN_HANDLE(0x0101), + + /** + * [258] Waiting response from GATT server to previous procedure. + */ + WAITING_RESPONSE(0x0102), + + /** + * [384] Command contained invalid parameter + */ + INVALID_PARAM(0x0180), + + /** + * [385] Device is in wrong state to receive command + */ + WRONG_STATE(0x0181), + + /** + * [386] Device has run out of memory + */ + OUT_OF_MEMORY(0x0182), + + /** + * [387] Feature is not implemented + */ + NOT_IMPLEMENTED(0x0183), + + /** + * [388] Command was not recognized + */ + INVALID_COMMAND(0x0184), + + /** + * [389] Command or Procedure failed due to timeout + */ + TIMEOUT(0x0185), + + /** + * [390] Connection handle passed is to command is not a valid handle + */ + NOT_CONNECTED(0x0186), + + /** + * [391] Command would cause either underflow or overflow error + */ + FLOW(0x0187), + + /** + * [392] User attribute was accessed through API which is not supported + */ + USER_ATTRIBUTE(0x0188), + + /** + * [393] No valid license key found + */ + INVALID_LICENSE_KEY(0x0189), + + /** + * [394] Command maximum length exceeded + */ + COMMAND_TOO_LONG(0x018A), + + /** + * [395] Bonding procedure can't be started because device has no space left for bond. + */ + OUT_OF_BONDS(0x018B), + + /** + * [396] Unspecified error + */ + UNSPECIFIED(0x018C), + + /** + * [397] Hardware failure + */ + HARDWARE(0x018D), + + /** + * [398] Command not accepted, because internal buffers are full + */ + BUFFERS_FULL(0x018E), + + /** + * [399] Command or Procedure failed due to disconnection + */ + DISCONNECTED(0x018F), + + /** + * [400] Too many Simultaneous Requests + */ + TOO_MANY_REQUESTS(0x0190), + + /** + * [401] Feature is not supported in this firmware build + */ + NOT_SUPPORTED(0x0191), + + /** + * [402] The bonding does not exist. + */ + NO_BONDING(0x0192), + + /** + * [403] Error using crypto functions + */ + CRYPTO(0x0193), + + /** + * [514] A command was sent from the Host that should identify a connection, but that connection + * does not exist. + */ + UNKNOWN_CONNECTION_IDENTIFIER(0x0202), + + /** + * [520] Link supervision timeout has expired. + */ + CONNECTION_TIMEOUT(0x0208), + + /** + * [521] Controller is at limit of connections it can support. + */ + CONNECTION_LIMIT_EXCEEDED(0x0209), + + /** + * [522] + */ + SYNCHRONOUS_CONNECTIONTION_LIMIT_EXCEEDED(0x020A), + + /** + * [523] The ACL Connection Already Exists error code indicates that an attempt to create a new + * ACL Connection to a device when there is already a connection to this device. + */ + ACL_CONNECTION_ALREADY_EXISTS(0x020B), + + /** + * [524] Command requested cannot be executed because the Controller is in a state where it + * cannot process this command at this time. + */ + COMMAND_DISALLOWED(0x020C), + + /** + * [525] The Connection Rejected Due To Limited Resources error code indicates that an + * incoming connection was rejected due to limited resources. + */ + CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES(0x020D), + + /** + * [526] The Connection Rejected Due To Security Reasons error code indicates that a + * connection was rejected due to security requirements not being fulfilled, like + * authentication or pairing. + */ + CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS(0x020E), + + /** + * [527] The Connection was rejected because this device does not accept the BD_ADDR. This may + * be because the device will only accept connections from specific BD_ADDRs. + */ + CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR(0x020F), + + /** + * [528] The Connection Accept Timeout has been exceeded for this connection attempt. + */ + CONNECTION_ACCEPT_TIMEOUT_EXCEEDED(0x0210), + + /** + * [529] A feature or parameter value in the HCI command is not supported. + */ + UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE(0x0211), + + /** + * [530] Command contained invalid parameters. + */ + INVALID_COMMAND_PARAMETERS(0x0212), + + /** + * [531] User on the remote device terminated the connection. + */ + REMOTE_USER_TERMINATED(0x0213), + + /** + * [532] The remote device terminated the connection because of low resources + */ + REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES(0x0214), + + /** + * [533] Remote Device Terminated Connection due to Power Off + */ + REMOTE_POWERING_OFF(0x0215), + + /** + * [534] Local device terminated the connection. + */ + CONNECTION_TERMINATED_BY_LOCAL_HOST(0x0216), + + /** + * [535] The Controller is disallowing an authentication or pairing procedure because too + * little time has elapsed since the last authentication or pairing attempt failed. + */ + REPEATED_ATTEMPTS(0x0217), + + /** + * [536] The device does not allow pairing. This can be for example, when a device only allows + * pairing during a certain time window after some user input allows pairing + */ + PAIRING_NOT_ALLOWED(0x0218), + + /** + * [537] The Controller has received an unknown LMP OpCode. + */ + UNKNOWN_LMP_PDU(0x0219), + + /** + * [538] The remote device does not support the feature associated with the issued command or + * LMP PDU. + */ + UNSUPPORTED_REMOTE_FEATURE(0x021A), + + /** + * [560] A parameter value requested is outside the mandatory range of parameters for the given + * HCI command or LMP PDU. + */ + PARAMETER_OUT_OF_MANDATORY_RANGE(0x0230), + + /** + * [569] The Controller could not calculate an appropriate value for the Channel selection + * operation. + */ + CONNECTION_REJECTED_NO_SUITABLE_CHANNEL(0x0239), + + /** + * [570] Operation was rejected because the controller is busy and unable to process the + * request. + */ + CONTROLLER_BUSY(0x023A), + + /** + * [571] Remote device terminated the connection because of an unacceptable connection + * interval. + */ + UNACCEPTABLE_CONNECTION_INTERVAL(0x023B), + + /** + * [573] Connection was terminated because the Message Integrity Check (MIC) failed on a + * received packet. + */ + CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE(0x023D), + + /** + * [574] LL initiated a connection but the connection has failed to be established. Controller + * did not receive any packets from remote end. + */ + CONNECTION_FAILED_TO_BE_ESTABLISHED(0x023E), + + /** + * [575] The MAC of the 802.11 AMP was requested to connect to a peer, but the connection failed. + */ + MAC_CONNECTION_FAILED(0x023F), + + /** + * [576] The master, at this time, is unable to make a coarse adjustment to the piconet clock, + * using the supplied parameters. Instead the master will attempt to move the clock using clock + * dragging. + */ + COARSE_CLOCK_ADJUSTMENT_REJECTED(0x0240), + + /** + * [769] The user input of passkey failed, for example, the user cancelled the operation + */ + PASSKEY_ENTRY_FAILED(0x0301), + + /** + * [1025] The attribute handle given was not valid on this server + */ + INVALID_HANDLE(0x0401), + + /** + * [1026] The attribute cannot be read + */ + READ_NOT_PERMITTED(0x0402), + + /** + * [1027] The attribute cannot be written + */ + WRITE_NOT_PERMITTED(0x0403), + + /** + * [1028] The attribute PDU was invalid + */ + INVALID_PDU(0x0404), + + /** + * [1029] The attribute requires authentication before it can be read or written. + */ + INSUFFICIENT_AUTHENTICATION(0x0405), + + /** + * [1030] Attribute Server does not support the request received from the client. + */ + REQUEST_NOT_SUPPORTED(0x0406), + + /** + * [1031] Offset specified was past the end of the attribute + */ + INVALID_OFFSET(0x0407), + + /** + * [1032] The attribute requires authorization before it can be read or written. + */ + INSUFFICIENT_AUTHORIZATION(0x0408), + + /** + * [1033] Too many prepare writes have been queueud + */ + PREPARE_QUEUE_FULL(0x0409), + + /** + * [1034] No attribute found within the given attribute handle range. + */ + ATT_NOT_FOUND(0x040A), + + /** + * [1035] The attribute cannot be read or written using the Read Blob Request + */ + ATT_NOT_LONG(0x040B), + + /** + * [1037] The attribute value length is invalid for the operation + */ + INVALID_ATT_LENGTH(0x040D), + + /** + * [1040] The attribute type is not a supported grouping attribute as defined by a higher layer + * specification. + */ + UNSUPPORTED_GROUP_TYPE(0x0410), + + /** + * [1041] Insufficient Resources to complete the request + */ + INSUFFICIENT_RESOURCES(0x0411), + + /** + * [1152] Application error code defined by a higher layer specification. + */ + APPLICATION(0x0480), + + /** + * [1537] Service Record not found + */ + RECORD_NOT_FOUND(0x0601), + + /** + * [1538] Service Record with this handle already exist + */ + RECORD_ALREADY_EXIST(0x0602), + + /** + * [2305] File not found. + */ + FILE_NOT_FOUND(0x0901), + + /** + * [2561] File open failed. + */ + FILE_OPEN_FAILED(0x0A01), + + /** + * [2562] XML parsing failed. + */ + XML_PARSE_FAILED(0x0A02), + + /** + * [2563] Device connection failed. + */ + DEVICE_CONNECTION_FAILED(0x0A03), + + /** + * [2817] Device firmware signature verification failed. + */ + IMAGE_SIGNATURE_VERIFICATION_FAILED(0x0B01), + + /** + * [2818] File signature verification failed. + */ + FILE_SIGNATURE_VERIFICATION_FAILED(0x0B02), + + /** + * [2819] Device firmware checksum is not valid. + */ + IMAGE_CHECKSUM_ERROR(0x0B03); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private BgApiResponse(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (BgApiResponse s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param bgApiResponse + * the code to lookup + * @return enumeration value. + */ + public static BgApiResponse getBgApiResponse(int bgApiResponse) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(bgApiResponse) == null) { + return UNKNOWN; + } + + return codeMapping.get(bgApiResponse); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BluetoothAddressType.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BluetoothAddressType.java new file mode 100644 index 00000000000..bee7245198c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/BluetoothAddressType.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration BluetoothAddressType. + *

+ * Bluetooth address types + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum BluetoothAddressType { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Public Address + */ + GAP_ADDRESS_TYPE_PUBLIC(0x0000), + + /** + * [1] Random Address + */ + GAP_ADDRESS_TYPE_RANDOM(0x0001); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private BluetoothAddressType(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (BluetoothAddressType s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param bluetoothAddressType + * the code to lookup + * @return enumeration value. + */ + public static BluetoothAddressType getBluetoothAddressType(int bluetoothAddressType) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(bluetoothAddressType) == null) { + return UNKNOWN; + } + + return codeMapping.get(bluetoothAddressType); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ConnectionStatusFlag.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ConnectionStatusFlag.java new file mode 100644 index 00000000000..5de4a9105af --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ConnectionStatusFlag.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration ConnectionStatusFlag. + *

+ * The possible connection status flags are described in the table below. The flags field is a + * bit mask, so multiple flags can be set at a time. If the bit is 1 the flag is active and if the bit is + * 0 the flag is inactive. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum ConnectionStatusFlag { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [1] This status flag tells the connection exists to a remote device. + */ + CONNECTION_CONNECTED(0x0001), + + /** + * [2] This flag tells the connection is encrypted. + */ + CONNECTION_ENCRYPTED(0x0002), + + /** + * [4] Connection completed flag, which is used to tell a new connection has been created. + */ + CONNECTION_COMPLETED(0x0004), + + /** + * [8] This flag tells that connection parameters have changed and. It is set when connection + * parameters have changed due to a link layer operation. + */ + CONNECTION_PARAMETERS_CHANGE(0x0008); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private ConnectionStatusFlag(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (ConnectionStatusFlag s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param connectionStatusFlag + * the code to lookup + * @return enumeration value. + */ + public static ConnectionStatusFlag getConnectionStatusFlag(int connectionStatusFlag) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(connectionStatusFlag) == null) { + return UNKNOWN; + } + + return codeMapping.get(connectionStatusFlag); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapConnectableMode.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapConnectableMode.java new file mode 100644 index 00000000000..d7d8b58a3aa --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapConnectableMode.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration GapConnectableMode. + *

+ * GAP connectable modes + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum GapConnectableMode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Not connectable + */ + GAP_NON_CONNECTABLE(0x0000), + + /** + * [1] Directed Connectable + */ + GAP_DIRECTED_CONNECTABLE(0x0001), + + /** + * [2] Undirected connectable + */ + GAP_UNDIRECTED_CONNECTABLE(0x0002), + + /** + * [3] Same as non-connectable, but also supports ADV_SCAN_IND packets. Device accepts scan + * requests (active scanning) but is not connectable. + */ + GAP_SCANNABLE_NON_CONNECTABLE(0x0003); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private GapConnectableMode(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (GapConnectableMode s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param gapConnectableMode + * the code to lookup + * @return enumeration value. + */ + public static GapConnectableMode getGapConnectableMode(int gapConnectableMode) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(gapConnectableMode) == null) { + return UNKNOWN; + } + + return codeMapping.get(gapConnectableMode); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverMode.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverMode.java new file mode 100644 index 00000000000..06c784bdd23 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverMode.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration GapDiscoverMode. + *

+ * GAP discover modes + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum GapDiscoverMode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Discover only limited discoverable devices, that is, Slaves which have the LE Limited + * Discoverable Mode bit set in the AD type of their Flags advertisement packets. + */ + GAP_DISCOVER_LIMITED(0x0000), + + /** + * [1] Discover limited and generic discoverable devices, that is, Slaves which have the LE + * Limited Discoverable Mode LE General or the Discoverable Mode bit set in the AD type of their + * advertisement Flags packets. + */ + GAP_DISCOVER_GENERIC(0x0001), + + /** + * [2] Discover all devices regardless of the AD type, so also devices in Flags + * non-discoverable mode will be reported to host. + */ + GAP_DISCOVER_OBSERVATION(0x0002), + + /** + * [3] Same as gap_non_discoverable. + */ + GAP_BROADCAST(0x0003), + + /** + * [4] In this advertisement the advertisement and scan response data defined by user will be + * used. The user is responsible of building the advertisement data so that it also contains the + * appropriate desired Flags AD type. + */ + GAP_USER_DATA(0x0004), + + /** + * [128] When turning the most highest bit on in GAP discoverable mode, the remote devices that + * send scan request packets to the advertiser are reported back to the application through + * Scan Response event. This is so called Enhanced Broadcasting mode. + */ + GAP_ENHANCED_BROADCASTING(0x0080); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private GapDiscoverMode(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (GapDiscoverMode s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param gapDiscoverMode + * the code to lookup + * @return enumeration value. + */ + public static GapDiscoverMode getGapDiscoverMode(int gapDiscoverMode) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(gapDiscoverMode) == null) { + return UNKNOWN; + } + + return codeMapping.get(gapDiscoverMode); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverableMode.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverableMode.java new file mode 100644 index 00000000000..94f7e5ecfcf --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/GapDiscoverableMode.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration GapDiscoverableMode. + *

+ * GAP discoverable modes + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum GapDiscoverableMode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Non-discoverable mode: the LE Limited Discoverable Mode and the LE General + * Discoverable Mode bits are NOT set in the AD Flags type. A master can still connect to the + * advertising slave in this mode. + */ + GAP_NON_DISCOVERABLE(0x0000), + + /** + * [1] Discoverable using limited scanning mode: the advertisement packets will carry the LE + * Limited Discoverable Mode bit set in the Flags AD type. + */ + GAP_LIMITED_DISCOVERABLE(0x0001), + + /** + * [2] Discoverable using general scanning mode: the advertisement packets will carry the LE + * General Discoverable Mode bit set in the Flags AD type. + */ + GAP_GENERAL_DISCOVERABLE(0x0002), + + /** + * [3] Same as gap_non_discoverable. + */ + GAP_BROADCAST(0x0003), + + /** + * [4] In this advertisement the advertisement and scan response data defined by user will be + * used. The user is responsible of building the advertisement data so that it also contains the + * appropriate desired Flags AD type. + */ + GAP_USER_DATA(0x0004), + + /** + * [128] When turning the most highest bit on in GAP discoverable mode, the remote devices that + * send scan request packets to the advertiser are reported back to the application through + * Scan Response event. This is so called Enhanced Broadcasting mode. + */ + GAP_ENHANCED_BROADCASTING(0x0080); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private GapDiscoverableMode(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (GapDiscoverableMode s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param gapDiscoverableMode + * the code to lookup + * @return enumeration value. + */ + public static GapDiscoverableMode getGapDiscoverableMode(int gapDiscoverableMode) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(gapDiscoverableMode) == null) { + return UNKNOWN; + } + + return codeMapping.get(gapDiscoverableMode); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ScanResponseType.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ScanResponseType.java new file mode 100644 index 00000000000..2e44310af43 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/ScanResponseType.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration ScanResponseType. + *

+ * Defines the packet types received during a scan response + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum ScanResponseType { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Connectable Advertisement packet + */ + CONNECTABLE_ADVERTISEMENT(0x0000), + + /** + * [2] Non Connectable Advertisement packet + */ + NON_CONNECTABLE_ADVERTISEMENT(0x0002), + + /** + * [4] Scan response packet + */ + SCAN_RESPONSE(0x0004), + + /** + * [6] Discoverable advertisement packet + */ + DISCOVERABLE_ADVERTISEMENT(0x0006); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private ScanResponseType(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (ScanResponseType s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param scanResponseType + * the code to lookup + * @return enumeration value. + */ + public static ScanResponseType getScanResponseType(int scanResponseType) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(scanResponseType) == null) { + return UNKNOWN; + } + + return codeMapping.get(scanResponseType); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/SmpIoCapabilities.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/SmpIoCapabilities.java new file mode 100644 index 00000000000..391bb19fc99 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/enumeration/SmpIoCapabilities.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.enumeration; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the BlueGiga Enumeration SmpIoCapabilities. + *

+ * Security Manager I/O Capabilities + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson - Initial contribution of Java code generator + */ +public enum SmpIoCapabilities { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * [0] Display Only + */ + SM_IO_CAPABILITY_DISPLAYONLY(0x0000), + + /** + * [1] Display with Yes/No-buttons + */ + SM_IO_CAPABILITY_DISPLAYYESNO(0x0001), + + /** + * [2] Keyboard Only + */ + SM_IO_CAPABILITY_KEYBOARDONLY(0x0002), + + /** + * [3] No Input and No Output + */ + SM_IO_CAPABILITY_NOINPUTNOOUTPUT(0x0003), + + /** + * [4] Display with Keyboard + */ + SM_IO_CAPABILITY_KEYBOARDDISPLAY(0x0004); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + private SmpIoCapabilities(int key) { + this.key = key; + } + + private static void initMapping() { + codeMapping = new HashMap(); + for (SmpIoCapabilities s : values()) { + codeMapping.put(s.key, s); + } + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param smpIoCapabilities + * the code to lookup + * @return enumeration value. + */ + public static SmpIoCapabilities getSmpIoCapabilities(int smpIoCapabilities) { + if (codeMapping == null) { + initMapping(); + } + + if (codeMapping.get(smpIoCapabilities) == null) { + return UNKNOWN; + } + + return codeMapping.get(smpIoCapabilities); + } + + /** + * Returns the BlueGiga protocol defined value for this enum + * + * @return the BGAPI enumeration key + */ + public int getKey() { + return key; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/factory/BlueGigaHandlerFactory.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/factory/BlueGigaHandlerFactory.java new file mode 100644 index 00000000000..49ff70fa048 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluegiga/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluegiga/internal/factory/BlueGigaHandlerFactory.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.factory; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothAdapter; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.BlueGigaAdapterConstants; +import org.eclipse.smarthome.binding.bluetooth.bluegiga.handler.BlueGigaBridgeHandler; +import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.UID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * The {@link BlueGigaHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - added support for adapter service registration + */ +@Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.bluegiga", configurationPolicy = ConfigurationPolicy.OPTIONAL) +public class BlueGigaHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Collections + .singleton(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA); + + private final Map> serviceRegs = new HashMap<>(); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA)) { + BlueGigaBridgeHandler handler = new BlueGigaBridgeHandler((Bridge) thing); + registerBluetoothAdapter(handler); + return handler; + } else { + return null; + } + } + + private synchronized void registerBluetoothAdapter(BluetoothAdapter adapter) { + this.serviceRegs.put(adapter.getUID(), bundleContext.registerService(BluetoothAdapter.class.getName(), adapter, + new Hashtable())); + } + + @Override + protected synchronized void removeHandler(ThingHandler thingHandler) { + if (thingHandler instanceof BluetoothAdapter) { + UID uid = ((BluetoothAdapter) thingHandler).getUID(); + ServiceRegistration serviceReg = this.serviceRegs.get(uid); + if (serviceReg != null) { + serviceReg.unregister(); + serviceRegs.remove(uid); + } + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.classpath new file mode 100644 index 00000000000..fdbb371ce27 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.project new file mode 100644 index 00000000000..692d80e9e5a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.binding.bluetooth.bluez + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/ESH-INF/thing/bluez.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/ESH-INF/thing/bluez.xml new file mode 100644 index 00000000000..1e0e9fb4954 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/ESH-INF/thing/bluez.xml @@ -0,0 +1,27 @@ + + + + + + Linux built-in Bluetooth support + + address + + + + + The Bluetooth address of the adapter in format XX:XX:XX:XX:XX:XX + + + + Whether this adapter actively participates in Bluetooth device discovery + true + true + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..03be622458b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/META-INF/MANIFEST.MF @@ -0,0 +1,34 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: BlueZ Bluetooth Adapter +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.bluez;singleton:=true +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: ., + lib/tinyb-0.5.1.jar +Bundle-NativeCode: + lib/armv6hf/libjavatinyb.so;lib/armv6hf/libtinyb.so;processor=arm;osname=linux, + * +Import-Package: org.eclipse.jdt.annotation;resolution:=optional, + org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.bluez, + org.eclipse.smarthome.binding.bluetooth.bluez.handler, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.type, + org.eclipse.smarthome.core.types, + org.osgi.framework, + org.slf4j +Service-Component: OSGI-INF/*.xml +Export-Package: org.eclipse.smarthome.binding.bluetooth.bluez, + org.eclipse.smarthome.binding.bluetooth.bluez.handler +Bundle-ActivationPolicy: lazy diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/NOTICE new file mode 100644 index 00000000000..b5cad373c26 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/NOTICE @@ -0,0 +1,52 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. + +== Third-party Content + +TinyB Version: 0.5.1 +* License: MIT License +* Project: https://github.com/intel-iot-devkit/tinyb +* Source: https://github.com/intel-iot-devkit/tinyb/tree/v0.5.1 + +== Third-party license(s) + +=== MIT License + +The MIT License (MIT) +Copyright © 2015-2016 Intel Corporation + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/OSGI-INF/.gitignore b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/OSGI-INF/.gitignore new file mode 100644 index 00000000000..b878e882aca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/README.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/README.md new file mode 100644 index 00000000000..8d7825bb9a0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/README.md @@ -0,0 +1,29 @@ +## Bluetooth BlueZ Adapter + +This extension supports Bluetooth access via BlueZ on Linux (ARMv6hf). + +## Supported Things + +It defines the following bridge type: + +| Bridge Type ID | Description | +|----------------|---------------------------------------------------------------------------| +| bluez | A Bluetooth adapter that is supported by BlueZ | + + +## Discovery + +If BlueZ is enabled and can be accessed, all available adapters are automatically discovered. + +## Bridge Configuration + +The bluez bridge requires the configuration parameter `address`, which corresponds to the Bluetooth address of the adapter (in format "XX:XX:XX:XX:XX:XX"). +Additionally, the parameter `discovery` can be set to true/false.When set to true, any Bluetooth device of which broadcasts are received is added to the Inbox. + +## Example + +This is how an BlueZ adapter can be configured textually in a *.things file: + +``` +Bridge bluetooth:bluez:hci0 [ address="12:34:56:78:90:AB", discovery=false ] +``` diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/build.properties new file mode 100644 index 00000000000..2846a025d2f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/build.properties @@ -0,0 +1,8 @@ +source..=src/main/java/ +output..=target/classes +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + NOTICE,\ + lib/ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libjavatinyb.so b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libjavatinyb.so new file mode 100644 index 00000000000..b1b5da17fc9 Binary files /dev/null and b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libjavatinyb.so differ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libtinyb.so b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libtinyb.so new file mode 100644 index 00000000000..bf444a7f101 Binary files /dev/null and b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/armv6hf/libtinyb.so differ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/tinyb-0.5.1.jar b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/tinyb-0.5.1.jar new file mode 100644 index 00000000000..dca6d7ad8bd Binary files /dev/null and b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/lib/tinyb-0.5.1.jar differ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/pom.xml new file mode 100644 index 00000000000..4212fc01098 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth.bluez + + Eclipse SmartHome BlueZ Bluetooth Adapter + eclipse-plugin + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZAdapterConstants.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZAdapterConstants.java new file mode 100644 index 00000000000..d45222c081c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZAdapterConstants.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluez; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.core.thing.ThingTypeUID; + +/** + * The {@link BlueZAdapterConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Kai Kreuzer - Initial contribution and API + */ +@NonNullByDefault +public class BlueZAdapterConstants { + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_BLUEZ = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, "bluez"); + + // Properties + public static final String PROPERTY_ADDRESS = "address"; + public static final String PROPERTY_DISCOVERY = "discovery"; + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZBluetoothDevice.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZBluetoothDevice.java new file mode 100644 index 00000000000..7cc09c34202 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/BlueZBluetoothDevice.java @@ -0,0 +1,378 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluez; + +import java.util.Collection; +import java.util.UUID; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothAddress; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCompletionStatus; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDescriptor; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.BluetoothService; +import org.eclipse.smarthome.binding.bluetooth.bluez.handler.BlueZBridgeHandler; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification; +import org.eclipse.smarthome.core.common.ThreadPoolManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import tinyb.BluetoothException; +import tinyb.BluetoothGattCharacteristic; +import tinyb.BluetoothGattDescriptor; +import tinyb.BluetoothGattService; + +/** + * Implementation of BluetoothDevice for BlueZ via TinyB + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +public class BlueZBluetoothDevice extends BluetoothDevice { + + private tinyb.BluetoothDevice device; + + private final Logger logger = LoggerFactory.getLogger(BlueZBluetoothDevice.class); + + private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("bluetooth"); + + /** + * Constructor + * + * @param adapter the bridge handler through which this device is connected + * @param address the Bluetooth address of the device + * @param name the name of the device + */ + public BlueZBluetoothDevice(BlueZBridgeHandler adapter, BluetoothAddress address, String name) { + super(adapter, address); + this.name = name; + logger.debug("Creating BlueZ device with address '{}'", address); + } + + /** + * Constructor + * + * @param adapter the bridge handler through which this device is connected + * @param tinybDevice the tinyB device to use internally (which already contains address and name information) + */ + public BlueZBluetoothDevice(BlueZBridgeHandler adapter, tinyb.BluetoothDevice tinybDevice) { + super(adapter, new BluetoothAddress(tinybDevice.getAddress())); + this.name = tinybDevice.getName(); + this.device = tinybDevice; + } + + /** + * Initializes a newly created instance of this class. + * It tries to set the internal tinyB device, if it isn't yet available, which is done asynchronously as + * BlueZ can take a while (it seems to do an active scan for the physical device). + * + * This method should always be called directly after creating a new object instance. + */ + public synchronized void initialize() { + scheduler.submit(() -> { + if (this.device == null) { + tinyb.BluetoothDevice tinybDevice = findTinybDevice(address.toString()); + if (tinybDevice != null) { + device = tinybDevice; + enableNotifications(); + } + } else { + enableNotifications(); + } + }); + } + + /** + * Updates the internally used tinyB device instance. It replaces any previous instance, disables notifications on + * it and enables notifications on the new instance. + * + * @param tinybDevice the new device instance to use for communication + */ + public synchronized void updateTinybDevice(tinyb.BluetoothDevice tinybDevice) { + if (device != null && !tinybDevice.equals(device)) { + // we need to replace the instance - let's deactivate notifications on the old one + disableNotifications(); + } + if (this.device == null || !tinybDevice.equals(device)) { + this.device = tinybDevice; + enableNotifications(); + } + tinyb.BluetoothDevice dev = this.device; + if (dev != null) { + this.rssi = (int) dev.getRSSI(); + this.txPower = (int) dev.getTxPower(); + if (dev.getConnected()) { + this.connectionState = ConnectionState.CONNECTED; + } + } + refreshServices(); + } + + private tinyb.@Nullable BluetoothDevice findTinybDevice(String address) { + Collection deviceList = ((BlueZBridgeHandler) getAdapter()).getTinyBDevices(); + logger.trace("Searching for '{}' in {} devices.", address, deviceList.size()); + return deviceList.stream().filter(d -> d.getAddress().equals(address)).findFirst().orElse(null); + } + + private void enableNotifications() { + logger.debug("Enabling notifications for device '{}'", device.getAddress()); + device.enableRSSINotifications(n -> { + rssi = (int) n; + BluetoothScanNotification notification = new BluetoothScanNotification(); + notification.setRssi(n); + notifyListeners(BluetoothEventType.SCAN_RECORD, notification); + }); + device.enableConnectedNotifications(connected -> { + connectionState = connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED; + logger.debug("Connection state of '{}' changed to {}", address, connectionState); + notifyListeners(BluetoothEventType.CONNECTION_STATE, + new BluetoothConnectionStatusNotification(connectionState)); + }); + device.enableServicesResolvedNotifications(resolved -> { + logger.debug("Received services resolved event for '{}': {}", address, resolved); + if (resolved) { + refreshServices(); + notifyListeners(BluetoothEventType.SERVICES_DISCOVERED); + } + }); + device.enableServiceDataNotifications(data -> { + logger.debug("Received service data for '{}': {}", address, data); + }); + } + + private void disableNotifications() { + logger.debug("Disabling notifications for device '{}'", device.getAddress()); + device.disableBlockedNotifications(); + device.disableManufacturerDataNotifications(); + device.disablePairedNotifications(); + device.disableRSSINotifications(); + device.disableServiceDataNotifications(); + device.disableTrustedNotifications(); + } + + protected void refreshServices() { + if (device.getServices().size() > getServices().size()) { + for (BluetoothGattService tinybService : device.getServices()) { + BluetoothService service = new BluetoothService(UUID.fromString(tinybService.getUUID()), + tinybService.getPrimary()); + for (BluetoothGattCharacteristic tinybCharacteristic : tinybService.getCharacteristics()) { + BluetoothCharacteristic characteristic = new BluetoothCharacteristic( + UUID.fromString(tinybCharacteristic.getUUID()), 0); + for (BluetoothGattDescriptor tinybDescriptor : tinybCharacteristic.getDescriptors()) { + BluetoothDescriptor descriptor = new BluetoothDescriptor(characteristic, + UUID.fromString(tinybDescriptor.getUUID())); + characteristic.addDescriptor(descriptor); + } + service.addCharacteristic(characteristic); + } + addService(service); + } + notifyListeners(BluetoothEventType.SERVICES_DISCOVERED); + } + } + + @Override + public boolean connect() { + if (device != null && !device.getConnected()) { + try { + return device.connect(); + } catch (BluetoothException e) { + if ("Timeout was reached".equals(e.getMessage())) { + notifyListeners(BluetoothEventType.CONNECTION_STATE, + new BluetoothConnectionStatusNotification(ConnectionState.DISCONNECTED)); + } else if (e.getMessage() != null && e.getMessage().contains("Protocol not available")) { + // this device does not seem to be connectable at all - let's log a warning and ignore it. + logger.warn("Bluetooth device '{}' does not allow a connection.", device.getAddress()); + } else { + logger.debug("Exception occurred when trying to connect device '{}': {}", device.getAddress(), + e.getMessage()); + } + } + } + return false; + } + + @Override + public boolean disconnect() { + if (device != null && device.getConnected()) { + logger.debug("Disconnecting '{}'", address); + try { + return device.disconnect(); + } catch (BluetoothException e) { + logger.debug("Exception occurred when trying to disconnect device '{}': {}", device.getAddress(), + e.getMessage()); + } + } + return false; + } + + @Override + public boolean readCharacteristic(BluetoothCharacteristic characteristic) { + if (device == null) { + throw new IllegalStateException("TinyB device is not yet set"); + } + BluetoothGattCharacteristic c = getTinybCharacteristicByUUID(characteristic.getUuid().toString()); + scheduler.submit(() -> { + try { + byte[] value = c.readValue(); + characteristic.setValue(value); + notifyListeners(BluetoothEventType.CHARACTERISTIC_READ_COMPLETE, characteristic, + BluetoothCompletionStatus.SUCCESS); + } catch (BluetoothException e) { + logger.debug("Exception occurred when trying to read characteristic '{}': {}", characteristic.getUuid(), + e.getMessage()); + notifyListeners(BluetoothEventType.CHARACTERISTIC_READ_COMPLETE, characteristic, + BluetoothCompletionStatus.ERROR); + } + }); + return true; + } + + @Override + public boolean writeCharacteristic(BluetoothCharacteristic characteristic) { + if (device == null) { + throw new IllegalStateException("TinyB device is not yet set"); + } + BluetoothGattCharacteristic c = getTinybCharacteristicByUUID(characteristic.getUuid().toString()); + scheduler.submit(() -> { + try { + BluetoothCompletionStatus successStatus = c.writeValue(characteristic.getByteValue()) + ? BluetoothCompletionStatus.SUCCESS + : BluetoothCompletionStatus.ERROR; + notifyListeners(BluetoothEventType.CHARACTERISTIC_WRITE_COMPLETE, characteristic, successStatus); + } catch (BluetoothException e) { + logger.debug("Exception occurred when trying to read characteristic '{}': {}", characteristic.getUuid(), + e.getMessage()); + notifyListeners(BluetoothEventType.CHARACTERISTIC_WRITE_COMPLETE, characteristic, + BluetoothCompletionStatus.ERROR); + } + }); + return true; + } + + @Override + public boolean enableNotifications(BluetoothCharacteristic characteristic) { + if (device == null || !device.getConnected()) { + throw new IllegalStateException("TinyB device is not set or not connected"); + } + BluetoothGattCharacteristic c = getTinybCharacteristicByUUID(characteristic.getUuid().toString()); + if (c != null) { + try { + c.enableValueNotifications(value -> { + logger.debug("Received new value '{}' for characteristic '{}' of device '{}'", value, + characteristic.getUuid(), address); + characteristic.setValue(value); + notifyListeners(BluetoothEventType.CHARACTERISTIC_UPDATED, characteristic); + }); + } catch (BluetoothException e) { + if (e.getMessage().contains("Already notifying")) { + return false; + } else if (e.getMessage().contains("In Progress")) { + // let's retry in 10 seconds + scheduler.schedule(() -> enableNotifications(characteristic), 10, TimeUnit.SECONDS); + } else { + logger.warn("Exception occurred while activating notifications on '{}'", address, e); + } + } + return true; + } else { + logger.warn("Characteristic '{}' is missing on device '{}'.", characteristic.getUuid(), address); + return false; + } + } + + @Override + public boolean disableNotifications(BluetoothCharacteristic characteristic) { + if (device == null || !device.getConnected()) { + throw new IllegalStateException("TinyB device is not set or not connected"); + } + BluetoothGattCharacteristic c = getTinybCharacteristicByUUID(characteristic.getUuid().toString()); + if (c != null) { + c.disableValueNotifications(); + return true; + } else { + logger.warn("Characteristic '{}' is missing on device '{}'.", characteristic.getUuid(), address); + return false; + } + } + + @Override + public boolean enableNotifications(BluetoothDescriptor descriptor) { + if (device == null || !device.getConnected()) { + throw new IllegalStateException("TinyB device is not set or not connected"); + } + BluetoothGattDescriptor d = getTinybDescriptorByUUID(descriptor.getUuid().toString()); + if (d != null) { + d.enableValueNotifications(value -> { + logger.debug("Received new value '{}' for descriptor '{}' of device '{}'", value, descriptor.getUuid(), + address); + descriptor.setValue(value); + notifyListeners(BluetoothEventType.DESCRIPTOR_UPDATED, descriptor); + }); + return true; + } else { + logger.warn("Descriptor '{}' is missing on device '{}'.", descriptor.getUuid(), address); + return false; + } + } + + @Override + public boolean disableNotifications(BluetoothDescriptor descriptor) { + if (device == null) { + throw new IllegalStateException("TinyB device is not yet set"); + } + BluetoothGattDescriptor d = getTinybDescriptorByUUID(descriptor.getUuid().toString()); + if (d != null) { + d.disableValueNotifications(); + return true; + } else { + logger.warn("Descriptor '{}' is missing on device '{}'.", descriptor.getUuid(), address); + return false; + } + } + + private BluetoothGattCharacteristic getTinybCharacteristicByUUID(String uuid) { + for (BluetoothGattService service : device.getServices()) { + for (BluetoothGattCharacteristic c : service.getCharacteristics()) { + if (c.getUUID().equals(uuid)) { + return c; + } + } + } + return null; + } + + private BluetoothGattDescriptor getTinybDescriptorByUUID(String uuid) { + for (BluetoothGattService service : device.getServices()) { + for (BluetoothGattCharacteristic c : service.getCharacteristics()) { + for (BluetoothGattDescriptor d : c.getDescriptors()) { + if (d.getUUID().equals(uuid)) { + return d; + } + } + } + } + return null; + } + + /** + * Clean up and release memory. + */ + public void dispose() { + disableNotifications(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/handler/BlueZBridgeHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/handler/BlueZBridgeHandler.java new file mode 100644 index 00000000000..027e2c93f16 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/handler/BlueZBridgeHandler.java @@ -0,0 +1,275 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluez.handler; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothAdapter; +import org.eclipse.smarthome.binding.bluetooth.BluetoothAddress; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDiscoveryListener; +import org.eclipse.smarthome.binding.bluetooth.bluez.BlueZAdapterConstants; +import org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice; +import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.ThingStatusDetail; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler; +import org.eclipse.smarthome.core.types.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import tinyb.BluetoothException; +import tinyb.BluetoothManager; + +/** + * The {@link BlueZBridgeHandler} is responsible for talking to the BlueZ stack. + * It provides a private interface for {@link BlueZBluetoothDevice}s to access the stack and provides top + * level adaptor functionality for scanning and arbitration. + * + * @author Kai Kreuzer - Initial contribution and API + */ +public class BlueZBridgeHandler extends BaseBridgeHandler implements BluetoothAdapter { + + private static final Logger logger = LoggerFactory.getLogger(BlueZBridgeHandler.class); + + private tinyb.BluetoothAdapter adapter; + + private final Map tinybDeviceCache = new ConcurrentHashMap<>(); + + // Our BT address + private BluetoothAddress address; + + // internal flag for the discovery configuration + private boolean discoveryActive = true; + + // Map of Bluetooth devices known to this bridge. + // This is all devices we have heard on the network - not just things bound to the bridge + private final Map devices = new ConcurrentHashMap<>(); + + // Set of discovery listeners + protected final Set discoveryListeners = new CopyOnWriteArraySet<>(); + + private ScheduledFuture discoveryJob; + + /** + * Constructor + * + * @param bridge the bridge definition for this handler + */ + public BlueZBridgeHandler(Bridge bridge) { + super(bridge); + } + + @Override + public void initialize() { + try { + BluetoothManager.getBluetoothManager(); + } catch (UnsatisfiedLinkError e) { + throw new IllegalStateException("BlueZ JNI connection cannot be established.", e); + } + + Object cfgAddress = getConfig().get(BlueZAdapterConstants.PROPERTY_ADDRESS); + if (cfgAddress != null) { + address = new BluetoothAddress(cfgAddress.toString()); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "address not set"); + return; + } + + Object discovery = getConfig().get(BlueZAdapterConstants.PROPERTY_DISCOVERY); + if (discovery != null && discovery.toString().equalsIgnoreCase(Boolean.FALSE.toString())) { + discoveryActive = false; + logger.debug("Deactivated discovery participation."); + } + + logger.debug("Creating BlueZ adapter with address '{}'", address); + for (tinyb.BluetoothAdapter a : BluetoothManager.getBluetoothManager().getAdapters()) { + if (a.getAddress().equals(address.toString())) { + adapter = a; + updateStatus(ThingStatus.ONLINE); + if (discoveryActive) { + adapter.startDiscovery(); + } + discoveryJob = scheduler.scheduleWithFixedDelay(() -> { + checkForNewDevices(); + }, 0, 10, TimeUnit.SECONDS); + return; + } + } + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No adapter for this address found."); + } + + @Override + public ThingUID getUID() { + return getThing().getUID(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + } + + @Override + public void addDiscoveryListener(BluetoothDiscoveryListener listener) { + discoveryListeners.add(listener); + } + + @Override + public void removeDiscoveryListener(@Nullable BluetoothDiscoveryListener listener) { + discoveryListeners.remove(listener); + } + + @Override + public void scanStart() { + adapter.setRssiDiscoveryFilter(-96); + adapter.startDiscovery(); + for (tinyb.BluetoothDevice tinybDevice : adapter.getDevices()) { + synchronized (devices) { + logger.debug("Device {} has RSSI {}", tinybDevice.getAddress(), tinybDevice.getRSSI()); + BluetoothDevice device = devices.get(tinybDevice.getAddress()); + if (device == null) { + createAndRegisterBlueZDevice(tinybDevice); + } else { + // let's update the rssi and txpower values + device.setRssi(tinybDevice.getRSSI()); + device.setTxPower(tinybDevice.getTxPower()); + // The Bluetooth discovery expects a complete list on every scan, + // so we also have to report the already known devices. + notifyDiscoveryListeners(device); + } + } + } + } + + @Override + public void scanStop() { + if (adapter != null && adapter.getDiscovering()) { + try { + adapter.stopDiscovery(); + } catch (BluetoothException e) { + // tinyb often throws the exception + // tinyb.BluetoothException: GDBus.Error:org.bluez.Error.Failed: No discovery started + // here, although we first check whether discovery is active or not. + // As a workaround, we simply ignore this exception. + } + } + } + + @Override + public BluetoothAddress getAddress() { + return address; + } + + @Override + public BluetoothDevice getDevice(BluetoothAddress address) { + if (devices.containsKey(address.toString())) { + return devices.get(address.toString()); + } else { + synchronized (devices) { + if (devices.containsKey(address.toString())) { + return devices.get(address.toString()); + } else { + BlueZBluetoothDevice device = new BlueZBluetoothDevice(this, address, ""); + device.initialize(); + devices.put(address.toString(), device); + return device; + } + } + } + } + + @Override + public void dispose() { + if (discoveryJob != null) { + discoveryJob.cancel(true); + discoveryJob = null; + } + for (BluetoothDevice device : devices.values()) { + ((BlueZBluetoothDevice) device).dispose(); + } + devices.clear(); + } + + public Collection getTinyBDevices() { + synchronized (tinybDeviceCache) { + return Collections.unmodifiableCollection(tinybDeviceCache.values()); + } + } + + private void checkForNewDevices() { + logger.debug("Refreshing Bluetooth device list..."); + Set newAddresses = new HashSet<>(); + List tinybDevices = adapter.getDevices(); + logger.debug("Found {} Bluetooth devices.", tinybDevices.size()); + synchronized (tinybDeviceCache) { + tinybDeviceCache.clear(); + tinybDevices.stream().forEach(d -> tinybDeviceCache.put(d.getAddress(), d)); + } + for (tinyb.BluetoothDevice tinybDevice : tinybDevices) { + synchronized (devices) { + newAddresses.add(tinybDevice.getAddress()); + BlueZBluetoothDevice device = (BlueZBluetoothDevice) devices.get(tinybDevice.getAddress()); + if (device == null) { + createAndRegisterBlueZDevice(tinybDevice); + } else { + device.updateTinybDevice(tinybDevice); + notifyDiscoveryListeners(device); + } + } + } + // clean up orphaned entries + synchronized (devices) { + Set oldAdresses = devices.keySet(); + for (String address : oldAdresses) { + if (!newAddresses.contains(address)) { + devices.remove(address); + } + } + } + } + + private BlueZBluetoothDevice createAndRegisterBlueZDevice(tinyb.BluetoothDevice tinybDevice) { + BlueZBluetoothDevice device = new BlueZBluetoothDevice(this, tinybDevice); + device.initialize(); + devices.put(tinybDevice.getAddress(), device); + notifyDiscoveryListeners(device); + return device; + } + + private void notifyDiscoveryListeners(BluetoothDevice device) { + if (discoveryActive && deviceReachable(device)) { + for (BluetoothDiscoveryListener listener : discoveryListeners) { + listener.deviceDiscovered(device); + } + } else { + logger.trace("Not notifying listeners for device '{}', because it is not reachable.", device.getAddress()); + } + } + + private boolean deviceReachable(BluetoothDevice device) { + Integer rssi = device.getRssi(); + return rssi != null && rssi != 0; + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/BlueZHandlerFactory.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/BlueZHandlerFactory.java new file mode 100644 index 00000000000..d86237ca96a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/BlueZHandlerFactory.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluez.internal; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothAdapter; +import org.eclipse.smarthome.binding.bluetooth.bluez.BlueZAdapterConstants; +import org.eclipse.smarthome.binding.bluetooth.bluez.handler.BlueZBridgeHandler; +import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.UID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * The {@link BlueZHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Kai Kreuzer - Initial contribution and API + */ +@Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.bluetooth.bluez", configurationPolicy = ConfigurationPolicy.OPTIONAL) +public class BlueZHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Collections + .singleton(BlueZAdapterConstants.THING_TYPE_BLUEZ); + + private final Map> serviceRegs = new HashMap<>(); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(BlueZAdapterConstants.THING_TYPE_BLUEZ)) { + BlueZBridgeHandler handler = new BlueZBridgeHandler((Bridge) thing); + registerBluetoothAdapter(handler); + return handler; + } else { + return null; + } + } + + private synchronized void registerBluetoothAdapter(BluetoothAdapter adapter) { + this.serviceRegs.put(adapter.getUID(), bundleContext.registerService(BluetoothAdapter.class.getName(), adapter, + new Hashtable())); + } + + @Override + protected synchronized void removeHandler(ThingHandler thingHandler) { + if (thingHandler instanceof BluetoothAdapter) { + UID uid = ((BluetoothAdapter) thingHandler).getUID(); + ServiceRegistration serviceReg = this.serviceRegs.remove(uid); + if (serviceReg != null) { + serviceReg.unregister(); + } + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/discovery/BlueZDiscoveryService.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/discovery/BlueZDiscoveryService.java new file mode 100644 index 00000000000..3d4bb801956 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.bluez/src/main/java/org/eclipse/smarthome/binding/bluetooth/bluez/internal/discovery/BlueZDiscoveryService.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.bluez.internal.discovery; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.bluez.BlueZAdapterConstants; +import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService; +import org.eclipse.smarthome.config.discovery.DiscoveryResult; +import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; +import org.eclipse.smarthome.config.discovery.DiscoveryService; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Modified; + +import tinyb.BluetoothAdapter; +import tinyb.BluetoothManager; + +/** + * This is a discovery service, which checks whether we are running on a Linux with a BlueZ stack. + * If this is the case, we create a bridge handler that provides Bluetooth access through BlueZ. + * + * @author Kai Kreuzer - Initial Contribution and API + * + */ +@Component(immediate = true, service = DiscoveryService.class, configurationPid = "discovery.bluetooth.bluez") +public class BlueZDiscoveryService extends AbstractDiscoveryService { + + private BluetoothManager manager; + + public BlueZDiscoveryService() { + super(Collections.singleton(BlueZAdapterConstants.THING_TYPE_BLUEZ), 1, true); + } + + @Override + @Activate + protected void activate(@Nullable Map<@NonNull String, @Nullable Object> configProperties) { + modified(configProperties); + } + + @Override + @Modified + protected void modified(@Nullable Map<@NonNull String, @Nullable Object> configProperties) { + super.modified(configProperties); + if (isBackgroundDiscoveryEnabled()) { + startScan(); + } + } + + @Override + @Deactivate + protected void deactivate() { + super.deactivate(); + } + + @Override + protected void startScan() { + try { + manager = BluetoothManager.getBluetoothManager(); + manager.getAdapters().stream().map(this::createDiscoveryResult).forEach(this::thingDiscovered); + } catch (UnsatisfiedLinkError e) { + // we cannot initialize the BlueZ stack + return; + } + } + + private DiscoveryResult createDiscoveryResult(BluetoothAdapter adapter) { + return DiscoveryResultBuilder.create(new ThingUID(BlueZAdapterConstants.THING_TYPE_BLUEZ, getId(adapter))) + .withLabel("Bluetooth Interface " + adapter.getName()) + .withProperty(BlueZAdapterConstants.PROPERTY_ADDRESS, adapter.getAddress()) + .withRepresentationProperty(BlueZAdapterConstants.PROPERTY_ADDRESS).build(); + } + + private String getId(BluetoothAdapter adapter) { + return adapter.getInterfaceName().replaceAll("[^a-zA-Z0-9_]", ""); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.classpath new file mode 100644 index 00000000000..7f457fa4138 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.project new file mode 100644 index 00000000000..a58bd02b7d9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.binding.bluetooth.blukii + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/ESH-INF/thing/blukii.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/ESH-INF/thing/blukii.xml new file mode 100644 index 00000000000..e7c3777a349 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/ESH-INF/thing/blukii.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + A Blukii Button + + + + + + + + + + + + + + + + + + + + + Bluetooth address in XX:XX:XX:XX:XX:XX format + + + + + + + Switch + + + + Number + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d83692ace38 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Blukii Binding +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.blukii +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: . +Import-Package: + org.eclipse.jdt.annotation;resolution:=optional, + org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.binding.firmware, + org.eclipse.smarthome.core.thing.type, + org.eclipse.smarthome.core.types, + org.slf4j +Service-Component: OSGI-INF/*.xml +Export-Package: + org.eclipse.smarthome.binding.bluetooth.blukii, + org.eclipse.smarthome.binding.bluetooth.blukii.handler +Bundle-ActivationPolicy: lazy diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/NOTICE new file mode 100644 index 00000000000..b8675cd02e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/NOTICE @@ -0,0 +1,19 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/OSGI-INF/.gitignore b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/OSGI-INF/.gitignore new file mode 100644 index 00000000000..b878e882aca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/README.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/README.md new file mode 100644 index 00000000000..7f9817a86ca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/README.md @@ -0,0 +1,52 @@ +# YeeLightBlue Binding + +_Give some details about what this binding is meant for - a protocol, system, specific device._ + +_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._ + +## Supported Things + +_Please describe the different supported things / devices within this section._ +_Which different types are supported, which models were tested etc.?_ +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Discovery + +_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._ + +## Binding Configuration + +_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_ + +``` +# Configuration for the Philips Hue Binding +# +# Default secret key for the pairing of the Philips Hue Bridge. +# It has to be between 10-40 (alphanumeric) characters +# This may be changed by the user for security reasons. +secret=EclipseSmartHome +``` + +_Note that it is planned to generate some part of this based on the information that is available within ```ESH-INF/binding``` of your binding._ + +_If your binding does not offer any generic configurations, you can remove this section completely._ + +## Thing Configuration + +_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Channels + +_Here you should provide information about available channel types, what their meaning is and how they can be used._ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Full Example + +_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._ + +## Any custom content here! + +_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/build.properties new file mode 100644 index 00000000000..a6cfff567c9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/build.properties @@ -0,0 +1,7 @@ +source..=src/main/java/ +output..=target/classes +bin.includes=META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + NOTICE diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/pom.xml new file mode 100644 index 00000000000..026de1da344 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth.blukii + + Eclipse SmartHome Blukii Binding + eclipse-plugin + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/BlukiiBindingConstants.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/BlukiiBindingConstants.java new file mode 100644 index 00000000000..f65105e65ba --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/BlukiiBindingConstants.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.blukii; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.type.ChannelTypeUID; + +/** + * The {@link BlukiiBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Kai Kreuzer - Initial contribution + */ +public class BlukiiBindingConstants { + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_BUTTON = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, + "blukii_bts"); + + public final static String BLUKII_PREFIX = "blukii"; + + // Channel IDs + public final static String CHANNEL_ID_ACCELREPORT = "accelReport"; + public final static String CHANNEL_ID_X = "accelX"; + public final static String CHANNEL_ID_Y = "accelY"; + public final static String CHANNEL_ID_Z = "accelZ"; + + // Channel types UIDs + public final static ChannelTypeUID CHANNEL_TYPE_UID_ACCEL_REPORT = new ChannelTypeUID( + BluetoothBindingConstants.BINDING_ID, "blukii_accel_report"); + public final static ChannelTypeUID CHANNEL_TYPE_UID_ACCEL = new ChannelTypeUID(BluetoothBindingConstants.BINDING_ID, + "blukii_accel"); + + // Characteristics + public final static UUID CHAR_ACCEL_REPORT = UUID.fromString("0000feb1-0000-1000-8000-00805f9b34fb"); + public final static UUID CHAR_ACCEL_X = UUID.fromString("0000feb3-0000-1000-8000-00805f9b34fb"); + public final static UUID CHAR_ACCEL_Y = UUID.fromString("0000feb4-0000-1000-8000-00805f9b34fb"); + public final static UUID CHAR_ACCEL_Z = UUID.fromString("0000feb5-0000-1000-8000-00805f9b34fb"); +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/handler/BlukiiHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/handler/BlukiiHandler.java new file mode 100644 index 00000000000..216270adc30 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/handler/BlukiiHandler.java @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.blukii.handler; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDeviceListener; +import org.eclipse.smarthome.binding.bluetooth.ConnectedBluetoothHandler; +import org.eclipse.smarthome.binding.bluetooth.blukii.BlukiiBindingConstants; +import org.eclipse.smarthome.core.library.types.DecimalType; +import org.eclipse.smarthome.core.library.types.OnOffType; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.types.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link BlukiiHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Kai Kreuzer - Initial contribution and API + */ +public class BlukiiHandler extends ConnectedBluetoothHandler implements BluetoothDeviceListener { + + private final Logger logger = LoggerFactory.getLogger(BlukiiHandler.class); + + public BlukiiHandler(Thing thing) { + super(thing); + } + + @Override + public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + super.handleCommand(channelUID, command); + if (channelUID.getId().equals(BlukiiBindingConstants.CHANNEL_ID_ACCELREPORT) && command instanceof OnOffType) { + BluetoothCharacteristic characteristic = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_REPORT); + int[] value = command == OnOffType.ON ? new int[] { 1 } : new int[] { 0 }; + characteristic.setValue(value); + device.writeCharacteristic(characteristic); + } + } + + @Override + public void onServicesDiscovered() { + super.onServicesDiscovered(); + BluetoothCharacteristic xAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_X); + BluetoothCharacteristic yAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_Y); + BluetoothCharacteristic zAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_Z); + activateChannel(xAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_X); + activateChannel(yAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_Y); + activateChannel(zAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_Z); + } + + @Override + public void onCharacteristicUpdate(@NonNull BluetoothCharacteristic characteristic) { + super.onCharacteristicUpdate(characteristic); + if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_REPORT)) { + OnOffType enabled = characteristic.getValue()[0] == 1 ? OnOffType.ON : OnOffType.OFF; + updateState(BlukiiBindingConstants.CHANNEL_ID_ACCELREPORT, enabled); + } + if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_X)) { + Integer x = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0); + updateState(BlukiiBindingConstants.CHANNEL_ID_X, new DecimalType(x)); + } + if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_Y)) { + Integer y = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0); + updateState(BlukiiBindingConstants.CHANNEL_ID_Y, new DecimalType(y)); + } + if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_Z)) { + Integer z = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0); + updateState(BlukiiBindingConstants.CHANNEL_ID_Z, new DecimalType(z)); + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java new file mode 100644 index 00000000000..acb73a6bd1d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.blukii.internal; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.blukii.BlukiiBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.discovery.BluetoothDiscoveryParticipant; +import org.eclipse.smarthome.config.discovery.DiscoveryResult; +import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.osgi.service.component.annotations.Component; + +/** + * This discovery participant is able to recognize blukii devices and create discovery results for them. + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +@Component(immediate = true) +public class BlukiiDiscoveryParticipant implements BluetoothDiscoveryParticipant { + + @Override + public @NonNull Set<@NonNull ThingTypeUID> getSupportedThingTypeUIDs() { + return Collections.singleton(BlukiiBindingConstants.THING_TYPE_BUTTON); + } + + @Override + public @Nullable ThingUID getThingUID(@NonNull BluetoothDevice device) { + if (device.getName() != null && device.getName().startsWith(BlukiiBindingConstants.BLUKII_PREFIX)) { + return new ThingUID(BlukiiBindingConstants.THING_TYPE_BUTTON, device.getAdapter().getUID(), + device.getAddress().toString().toLowerCase().replace(":", "")); + } else { + return null; + } + } + + @Override + public DiscoveryResult createResult(@NonNull BluetoothDevice device) { + ThingUID thingUID = getThingUID(device); + + if (thingUID != null) { + String label = device.getName(); + + Map properties = new HashMap<>(); + properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString()); + properties.put(Thing.PROPERTY_VENDOR, "Schneider Schreibgeräte GmbH"); + Integer txPower = device.getTxPower(); + if (txPower != null) { + properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower)); + } + + // Create the discovery result and add to the inbox + return DiscoveryResultBuilder.create(thingUID).withProperties(properties) + .withRepresentationProperty(BluetoothBindingConstants.CONFIGURATION_ADDRESS) + .withBridge(device.getAdapter().getUID()).withLabel(label).build(); + } else { + return null; + } + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java new file mode 100644 index 00000000000..227f5a20b53 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.blukii/src/main/java/org/eclipse/smarthome/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.blukii.internal; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.blukii.BlukiiBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.blukii.handler.BlukiiHandler; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * The {@link BlukiiHandlerFactory} is responsible for creating things and thing handlers. + * + * @author Kai Kreuzer - Initial contribution + */ +@Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.blukii", configurationPolicy = ConfigurationPolicy.OPTIONAL) +public class BlukiiHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Collections + .singleton(BlukiiBindingConstants.THING_TYPE_BUTTON); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(BlukiiBindingConstants.THING_TYPE_BUTTON)) { + return new BlukiiHandler(thing); + } + + return null; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.classpath new file mode 100644 index 00000000000..64777f25c82 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.project new file mode 100644 index 00000000000..1085ce79bc0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/.project @@ -0,0 +1,28 @@ + + + org.eclipse.smarthome.binding.bluetooth.test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2b614bac445 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Bluetooth Binding Tests +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.test;singleton:=true +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Fragment-Host: org.eclipse.smarthome.binding.bluetooth +Import-Package: org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.core.events, + org.eclipse.smarthome.core.thing.util, + org.eclipse.smarthome.test.java, + org.eclipse.smarthome.test.storage, + org.hamcrest;core=split, + org.junit;version="4.0.0", + org.mockito, + org.objenesis, + org.osgi.framework, + org.osgi.service.device, + org.slf4j +Require-Bundle: org.junit,org.mockito,org.hamcrest diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/NOTICE new file mode 100644 index 00000000000..b8675cd02e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/NOTICE @@ -0,0 +1,19 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/build.properties new file mode 100644 index 00000000000..271c737ba03 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/build.properties @@ -0,0 +1,6 @@ +source.. = src/test/java/ +output.. = target/classes +bin.includes = META-INF/,\ + .,\ + NOTICE + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/org.eclipse.smarthome.binding.bluetooth.test.launch b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/org.eclipse.smarthome.binding.bluetooth.test.launch new file mode 100644 index 00000000000..b21dae0f3da --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/org.eclipse.smarthome.binding.bluetooth.test.launch @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/pom.xml new file mode 100644 index 00000000000..f9542698dcb --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/pom.xml @@ -0,0 +1,119 @@ + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth.test + + eclipse-test-plugin + + Eclipse SmartHome Bluetooth Binding Tests + + + + + org.eclipse.tycho + target-platform-configuration + + + + + + eclipse-plugin + org.eclipse.equinox.event + 0.0.0 + + + eclipse-plugin + org.eclipse.equinox.ds + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.config.xml + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.core.thing.xml + 0.0.0 + + + eclipse-plugin + org.eclipse.smarthome.core.binding.xml + 0.0.0 + + + + + + + org.eclipse.tycho + tycho-surefire-plugin + + + + eclipse-plugin + ch.qos.logback.classic + 0.0.0 + + + eclipse-plugin + ch.qos.logback.core + 0.0.0 + + + eclipse-plugin + ch.qos.logback.slf4j + 0.0.0 + + + + + org.eclipse.equinox.ds + 1 + true + + + org.eclipse.equinox.event + 2 + true + + + org.eclipse.smarthome.core + 4 + true + + + org.eclipse.smarthome.core.thing + 4 + true + + + org.eclipse.smarthome.config.xml + 4 + true + + + org.eclipse.smarthome.core.thing.xml + 4 + true + + + org.eclipse.smarthome.core.binding.xml + 4 + true + + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/src/test/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddressTest.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/src/test/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddressTest.java new file mode 100644 index 00000000000..6b23972797a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.test/src/test/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddressTest.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import org.junit.Test; + +public class BluetoothAddressTest { + + @Test(expected = IllegalArgumentException.class) + public void testConstructorWithNullParam() { + new BluetoothAddress(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorWithoutColons() { + new BluetoothAddress("123456789ABC"); + } + + @Test + public void testConstructorCorrect() { + new BluetoothAddress("12:34:56:78:9A:BC"); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.classpath new file mode 100644 index 00000000000..7f457fa4138 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.project new file mode 100644 index 00000000000..5ea9154ebf4 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.binding.bluetooth.yeelightblue + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/ESH-INF/thing/yeelight_blue2.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/ESH-INF/thing/yeelight_blue2.xml new file mode 100644 index 00000000000..a3484f8a566 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/ESH-INF/thing/yeelight_blue2.xml @@ -0,0 +1,38 @@ + + + + + + + + + + A bluetooth enabled color bulb + + + + + + + + + + Bluetooth address in XX:XX:XX:XX:XX:XX format + + + + + + + + Color + + The color channel allows to control the color of a light. + It is also possible to dim values and switch the light on and off. + + ColorLight + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..e62d9488704 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: YeelightBlue Binding +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.yeelightblue +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: . +Import-Package: + org.eclipse.jdt.annotation;resolution:=optional, + org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.binding.firmware, + org.eclipse.smarthome.core.thing.type, + org.eclipse.smarthome.core.types, + org.slf4j +Service-Component: OSGI-INF/*.xml +Export-Package: + org.eclipse.smarthome.binding.bluetooth.yeelightblue, + org.eclipse.smarthome.binding.bluetooth.yeelightblue.handler +Bundle-ActivationPolicy: lazy diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/NOTICE new file mode 100644 index 00000000000..b8675cd02e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/NOTICE @@ -0,0 +1,19 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/OSGI-INF/.gitignore b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/OSGI-INF/.gitignore new file mode 100644 index 00000000000..b878e882aca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/README.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/README.md new file mode 100644 index 00000000000..7f9817a86ca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/README.md @@ -0,0 +1,52 @@ +# YeeLightBlue Binding + +_Give some details about what this binding is meant for - a protocol, system, specific device._ + +_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._ + +## Supported Things + +_Please describe the different supported things / devices within this section._ +_Which different types are supported, which models were tested etc.?_ +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Discovery + +_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._ + +## Binding Configuration + +_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_ + +``` +# Configuration for the Philips Hue Binding +# +# Default secret key for the pairing of the Philips Hue Bridge. +# It has to be between 10-40 (alphanumeric) characters +# This may be changed by the user for security reasons. +secret=EclipseSmartHome +``` + +_Note that it is planned to generate some part of this based on the information that is available within ```ESH-INF/binding``` of your binding._ + +_If your binding does not offer any generic configurations, you can remove this section completely._ + +## Thing Configuration + +_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Channels + +_Here you should provide information about available channel types, what their meaning is and how they can be used._ + +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Full Example + +_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._ + +## Any custom content here! + +_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_ diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/build.properties new file mode 100644 index 00000000000..a6cfff567c9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/build.properties @@ -0,0 +1,7 @@ +source..=src/main/java/ +output..=target/classes +bin.includes=META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + NOTICE diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/pom.xml new file mode 100644 index 00000000000..f0d93d84f16 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth.yeelightblue + + Eclipse SmartHome YeelightBlue Binding + eclipse-plugin + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/YeelightBlueBindingConstants.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/YeelightBlueBindingConstants.java new file mode 100644 index 00000000000..46ab17a7d20 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/YeelightBlueBindingConstants.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.yeelightblue; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.core.thing.ThingTypeUID; + +/** + * The {@link YeelightBlueBindingConstants.YeeLightBlueBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Chris Jackson - Initial contribution + */ +public class YeelightBlueBindingConstants { + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_BLUE2 = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, + "yeelight_blue2"); + + // List of all Channel ids + public final static String CHANNEL_SWITCH = "switch"; + public final static String CHANNEL_BRIGHTNESS = "brightness"; + public final static String CHANNEL_COLOR = "color"; + public final static String CHANNEL_RSSI = "rssi"; + + public final static String YEELIGHT_NAME = "Yeelight Blue II"; +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/handler/YeelightBlueHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/handler/YeelightBlueHandler.java new file mode 100644 index 00000000000..e4a2cfd120d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/handler/YeelightBlueHandler.java @@ -0,0 +1,167 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.yeelightblue.handler; + +import java.util.UUID; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCompletionStatus; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDeviceListener; +import org.eclipse.smarthome.binding.bluetooth.ConnectedBluetoothHandler; +import org.eclipse.smarthome.binding.bluetooth.yeelightblue.YeelightBlueBindingConstants; +import org.eclipse.smarthome.core.library.types.HSBType; +import org.eclipse.smarthome.core.library.types.OnOffType; +import org.eclipse.smarthome.core.library.types.PercentType; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.types.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link YeelightBlueHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Refactored to extend {@link ConnectedBluetoothHandler}. + */ +public class YeelightBlueHandler extends ConnectedBluetoothHandler implements BluetoothDeviceListener { + + private final Logger logger = LoggerFactory.getLogger(YeelightBlueHandler.class); + + private final UUID UUID_YEELIGHT_CONTROL = UUID.fromString("0000fff1-0000-0000-0000-000000000000"); + private final UUID UUID_YEELIGHT_STATUS_REQUEST = UUID.fromString("0000fff5-0000-0000-0000-000000000000"); + private final UUID UUID_YEELIGHT_STATUS_RESPONSE = UUID.fromString("0000fff6-0000-0000-0000-000000000000"); + + // The characteristics we regularly use + private BluetoothCharacteristic characteristicControl = null; + private BluetoothCharacteristic characteristicRequest = null; + + public YeelightBlueHandler(Thing thing) { + super(thing); + } + + @Override + public void initialize() { + super.initialize(); + device.connect(); + device.discoverServices(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + String value = null; + + if (command instanceof HSBType) { + HSBType hsb = (HSBType) command; + double r = hsb.getRed().doubleValue() * 2.55; + double g = hsb.getGreen().doubleValue() * 2.55; + double b = hsb.getBlue().doubleValue() * 2.55; + double a = hsb.getSaturation().doubleValue(); + value = String.format("%.0f,%.0f,%.0f,%.0f", r, g, b, a); + } + + else if (command instanceof PercentType) { + value = ",,," + ((PercentType) command).intValue() + ""; + } + + else if (command instanceof OnOffType) { + value = ",,," + ((OnOffType) command == OnOffType.ON ? 100 : 0) + ""; + } + + if (value == null) { + logger.debug("Unable to convert value!"); + return; + } + + if (characteristicControl == null) { + logger.debug("YeeLightBlue: Unable to find control characteristic!"); + return; + } + + // Terminate the value string with commas - up to 18 characters long + for (int cnt = value.length(); cnt < 18; cnt++) { + value += ","; + } + logger.debug("YeelightBlue conversion: {} to \"{}\"", command, value); + + characteristicControl.setValue(value); + device.writeCharacteristic(characteristicControl); + } + + @Override + public void onServicesDiscovered() { + // Everything is initialised now - get the characteristics we want to use + characteristicControl = device.getCharacteristic(UUID_YEELIGHT_CONTROL); + if (characteristicControl == null) { + logger.debug("YeeLightBlue control characteristic not known after service discovery!"); + } + characteristicRequest = device.getCharacteristic(UUID_YEELIGHT_STATUS_REQUEST); + if (characteristicRequest == null) { + logger.debug("YeeLightBlue status characteristic not known after service discovery!"); + } + + // Read the current value so we can update the UI + readStatus(); + } + + @Override + public void onCharacteristicWriteComplete(BluetoothCharacteristic characteristic, + BluetoothCompletionStatus status) { + // If this was a write to the control, then read back the state + if (characteristic.getUuid().equals(UUID_YEELIGHT_CONTROL)) { + readStatus(); + } + } + + @Override + public void onCharacteristicUpdate(BluetoothCharacteristic characteristic) { + if (characteristic.getUuid().equals(UUID_YEELIGHT_STATUS_RESPONSE)) { + String value = characteristic.getStringValue(0); + logger.debug("Yeelight status update is \"{}\"", value); + + String[] elements = value.split(","); + + int red, green, blue; + try { + red = Integer.parseInt(elements[0]); + } catch (NumberFormatException e) { + red = 0; + } + try { + green = Integer.parseInt(elements[1]); + } catch (NumberFormatException e) { + green = 0; + } + try { + blue = Integer.parseInt(elements[2]); + } catch (NumberFormatException e) { + blue = 0; + } + + HSBType hsbState = HSBType.fromRGB(red, green, blue); + + updateState(new ChannelUID(getThing().getUID(), YeelightBlueBindingConstants.CHANNEL_COLOR), hsbState); + } + } + + private void readStatus() { + if (characteristicRequest == null) { + logger.debug("YeeLightBlue status characteristic not known"); + return; + } + + characteristicRequest.setValue("S"); + device.writeCharacteristic(characteristicRequest); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightBlueHandlerFactory.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightBlueHandlerFactory.java new file mode 100644 index 00000000000..9f331a49993 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightBlueHandlerFactory.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.yeelightblue.internal; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.yeelightblue.YeelightBlueBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.yeelightblue.handler.YeelightBlueHandler; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * The {@link YeelightBlueHandlerFactory.YeeLightBlueHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Chris Jackson - Initial contribution + */ +@Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.yeelight", configurationPolicy = ConfigurationPolicy.OPTIONAL) +public class YeelightBlueHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Collections + .singleton(YeelightBlueBindingConstants.THING_TYPE_BLUE2); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(YeelightBlueBindingConstants.THING_TYPE_BLUE2)) { + return new YeelightBlueHandler(thing); + } + + return null; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightDiscoveryParticipant.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightDiscoveryParticipant.java new file mode 100644 index 00000000000..50cf1461dda --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth.yeelightblue/src/main/java/org/eclipse/smarthome/binding/bluetooth/yeelightblue/internal/YeelightDiscoveryParticipant.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2014,2017 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.yeelightblue.internal; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.discovery.BluetoothDiscoveryParticipant; +import org.eclipse.smarthome.binding.bluetooth.yeelightblue.YeelightBlueBindingConstants; +import org.eclipse.smarthome.config.discovery.DiscoveryResult; +import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.osgi.service.component.annotations.Component; + +/** + * This discovery participant is able to recognize Yeelight devices and create discovery results for them. + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +@Component(immediate = true) +public class YeelightDiscoveryParticipant implements BluetoothDiscoveryParticipant { + + @Override + public @NonNull Set<@NonNull ThingTypeUID> getSupportedThingTypeUIDs() { + return Collections.singleton(YeelightBlueBindingConstants.THING_TYPE_BLUE2); + } + + @Override + public @Nullable ThingUID getThingUID(@NonNull BluetoothDevice device) { + if (YeelightBlueBindingConstants.YEELIGHT_NAME.equals(device.getName())) { + return new ThingUID(YeelightBlueBindingConstants.THING_TYPE_BLUE2, device.getAdapter().getUID(), + device.getAddress().toString().toLowerCase().replace(":", "")); + } else { + return null; + } + } + + @Override + public DiscoveryResult createResult(@NonNull BluetoothDevice device) { + ThingUID thingUID = getThingUID(device); + + if (thingUID != null) { + String label = device.getName(); + + Map properties = new HashMap<>(); + properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString()); + properties.put(Thing.PROPERTY_VENDOR, "Yeelight"); + Integer txPower = device.getTxPower(); + if (txPower != null) { + properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower)); + } + + // Create the discovery result and add to the inbox + return DiscoveryResultBuilder.create(thingUID).withProperties(properties) + .withBridge(device.getAdapter().getUID()).withLabel(label).build(); + } else { + return null; + } + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.classpath b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.classpath new file mode 100644 index 00000000000..7f457fa4138 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.project b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.project new file mode 100644 index 00000000000..3684cd6a366 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.binding.bluetooth + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ARCHITECTURE.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ARCHITECTURE.md new file mode 100644 index 00000000000..bceb488708d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ARCHITECTURE.md @@ -0,0 +1,68 @@ +# Bluetooth Binding overview + +The Bluetooth binding is implemented to allow bundles to extend the main Bluetooth bundle (this one) in order to add new Bluetooth adapter as well as device support. +This architecture means that such extension bundles must utilise the binding name `bluetooth`. + +A base class structure is defined in the `org.eclipse.smarthome.binding.bluetooth` bundle. +This includes the main classes required to implement Bluetooth: + +* `BluetoothAdapter`. This interface defines the main functionality required to be implemented by a Bluetooth adapter, including device discovery. Typically, this interface is implemented by a BridgeHandler and then registered as an OSGi service +* `BluetoothDiscoveryParticipant`. An interface to be implemented by services that can identify specific Bluetooth devices. +* `BluetoothDevice`. This implements a Bluetooth device. It manages the notifications of device notifications, Bluetooth service and characteristic management, and provides the main interface to communicate to a Bluetooth device. +* `BluetoothService`. Implements the Bluetooth service. A service holds a number of characteristics. +* `BluetoothCharacteristic`. Implements the Bluetooth characteristic. This is the basic component for communicating data to and from a Bluetooth device. +* `BluetoothDescriptor`. Implements the Bluetooth descriptors for each characteristic. + +## Implementing a new Bluetooth Adapter bundle + +Bluetooth adapters are modelled as a bridge in ESH. +The bridge handler provides the link with the Bluetooth hardware (eg a dongle, or system Bluetooth API). +An adapter bundle needs to implement two main classes: the `BridgeHandler` which should implement `BluetoothAdapter` (any be registered as a service), and a `ThingFactory`, which is required to instantiate the handler. + +The bridge handler must implement any functionality required to interface to the Bluetooth layer. +It is responsible for managing the Bluetooth scanning, device discovery (i.e. the device interrogation to get the list of services and characteristics) and reading and writing of characteristics. +The bridge needs to manage any interaction between the interface with any things it provides – this needs to account for any constraints that a interface may impose such that things do not need to worry about any peculiarities imposed by a specific interface. + +Classes such as `BluetoothCharacteristic` or `BluetoothService` may be extended to provide additional functionality to interface to a specific library if needed. + +## Implementing specific Bluetooth device support + +A specific Bluetooth thing handler provides the functionality required to interact with a specific Bluetooth device. +The new thing bundle needs to implement three main classes – a `BluetoothDiscoveryParticipant`, a `ThingHandler` and a `ThingFactory`, which is required to instantiate the handler. + +Two fundamental communications methods can be employed in Bluetooth: beacons and connected mode. A Bluetooth thing handler can implement one or both of these communications + In practice, a connected mode Thing implementation would normally handle the beacons in order to provide as a minimum the RSSI data. + +### Thing Naming + +To avoid naming conflicts with different Bluetooth bundles a strict naming policy for things and thing xml files is proposed. +This should use the bundle name and the thing name, separated with an underscore - e.g. for a Yeelight binding Blue2 thing, the thing type would be `yeelight_blue2`. + +### Connected Mode Implementation + +The connected mode `BluetoothThingHandler` needs to handle the following functionality +* Extend the connected bluetooth thing handler. This holds the `adapter` through which all communication is done. +* Call the `adapter.getDevice()` method to get the `BluetoothDevice` class for the requested device. The `getDevice()` method will return a `BluetoothDevice` class even if the device is not currently known. +* Implement the `BluetoothDeviceListener` methods. These provide callbacks for various notifications regarding device updates – e.g. when the connection state of a device changes, when the device discovery is complete, when a read and write completes, and when beacon messages are received. +* The parent class calls the `device.connect()` method to connect to the device. Once the device is connected, the `BluetoothDeviceListener.onConnectionStateChange()` callback will be called. +* The parent class calls the `device.discoverServices()` method to discover all the BluetoothServices and `BluetoothCharacteristic`s implemented by the device. Once this is complete, the `BluetoothDeviceListener.onServicesDiscovered()` callback will be called. +* Call the `readCharacteristic` or `writeCharacteristic` methods to interact with the device. The `BluetoothDeviceListener.onCharacteristicReadComplete()` and `BluetoothDeviceListener.onCharacteristicWriteComplete()` methods will be called on completion. +* Implement the `BluetoothDeviceListener.onCharacteristicUpdate()` method to process any read responses or unsolicited updates of a characteristic value. + +### Beacon Mode Implementation + +The beacon mode thing handler needs to handle the following functionality: + +* Extend the beacon Bluetooth thing handler. This holds the `adapter` through which all communication is done. +* Call the `adapter.getDevice()` method to get the `BluetoothDevice` class for the requested device. The `getDevice()` method will return a `BluetoothDevice` class even if the device is not currently known. +* Implement the `BluetoothDeviceListener.onScanRecordReceived()` method to process the beacons. The notification will provide the current receive signal strength (RSSI), the raw beacon data, and various elements of generally useful beacon data is provided separately. + +### Generic Bluetooth Device Support + +The core Bluetooth binding already includes generic "beacon" and "connected" Bluetooth thing types. +All devices for which no discovery participant defines a specific thing type are added to the inbox as a beacon device. +The corresponding handler implementation (`BeaconBluetoothHandler`) uses Beacon mode and merely defines a channel for RSSI for such devices. + +The "connected" thing type can be used by manually defining a thing. +The corresponding handler implementation (`ConnectedBluetoothHandler`) uses Connected mode and thus immediately connects to the device and reads its services. +Common services are added as channels (t.b.d.). diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/binding/binding.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/binding/binding.xml new file mode 100644 index 00000000000..89bd040b06a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/binding/binding.xml @@ -0,0 +1,8 @@ + + + + Bluetooth Binding + This binding supports the Bluetooth protocol. + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/channels.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/channels.xml new file mode 100644 index 00000000000..a7824ffbb07 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/channels.xml @@ -0,0 +1,14 @@ + + + + + Number + + Received signal strength indicator + QualityOfService + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/thing-types.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/thing-types.xml new file mode 100644 index 00000000000..f2c5f3e31e4 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/ESH-INF/thing/thing-types.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + A generic Bluetooth device in beacon-mode + + + + + + + + The unique Bluetooth address of the device + + + + + + + + + + + + A generic Bluetooth device in connected-mode + + + + + + + + The unique Bluetooth address of the device + + + + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/META-INF/MANIFEST.MF b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..df568a56b1a --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Bluetooth Binding +Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth;singleton:=true +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.10.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: . +Import-Package: + org.eclipse.jdt.annotation;resolution:=optional, + org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.config.discovery, + org.eclipse.smarthome.core.common.registry, + org.eclipse.smarthome.core.library.types, + org.eclipse.smarthome.core.thing, + org.eclipse.smarthome.core.thing.binding, + org.eclipse.smarthome.core.thing.binding.builder, + org.eclipse.smarthome.core.thing.type, + org.eclipse.smarthome.core.types, + org.slf4j +Service-Component: OSGI-INF/*.xml +Export-Package: org.eclipse.smarthome.binding.bluetooth, + org.eclipse.smarthome.binding.bluetooth.discovery, + org.eclipse.smarthome.binding.bluetooth.notification +Bundle-ActivationPolicy: lazy diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/NOTICE b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/NOTICE new file mode 100644 index 00000000000..b8675cd02e8 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/NOTICE @@ -0,0 +1,19 @@ +This content is produced and maintained by the Eclipse SmartHome project. + +* Project home: https://eclipse.org/smarthome/ + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/eclipse/smarthome + +== Copyright Holders + +See the NOTICE file distributed with the source code at +https://github.com/eclipse/smarthome/blob/master/NOTICE +for detailed information regarding copyright ownership. diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/OSGI-INF/.gitignore b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/OSGI-INF/.gitignore new file mode 100644 index 00000000000..b878e882aca --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/README.md b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/README.md new file mode 100644 index 00000000000..9f882d66982 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/README.md @@ -0,0 +1,72 @@ +# Bluetooth Binding + +This binding provides support for generic Bluetooth devices. + +## Bridges + +In order to function, this binding requires a Bluetoooth adapter to be present, which handles the wireless communication. +As there is no standard in Bluetooth for such dongles resp. chips, different adapters require a different implementation. +This is why the Bluetooth binding itself does not come with any bridge handlers for such adapters itself, but instead is extensible by additional bundles which can implement support for a specific adapter. + +For Linux, there exists a special bundle which provides a Bluetooth bridge that talks to BlueZ. +This should be the best choice for any Linux-based single board computers like e.g. the Raspberry Pi. + +## Supported Things + +Two thing types are supported by this binding: + +| Thing Type ID | Description | +|---------------|---------------------------------------------------------------------------------------------------------| +| beacon | A Bluetooth device that is not connected, but only broadcasts annoucements. | +| connected | A Bluetooth device that allows a direct connection and which provides specific services when connected. | + + +## Discovery + +Discovery is performed through the Bluetooth bridge. +Normally, any broadcasting Bluetooth device can be uniquely identified and thus a bridge can create an inbox result for it. +As this might lead to a huge list of devices, bridges usually also offer a way to deactivate this behavior. + +## Thing Configuration + +Both thing types only require a single configuration parameter `address`, which corresponds to the Bluetooth address of the device (in format "XX:XX:XX:XX:XX:XX"). + +## Channels + +Every Bluetooth thing has the following channel: + +| Channel ID | Item Type | Description | +|------------|-----------|-----------------------------------------------------------------------------------------------------| +| rssi | Number | The "Received Signal Strength Indicator", the [RSSI](https://blog.bluetooth.com/proximity-and-rssi) | + +`connected` Things are dynamically queried for their services and if they support certain standard GATT characteristics, the appropriate channels are automatically added as well: + +| Channel ID | Item Type | Description | +|---------------|-----------|-----------------------------------------------------------------| +| battery_level | Number | The device's battery level in percent | + + +## Full Example + +demo.things (assuming you have a Bluetooth bridge with the ID `bluetooth:bluez:hci0`): + +``` +bluetooth:beacon:hci0:b1 "BLE Beacon" (bluetooth:bluez:hci0) [ address="68:64:4C:14:FC:C4" ] +``` + +demo.items: + +``` +Number Beacon_RSSI "My Beacon [%.0f]" { channel="bluetooth:beacon:hci0:b1:rssi" } +``` + +demo.sitemap: + +``` +sitemap demo label="Main Menu" +{ + Frame { + Text item=Beacon_RSSI + } +} +``` diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/build.properties b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/build.properties new file mode 100644 index 00000000000..a6cfff567c9 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/build.properties @@ -0,0 +1,7 @@ +source..=src/main/java/ +output..=target/classes +bin.includes=META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/,\ + NOTICE diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/pom.xml b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/pom.xml new file mode 100644 index 00000000000..80a89b8112f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/pom.xml @@ -0,0 +1,18 @@ + + + + 4.0.0 + + + org.eclipse.smarthome.binding + pom + 0.10.0-SNAPSHOT + + + org.eclipse.smarthome.binding.bluetooth + + Eclipse SmartHome Bluetooth Binding + eclipse-plugin + + diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BeaconBluetoothHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BeaconBluetoothHandler.java new file mode 100644 index 00000000000..484fac43d28 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BeaconBluetoothHandler.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification; +import org.eclipse.smarthome.core.library.types.DecimalType; +import org.eclipse.smarthome.core.thing.Bridge; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.ThingStatusDetail; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; +import org.eclipse.smarthome.core.thing.binding.BridgeHandler; +import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.RefreshType; +import org.eclipse.smarthome.core.types.UnDefType; + +/** + * This is a handler for generic Bluetooth devices in beacon-mode (i.e. not connected), which at the same time can be + * used as a base implementation for more specific thing handlers. + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +public class BeaconBluetoothHandler extends BaseThingHandler implements BluetoothDeviceListener { + + protected BluetoothAdapter adapter; + protected BluetoothAddress address; + protected BluetoothDevice device; + + public BeaconBluetoothHandler(@NonNull Thing thing) { + super(thing); + } + + @Override + public void initialize() { + try { + address = new BluetoothAddress(getConfig().get(BluetoothBindingConstants.CONFIGURATION_ADDRESS).toString()); + } catch (IllegalArgumentException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getLocalizedMessage()); + return; + } + + Bridge bridge = getBridge(); + if (bridge == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Not associated with any bridge"); + return; + } + + BridgeHandler bridgeHandler = bridge.getHandler(); + if (!(bridgeHandler instanceof BluetoothAdapter)) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Associated with an unsupported bridge"); + return; + } + + adapter = (BluetoothAdapter) bridgeHandler; + device = adapter.getDevice(address); + device.addListener(this); + + updateStatus(ThingStatus.UNKNOWN); + } + + @Override + public void dispose() { + if (device != null) { + device.removeListener(this); + device = null; + } + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (command == RefreshType.REFRESH && channelUID.getId().equals(BluetoothBindingConstants.CHANNEL_TYPE_RSSI)) { + updateRSSI(); + } + } + + /** + * Updates the RSSI channel and the Thing status according to the new received rssi value + */ + protected void updateRSSI() { + if (device != null) { + Integer rssi = device.getRssi(); + if (rssi != null && rssi != 0) { + updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, new DecimalType(rssi)); + updateStatusBasedOnRssi(true); + } else { + updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, UnDefType.NULL); + updateStatusBasedOnRssi(false); + } + } + } + + /** + * This method sets the Thing status based on whether or not we can receive a signal from it. + * This is the best logic for beacons, but connected devices might want to deactivate this by overriding the method. + * + * @param receivedSignal true, if the device is in reach + */ + protected void updateStatusBasedOnRssi(boolean receivedSignal) { + if (receivedSignal) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); + } + } + + @Override + public void onScanRecordReceived(BluetoothScanNotification scanNotification) { + int rssi = scanNotification.getRssi(); + device.setRssi(rssi); + updateRSSI(); + } + + @Override + public void onConnectionStateChange(@NonNull BluetoothConnectionStatusNotification connectionNotification) { + } + + @Override + public void onServicesDiscovered() { + } + + @Override + public void onCharacteristicReadComplete(@NonNull BluetoothCharacteristic characteristic, + @NonNull BluetoothCompletionStatus status) { + } + + @Override + public void onCharacteristicWriteComplete(@NonNull BluetoothCharacteristic characteristic, + @NonNull BluetoothCompletionStatus status) { + } + + @Override + public void onCharacteristicUpdate(@NonNull BluetoothCharacteristic characteristic) { + } + + @Override + public void onDescriptorUpdate(@NonNull BluetoothDescriptor bluetoothDescriptor) { + } + +} \ No newline at end of file diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAdapter.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAdapter.java new file mode 100644 index 00000000000..3446ec5d1b0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAdapter.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.common.registry.Identifiable; +import org.eclipse.smarthome.core.thing.ThingUID; + +/** + * The {@link BluetoothAdapter} class defines the standard adapter API that must be implemented by bridge handlers, + * which are then required to be registered as an BluetoothAdapter OSGi service. + *

+ * Scanning + * The API assumes that the adapter is "always" scanning to enable beacons to be received. + * The bridge must decide to enable and disable scanning as it needs. This design choice avoids interaction between + * higher layers where a binding may want to enable scanning while another needs to disable scanning for a specific + * function (e.g. to connect to a device). The bridge should disable scanning only for the period that is needed. + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - renamed it, made it identifiable and added listener support + */ +@NonNullByDefault +public interface BluetoothAdapter extends Identifiable { + + /** + * Adds a {@link BluetoothDiscoveryListener} to the adapter + * + * @param listener the listener to add + */ + void addDiscoveryListener(BluetoothDiscoveryListener listener); + + /** + * Removes a {@link BluetoothDiscoveryListener} from the adapter + * + * @param listener the listener to remove + */ + void removeDiscoveryListener(@Nullable BluetoothDiscoveryListener listener); + + /** + * Starts an active scan on the Bluetooth interface. + */ + void scanStart(); + + /** + * Stops an active scan on the Bluetooth interface + */ + void scanStop(); + + /** + * Gets the {@link BluetoothAddress} of the adapter + * + * @return the {@link BluetoothAddress} of the adapter + * @throws IllegalStateException if the adapter is not initialized + */ + BluetoothAddress getAddress(); + + /** + * Gets the {@link BluetoothDevice} given the {@link BluetoothAddress}. + * A {@link BluetoothDevice} will always be returned for a valid hardware address, even if this adapter has never + * seen that device. + * + * @param address the {@link BluetoothAddress} to retrieve + * @return the {@link BluetoothDevice} + * @throws IllegalArgumentException if the address is no valid hardware address + */ + BluetoothDevice getDevice(BluetoothAddress address); + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddress.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddress.java new file mode 100644 index 00000000000..0bdb22f9704 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothAddress.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +/** + * The {@link BluetoothAddress} class defines a bluetooth address + * + * @author Chris Jackson - Initial contribution + */ +public class BluetoothAddress { + + public static final int BD_ADDRESS_LENGTH = 17; + + private final String address; + + /** + * The default constructor + * + * @param address the device address + */ + public BluetoothAddress(String address) { + if (address == null || address.length() != BD_ADDRESS_LENGTH) { + throw new IllegalArgumentException("BT Address cannot be null and must be in format XX:XX:XX:XX:XX:XX"); + } + for (int i = 0; i < BD_ADDRESS_LENGTH; i++) { + char c = address.charAt(i); + + // Check address - 2 bytes should be hex, and then a colon + switch (i % 3) { + case 0: // fall through + case 1: + if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) { + break; + } + throw new IllegalArgumentException("BT Address must contain upper case hex values only"); + case 2: + if (c == ':') { + break; + } + throw new IllegalArgumentException("BT Address bytes must be separated with colon"); + } + } + + this.address = address; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((address == null) ? 0 : address.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + BluetoothAddress other = (BluetoothAddress) obj; + if (address == null) { + if (other.address != null) { + return false; + } + } else if (!address.equals(other.address)) { + return false; + } + return true; + } + + @Override + public String toString() { + return address; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothBindingConstants.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothBindingConstants.java new file mode 100644 index 00000000000..d31dbc63720 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothBindingConstants.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.UUID; + +import org.eclipse.smarthome.core.thing.ThingTypeUID; + +/** + * The {@link BluetoothBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - refactoring and extension + */ +public class BluetoothBindingConstants { + + public static final String BINDING_ID = "bluetooth"; + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_CONNECTED = new ThingTypeUID(BINDING_ID, "connected"); + public static final ThingTypeUID THING_TYPE_BEACON = new ThingTypeUID(BINDING_ID, "beacon"); + + // List of all Channel Type IDs + public static final String CHANNEL_TYPE_RSSI = "rssi"; + + public static final String PROPERTY_TXPOWER = "txpower"; + public static final String PROPERTY_MAXCONNECTIONS = "maxconnections"; + + public static final String CONFIGURATION_ADDRESS = "address"; + + public static final long BLUETOOTH_BASE_UUID = 0x800000805f9b34fbL; + + // Bluetooth profile UUID definitions + public final static UUID PROFILE_GATT = UUID.fromString("00001801-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_A2DP_SOURCE = UUID.fromString("0000110a-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_A2DP_SINK = UUID.fromString("0000110b-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_A2DP = UUID.fromString("0000110d-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_AVRCP_REMOTE = UUID.fromString("0000110c-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_CORDLESS_TELEPHONE = UUID.fromString("00001109-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_DID_PNPINFO = UUID.fromString("00001200-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_HEADSET = UUID.fromString("00001108-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_HFP = UUID.fromString("0000111e-0000-1000-8000-00805f9b34fb"); + public final static UUID PROFILE_HFP_AUDIOGATEWAY = UUID.fromString("0000111f-0000-1000-8000-00805f9b34fb"); + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCharacteristic.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCharacteristic.java new file mode 100644 index 00000000000..c7888b02807 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCharacteristic.java @@ -0,0 +1,658 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link BluetoothCharacteristic} class defines the Bluetooth characteristic. + *

+ * Characteristics are defined attribute types that contain a single logical value. + *

+ * https://www.bluetooth.com/specifications/gatt/characteristics + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Cleaned up code + */ +public class BluetoothCharacteristic { + public static final int FORMAT_UINT8 = 0x11; + public static final int FORMAT_UINT16 = 0x12; + public static final int FORMAT_UINT32 = 0x14; + public static final int FORMAT_SINT8 = 0x21; + public static final int FORMAT_SINT16 = 0x22; + public static final int FORMAT_SINT32 = 0x24; + public static final int FORMAT_SFLOAT = 0x32; + public static final int FORMAT_FLOAT = 0x34; + + public static final int PROPERTY_BROADCAST = 0x01; + public static final int PROPERTY_READ = 0x02; + public static final int PROPERTY_WRITE_NO_RESPONSE = 0x04; + public static final int PROPERTY_WRITE = 0x08; + public static final int PROPERTY_NOTIFY = 0x10; + public static final int PROPERTY_INDICATE = 0x20; + public static final int PROPERTY_SIGNED_WRITE = 0x40; + public static final int PROPERTY_EXTENDED_PROPS = 0x80; + + public static final int PERMISSION_READ = 0x01; + public static final int PERMISSION_READ_ENCRYPTED = 0x02; + public static final int PERMISSION_READ_ENCRYPTED_MITM = 0x04; + public static final int PERMISSION_WRITE = 0x10; + public static final int PERMISSION_WRITE_ENCRYPTED = 0x20; + public static final int PERMISSION_WRITE_ENCRYPTED_MITM = 0x40; + public static final int PERMISSION_WRITE_SIGNED = 0x80; + public static final int PERMISSION_WRITE_SIGNED_MITM = 0x100; + + public static final int WRITE_TYPE_DEFAULT = 0x02; + public static final int WRITE_TYPE_NO_RESPONSE = 0x01; + public static final int WRITE_TYPE_SIGNED = 0x04; + + private final Logger logger = LoggerFactory.getLogger(BluetoothCharacteristic.class); + + /** + * The {@link UUID} for this characteristic + */ + protected UUID uuid; + + /** + * The handle for this characteristic + */ + protected int handle; + + /** + * A map of {@link BluetoothDescriptor}s applicable to this characteristic + */ + protected Map gattDescriptors = new HashMap(); + protected int instance; + protected int properties; + protected int permissions; + protected int writeType; + + /** + * The raw data value for this characteristic + */ + protected int[] value = new int[0]; + + /** + * The {@link BluetoothService} to which this characteristic belongs + */ + protected BluetoothService service; + + /** + * Create a new BluetoothCharacteristic. + * + * @param uuid the {@link UUID} of the new characteristic + * @param handle + */ + public BluetoothCharacteristic(UUID uuid, int handle) { + this.uuid = uuid; + this.handle = handle; + } + + /** + * Adds a descriptor to this characteristic. + * + * @param descriptor {@link BluetoothDescriptor} to be added to this characteristic. + * @return true, if the descriptor was added to the characteristic + */ + public boolean addDescriptor(BluetoothDescriptor descriptor) { + if (gattDescriptors.get(descriptor.getUuid()) != null) { + return false; + } + + gattDescriptors.put(descriptor.getUuid(), descriptor); + return true; + } + + /** + * Returns the {@link UUID} of this characteristic + * + * @return UUID of this characteristic + */ + public UUID getUuid() { + return uuid; + } + + /** + * Returns the instance ID for this characteristic. + * + * If a remote device offers multiple characteristics with the same UUID, the instance ID is used to distinguish + * between characteristics. + * + * @return Instance ID of this characteristic + */ + public int getInstanceId() { + return instance; + } + + /** + * Returns the properties of this characteristic. + * + * The properties contain a bit mask of property flags indicating the features of this characteristic. + * + */ + public int getProperties() { + return properties; + } + + /** + * Returns the permissions for this characteristic. + */ + public int getPermissions() { + return permissions; + } + + /** + * Gets the write type for this characteristic. + * + */ + public int getWriteType() { + return writeType; + } + + /** + * Set the write type for this characteristic + * + * @param writeType + */ + public void setWriteType(int writeType) { + this.writeType = writeType; + } + + /** + * Get the service to which this characteristic belongs + * + * @return the {@link BluetoothService} + */ + public BluetoothService getService() { + return service; + } + + /** + * Returns the handle for this characteristic + * + * @return the handle for the characteristic + */ + public int getHandle() { + return handle; + } + + /** + * Get the service to which this characteristic belongs + * + * @return the {@link BluetoothService} + */ + public void setService(BluetoothService service) { + this.service = service; + } + + /** + * Returns a list of descriptors for this characteristic. + * + */ + public List getDescriptors() { + return new ArrayList(gattDescriptors.values()); + } + + /** + * Returns a descriptor with a given UUID out of the list of + * descriptors for this characteristic. + * + * @return the {@link BluetoothDescriptor} + */ + public BluetoothDescriptor getDescriptor(UUID uuid) { + return gattDescriptors.get(uuid); + } + + /** + * Get the stored value for this characteristic. + * + */ + public int[] getValue() { + return value; + } + + /** + * Get the stored value for this characteristic. + * + */ + public byte[] getByteValue() { + byte[] byteValue = new byte[value.length]; + for (int cnt = 0; cnt < value.length; cnt++) { + byteValue[cnt] = (byte) (value[cnt] & 0xFF); + } + return byteValue; + } + + /** + * Return the stored value of this characteristic. + * + */ + public Integer getIntValue(int formatType, int offset) { + if ((offset + getTypeLen(formatType)) > value.length) { + return null; + } + + switch (formatType) { + case FORMAT_UINT8: + return unsignedByteToInt(value[offset]); + + case FORMAT_UINT16: + return unsignedBytesToInt(value[offset], value[offset + 1]); + + case FORMAT_UINT32: + return unsignedBytesToInt(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]); + + case FORMAT_SINT8: + return unsignedToSigned(unsignedByteToInt(value[offset]), 8); + + case FORMAT_SINT16: + return unsignedToSigned(unsignedBytesToInt(value[offset], value[offset + 1]), 16); + + case FORMAT_SINT32: + return unsignedToSigned( + unsignedBytesToInt(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]), 32); + default: + logger.error("Unknown format type {} - no int value can be provided for it.", formatType); + } + + return null; + } + + /** + * Return the stored value of this characteristic. This doesn't read the remote data. + * + */ + public Float getFloatValue(int formatType, int offset) { + if ((offset + getTypeLen(formatType)) > value.length) { + return null; + } + + switch (formatType) { + case FORMAT_SFLOAT: + return bytesToFloat(value[offset], value[offset + 1]); + case FORMAT_FLOAT: + return bytesToFloat(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]); + default: + logger.error("Unknown format type {} - no float value can be provided for it.", formatType); + } + + return null; + } + + /** + * Return the stored value of this characteristic. This doesn't read the remote data. + * + */ + public String getStringValue(int offset) { + if (value == null || offset > value.length) { + return null; + } + byte[] strBytes = new byte[value.length - offset]; + for (int i = 0; i < (value.length - offset); ++i) { + strBytes[i] = (byte) value[offset + i]; + } + return new String(strBytes, StandardCharsets.UTF_8); + } + + /** + * Updates the locally stored value of this characteristic. + * + * @param value the value to set + * @return true, if it has been set successfully + */ + public boolean setValue(int[] value) { + this.value = value; + return true; + } + + /** + * Set the local value of this characteristic. + * + * @param value the value to set + * @param formatType the format of the value (as one of the FORMAT_* constants in this class) + * @param offset the offset to use when interpreting the value + * @return true, if it has been set successfully + */ + public boolean setValue(int value, int formatType, int offset) { + int len = offset + getTypeLen(formatType); + if (this.value == null) { + this.value = new int[len]; + } + if (len > this.value.length) { + return false; + } + int val = value; + switch (formatType) { + case FORMAT_SINT8: + val = intToSignedBits(value, 8); + // Fall-through intended + case FORMAT_UINT8: + this.value[offset] = (byte) (val & 0xFF); + break; + + case FORMAT_SINT16: + val = intToSignedBits(value, 16); + // Fall-through intended + case FORMAT_UINT16: + this.value[offset] = (byte) (val & 0xFF); + this.value[offset + 1] = (byte) ((val >> 8) & 0xFF); + break; + + case FORMAT_SINT32: + val = intToSignedBits(value, 32); + // Fall-through intended + case FORMAT_UINT32: + this.value[offset] = (byte) (val & 0xFF); + this.value[offset + 1] = (byte) ((val >> 8) & 0xFF); + this.value[offset + 2] = (byte) ((val >> 16) & 0xFF); + this.value[offset + 2] = (byte) ((val >> 24) & 0xFF); + break; + + default: + return false; + } + return true; + } + + /** + * Set the local value of this characteristic. + * + * @param mantissa the mantissa of the value + * @param exponent the exponent of the value + * @param formatType the format of the value (as one of the FORMAT_* constants in this class) + * @param offset the offset to use when interpreting the value + * @return true, if it has been set successfully + * + */ + public boolean setValue(int mantissa, int exponent, int formatType, int offset) { + int len = offset + getTypeLen(formatType); + if (value == null) { + value = new int[len]; + } + if (len > value.length) { + return false; + } + + switch (formatType) { + case FORMAT_SFLOAT: + int m = intToSignedBits(mantissa, 12); + int exp = intToSignedBits(exponent, 4); + value[offset] = (byte) (m & 0xFF); + value[offset + 1] = (byte) ((m >> 8) & 0x0F); + value[offset + 1] += (byte) ((exp & 0x0F) << 4); + break; + + case FORMAT_FLOAT: + m = intToSignedBits(mantissa, 24); + exp = intToSignedBits(exponent, 8); + value[offset] = (byte) (m & 0xFF); + value[offset + 1] = (byte) ((m >> 8) & 0xFF); + value[offset + 2] = (byte) ((m >> 16) & 0xFF); + value[offset + 2] += (byte) (exp & 0xFF); + break; + + default: + return false; + } + + return true; + } + + /** + * Set the local value of this characteristic. + * + * @param value the value to set + * @return true, if it has been set successfully + */ + public boolean setValue(byte[] value) { + this.value = new int[value.length]; + int cnt = 0; + for (byte val : value) { + this.value[cnt++] = val; + } + return true; + } + + /** + * Set the local value of this characteristic. + * + * @param value the value to set + * @return true, if it has been set successfully + */ + public boolean setValue(String value) { + this.value = new int[value.getBytes().length]; + int cnt = 0; + for (byte val : value.getBytes()) { + this.value[cnt++] = val; + } + return true; + } + + /** + * Returns the size of the requested value type. + */ + private int getTypeLen(int formatType) { + return formatType & 0xF; + } + + /** + * Convert a signed byte to an unsigned int. + */ + private int unsignedByteToInt(int value) { + return value & 0xFF; + } + + /** + * Convert signed bytes to a 16-bit unsigned int. + */ + private int unsignedBytesToInt(int value1, int value2) { + return value1 + (value2 << 8); + } + + /** + * Convert signed bytes to a 32-bit unsigned int. + */ + private int unsignedBytesToInt(int value1, int value2, int value3, int value4) { + return value1 + (value2 << 8) + (value3 << 16) + (value4 << 24); + } + + /** + * Convert signed bytes to a 16-bit short float value. + */ + private float bytesToFloat(int value1, int value2) { + int mantissa = unsignedToSigned(unsignedByteToInt(value1) + ((unsignedByteToInt(value2) & 0x0F) << 8), 12); + int exponent = unsignedToSigned(unsignedByteToInt(value2) >> 4, 4); + return (float) (mantissa * Math.pow(10, exponent)); + } + + /** + * Convert signed bytes to a 32-bit short float value. + */ + private float bytesToFloat(int value1, int value2, int value3, int value4) { + int mantissa = unsignedToSigned( + unsignedByteToInt(value1) + (unsignedByteToInt(value2) << 8) + (unsignedByteToInt(value3) << 16), 24); + return (float) (mantissa * Math.pow(10, value4)); + } + + /** + * Convert an unsigned integer to a two's-complement signed value. + */ + private int unsignedToSigned(int unsigned, int size) { + if ((unsigned & (1 << size - 1)) != 0) { + return -1 * ((1 << size - 1) - (unsigned & ((1 << size - 1) - 1))); + } else { + return unsigned; + } + } + + /** + * Convert an integer into the signed bits of the specified length. + */ + private int intToSignedBits(int i, int size) { + if (i < 0) { + return (1 << size - 1) + (i & ((1 << size - 1) - 1)); + } else { + return i; + } + } + + public GattCharacteristic getGattCharacteristic() { + return GattCharacteristic.getCharacteristic(uuid); + } + + public enum GattCharacteristic { + // Characteristic + ALERT_CATEGORY_ID(0x2A43), + ALERT_CATEGORY_ID_BIT_MASK(0x2A42), + ALERT_LEVEL(0x2A06), + ALERT_NOTIFICATION_CONTROL_POINT(0x2A44), + ALERT_STATUS(0x2A3F), + APPEARANCE(0x2A01), + BATTERY_LEVEL(0x2A19), + BLOOD_PRESSURE_FEATURE(0x2A49), + BLOOD_PRESSURE_MEASUREMENT(0x2A35), + BODY_SENSOR_LOCATION(0x2A38), + BOOT_KEYOBARD_INPUT_REPORT(0x2A22), + BOOT_KEYOBARD_OUTPUT_REPORT(0x2A32), + BOOT_MOUSE_INPUT_REPORT(0x2A33), + CSC_FEATURE(0x2A5C), + CSC_MEASUREMENT(0x2A5B), + CURRENT_TIME(0x2A2B), + CYCLING_POWER_CONTROL_POINT(0x2A66), + CYCLING_POWER_FEATURE(0x2A65), + CYCLING_POWER_MEASUREMENT(0x2A63), + CYCLING_POWER_VECTOR(0x2A64), + DATE_TIME(0x2A08), + DAY_DATE_TIME(0x2A0A), + DAY_OF_WEEK(0x2A09), + DEVICE_NAME(0x2A00), + DST_OFFSET(0x2A0D), + EXACT_TIME_256(0x2A0C), + FIRMWARE_REVISION_STRING(0x2A26), + GLUCOSE_FEATURE(0x2A51), + GLUCOSE_MEASUREMENT(0x2A18), + GLUCOSE_MEASUREMENT_CONTROL(0x2A34), + HARDWARE_REVISION_STRING(0x2A27), + HEART_RATE_CONTROL_POINT(0x2A39), + HEART_RATE_MEASUREMENT(0x2A37), + HID_CONTROL_POINT(0x2A4C), + HID_INFORMATION(0x2A4A), + IEEE11073_20601_REGULATORY_CERTIFICATION_DATA_LIST(0x2A2A), + INTERMEDIATE_CUFF_PRESSURE(0x2A36), + INTERMEDIATE_TEMPERATURE(0x2A1E), + LN_CONTROL_POINT(0x2A6B), + LN_FEATURE(0x2A6A), + LOCAL_TIME_INFORMATION(0x2A0F), + LOCATION_AND_SPEED(0x2A67), + MANUFACTURER_NAME_STRING(0x2A29), + MEASUREMENT_INTERVAL(0x2A21), + MODEL_NUMBER_STRING(0x2A24), + NAVIGATION(0x2A68), + NEW_ALERT(0x2A46), + PERIPERAL_PREFFERED_CONNECTION_PARAMETERS(0x2A04), + PERIPHERAL_PRIVACY_FLAG(0x2A02), + PN_PID(0x2A50), + POSITION_QUALITY(0x2A69), + PROTOCOL_MODE(0x2A4E), + RECONNECTION_ADDRESS(0x2A03), + RECORD_ACCESS_CONTROL_POINT(0x2A52), + REFERENCE_TIME_INFORMATION(0x2A14), + REPORT(0x2A4D), + REPORT_MAP(0x2A4B), + RINGER_CONTROL_POINT(0x2A40), + RINGER_SETTING(0x2A41), + RSC_FEATURE(0x2A54), + RSC_MEASUREMENT(0x2A53), + SC_CONTROL_POINT(0x2A55), + SCAN_INTERVAL_WINDOW(0x2A4F), + SCAN_REFRESH(0x2A31), + SENSOR_LOCATION(0x2A5D), + SERIAL_NUMBER_STRING(0x2A25), + SERVICE_CHANGED(0x2A05), + SOFTWARE_REVISION_STRING(0x2A28), + SUPPORTED_NEW_ALERT_CATEGORY(0x2A47), + SUPPORTED_UNREAD_ALERT_CATEGORY(0x2A48), + SYSTEM_ID(0x2A23), + TEMPERATURE_MEASUREMENT(0x2A1C), + TEMPERATURE_TYPE(0x2A1D), + TIME_ACCURACY(0x2A12), + TIME_SOURCE(0x2A13), + TIME_UPDATE_CONTROL_POINT(0x2A16), + TIME_UPDATE_STATE(0x2A17), + TIME_WITH_DST(0x2A11), + TIME_ZONE(0x2A0E), + TX_POWER_LEVEL(0x2A07), + UNREAD_ALERT_STATUS(0x2A45), + AGGREGATE_INPUT(0x2A5A), + ANALOG_INPUT(0x2A58), + ANALOG_OUTPUT(0x2A59), + DIGITAL_INPUT(0x2A56), + DIGITAL_OUTPUT(0x2A57), + EXACT_TIME_100(0x2A0B), + NETWORK_AVAILABILITY(0x2A3E), + SCIENTIFIC_TEMPERATURE_IN_CELSIUS(0x2A3C), + SECONDARY_TIME_ZONE(0x2A10), + STRING(0x2A3D), + TEMPERATURE_IN_CELSIUS(0x2A1F), + TEMPERATURE_IN_FAHRENHEIT(0x2A20), + TIME_BROADCAST(0x2A15), + BATTERY_LEVEL_STATE(0x2A1B), + BATTERY_POWER_STATE(0x2A1A), + PULSE_OXIMETRY_CONTINUOUS_MEASUREMENT(0x2A5F), + PULSE_OXIMETRY_CONTROL_POINT(0x2A62), + PULSE_OXIMETRY_FEATURES(0x2A61), + PULSE_OXIMETRY_PULSATILE_EVENT(0x2A60), + PULSE_OXIMETRY_SPOT_CHECK_MEASUREMENT(0x2A5E), + RECORD_ACCESS_CONTROL_POINT_TESTVERSION(0x2A52), + REMOVABLE(0x2A3A), + SERVICE_REQUIRED(0x2A3B); + + private static Map uuidToServiceMapping; + + private UUID uuid; + + private GattCharacteristic(long key) { + this.uuid = new UUID((key << 32) | 0x1000, BluetoothBindingConstants.BLUETOOTH_BASE_UUID); + } + + private static void initMapping() { + uuidToServiceMapping = new HashMap(); + for (GattCharacteristic s : values()) { + uuidToServiceMapping.put(s.uuid, s); + } + } + + public static GattCharacteristic getCharacteristic(UUID uuid) { + if (uuidToServiceMapping == null) { + initMapping(); + } + return uuidToServiceMapping.get(uuid); + } + + /** + * @return the key + */ + public UUID getUUID() { + return uuid; + } + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothClass.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothClass.java new file mode 100644 index 00000000000..8b0c1bbe594 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothClass.java @@ -0,0 +1,166 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +/** + * Represents a Bluetooth class, which describes the general characteristics and capabilities of a device. + * + * @author Chris Jackson - Initial Contribution + * + */ +public class BluetoothClass { + private final int clazz; + + public static final class Service { + private static final int BITMASK = 0xFFE000; + + public static final int LIMITED_DISCOVERABILITY = 0x002000; + public static final int POSITIONING = 0x010000; + public static final int NETWORKING = 0x020000; + public static final int RENDER = 0x040000; + public static final int CAPTURE = 0x080000; + public static final int OBJECT_TRANSFER = 0x100000; + public static final int AUDIO = 0x200000; + public static final int TELEPHONY = 0x400000; + public static final int INFORMATION = 0x800000; + } + + public static class Device { + private static final int BITMASK = 0x1FFC; + + /** + * Defines the major device class constants. + * + */ + public static class Major { + private static final int BITMASK = 0x1F00; + + public static final int MISC = 0x0000; + public static final int COMPUTER = 0x0100; + public static final int PHONE = 0x0200; + public static final int NETWORKING = 0x0300; + public static final int AUDIO_VIDEO = 0x0400; + public static final int PERIPHERAL = 0x0500; + public static final int IMAGING = 0x0600; + public static final int WEARABLE = 0x0700; + public static final int TOY = 0x0800; + public static final int HEALTH = 0x0900; + public static final int UNCATEGORIZED = 0x1F00; + } + + // Devices in the COMPUTER major class + public static final int COMPUTER_UNCATEGORIZED = 0x0100; + public static final int COMPUTER_DESKTOP = 0x0104; + public static final int COMPUTER_SERVER = 0x0108; + public static final int COMPUTER_LAPTOP = 0x010C; + public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110; + public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114; + public static final int COMPUTER_WEARABLE = 0x0118; + + // Devices in the PHONE major class + public static final int PHONE_UNCATEGORIZED = 0x0200; + public static final int PHONE_CELLULAR = 0x0204; + public static final int PHONE_CORDLESS = 0x0208; + public static final int PHONE_SMART = 0x020C; + public static final int PHONE_MODEM_OR_GATEWAY = 0x0210; + public static final int PHONE_ISDN = 0x0214; + + // Minor classes for the AUDIO_VIDEO major class + public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400; + public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404; + public static final int AUDIO_VIDEO_HANDSFREE = 0x0408; + public static final int AUDIO_VIDEO_MICROPHONE = 0x0410; + public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414; + public static final int AUDIO_VIDEO_HEADPHONES = 0x0418; + public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C; + public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420; + public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424; + public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428; + public static final int AUDIO_VIDEO_VCR = 0x042C; + public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430; + public static final int AUDIO_VIDEO_CAMCORDER = 0x0434; + public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438; + public static final int AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = 0x043C; + public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440; + public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448; + + // Devices in the WEARABLE major class + public static final int WEARABLE_UNCATEGORIZED = 0x0700; + public static final int WEARABLE_WRIST_WATCH = 0x0704; + public static final int WEARABLE_PAGER = 0x0708; + public static final int WEARABLE_JACKET = 0x070C; + public static final int WEARABLE_HELMET = 0x0710; + public static final int WEARABLE_GLASSES = 0x0714; + + // Devices in the TOY major class + public static final int TOY_UNCATEGORIZED = 0x0800; + public static final int TOY_ROBOT = 0x0804; + public static final int TOY_VEHICLE = 0x0808; + public static final int TOY_DOLL_ACTION_FIGURE = 0x080C; + public static final int TOY_CONTROLLER = 0x0810; + public static final int TOY_GAME = 0x0814; + + // Devices in the HEALTH major class + public static final int HEALTH_UNCATEGORIZED = 0x0900; + public static final int HEALTH_BLOOD_PRESSURE = 0x0904; + public static final int HEALTH_THERMOMETER = 0x0908; + public static final int HEALTH_WEIGHING = 0x090C; + public static final int HEALTH_GLUCOSE = 0x0910; + public static final int HEALTH_PULSE_OXIMETER = 0x0914; + public static final int HEALTH_PULSE_RATE = 0x0918; + public static final int HEALTH_DATA_DISPLAY = 0x091C; + + // Devices in PERIPHERAL major class + public static final int PERIPHERAL_NON_KEYBOARD_NON_POINTING = 0x0500; + public static final int PERIPHERAL_KEYBOARD = 0x0540; + public static final int PERIPHERAL_POINTING = 0x0580; + public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0; + } + + /** + * Public constructor + * + * @param clazz the device class provided in the bluetooth descriptor + */ + public BluetoothClass(int clazz) { + this.clazz = clazz; + } + + /** + * Return the major and minor device class + * + * @return major and minor device class + */ + public int getDeviceClass() { + return (clazz & Device.BITMASK); + } + + /** + * Return the major device class + * + * @return the major device class + */ + public int getMajorDeviceClass() { + return (clazz & Device.Major.BITMASK); + } + + /** + * Return true if the specified service class is supported + * + * @param service the service id + * @return true, if the class supports the service + */ + public boolean hasService(int service) { + return ((clazz & Service.BITMASK & service) != 0); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompanyIdentifiers.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompanyIdentifiers.java new file mode 100644 index 00000000000..f4bb828a66c --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompanyIdentifiers.java @@ -0,0 +1,1466 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * See https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +@NonNullByDefault +public class BluetoothCompanyIdentifiers { + + private static final Map cic = new HashMap<>(); + + static { + cic.put(0, "Ericsson Technology Licensing"); + cic.put(1, "Nokia Mobile Phones"); + cic.put(2, "Intel Corp."); + cic.put(3, "IBM Corp."); + cic.put(4, "Toshiba Corp."); + cic.put(5, "3Com"); + cic.put(6, "Microsoft"); + cic.put(7, "Lucent"); + cic.put(8, "Motorola"); + cic.put(9, "Infineon Technologies AG"); + cic.put(10, "Cambridge Silicon Radio"); + cic.put(11, "Silicon Wave"); + cic.put(12, "Digianswer A/S"); + cic.put(13, "Texas Instruments Inc."); + cic.put(14, "Parthus Technologies Inc."); + cic.put(15, "Broadcom Corporation"); + cic.put(16, "Mitel Semiconductor"); + cic.put(17, "Widcomm, Inc."); + cic.put(18, "Zeevo, Inc."); + cic.put(19, "Atmel Corporation"); + cic.put(20, "Mitsubishi Electric Corporation"); + cic.put(21, "RTX Telecom A/S"); + cic.put(22, "KC Technology Inc."); + cic.put(23, "Newlogic"); + cic.put(24, "Transilica, Inc."); + cic.put(25, "Rohde & Schwarz GmbH & Co. KG"); + cic.put(26, "TTPCom Limited"); + cic.put(27, "Signia Technologies, Inc."); + cic.put(28, "Conexant Systems Inc."); + cic.put(29, "Qualcomm"); + cic.put(30, "Inventel"); + cic.put(31, "AVM Berlin"); + cic.put(32, "BandSpeed, Inc."); + cic.put(33, "Mansella Ltd"); + cic.put(34, "NEC Corporation"); + cic.put(35, "WavePlus Technology Co., Ltd."); + cic.put(36, "Alcatel"); + cic.put(37, "NXP Semiconductors (formerly Philips Semiconductors)"); + cic.put(38, "C Technologies"); + cic.put(39, "Open Interface"); + cic.put(40, "R F Micro Devices"); + cic.put(41, "Hitachi Ltd"); + cic.put(42, "Symbol Technologies, Inc."); + cic.put(43, "Tenovis"); + cic.put(44, "Macronix International Co. Ltd."); + cic.put(45, "GCT Semiconductor"); + cic.put(46, "Norwood Systems"); + cic.put(47, "MewTel Technology Inc."); + cic.put(48, "ST Microelectronics"); + cic.put(49, "Synopsys, Inc."); + cic.put(50, "Red-M (Communications) Ltd"); + cic.put(51, "Commil Ltd"); + cic.put(52, "Computer Access Technology Corporation (CATC)"); + cic.put(53, "Eclipse (HQ Espana) S.L."); + cic.put(54, "Renesas Electronics Corporation"); + cic.put(55, "Mobilian Corporation"); + cic.put(56, "Terax"); + cic.put(57, "Integrated System Solution Corp."); + cic.put(58, "Matsushita Electric Industrial Co., Ltd."); + cic.put(59, "Gennum Corporation"); + cic.put(60, "BlackBerry Limited (formerly Research In Motion)"); + cic.put(61, "IPextreme, Inc."); + cic.put(62, "Systems and Chips, Inc"); + cic.put(63, "Bluetooth SIG, Inc"); + cic.put(64, "Seiko Epson Corporation"); + cic.put(65, "Integrated Silicon Solution Taiwan, Inc."); + cic.put(66, "CONWISE Technology Corporation Ltd"); + cic.put(67, "PARROT AUTOMOTIVE SAS"); + cic.put(68, "Socket Mobile"); + cic.put(69, "Atheros Communications, Inc."); + cic.put(70, "MediaTek, Inc."); + cic.put(71, "Bluegiga"); + cic.put(72, "Marvell Technology Group Ltd."); + cic.put(73, "3DSP Corporation"); + cic.put(74, "Accel Semiconductor Ltd."); + cic.put(75, "Continental Automotive Systems"); + cic.put(76, "Apple, Inc."); + cic.put(77, "Staccato Communications, Inc."); + cic.put(78, "Avago Technologies"); + cic.put(79, "APT Ltd."); + cic.put(80, "SiRF Technology, Inc."); + cic.put(81, "Tzero Technologies, Inc."); + cic.put(82, "J&M Corporation"); + cic.put(83, "Free2move AB"); + cic.put(84, "3DiJoy Corporation"); + cic.put(85, "Plantronics, Inc."); + cic.put(86, "Sony Ericsson Mobile Communications"); + cic.put(87, "Harman International Industries, Inc."); + cic.put(88, "Vizio, Inc."); + cic.put(89, "Nordic Semiconductor ASA"); + cic.put(90, "EM Microelectronic-Marin SA"); + cic.put(91, "Ralink Technology Corporation"); + cic.put(92, "Belkin International, Inc."); + cic.put(93, "Realtek Semiconductor Corporation"); + cic.put(94, "Stonestreet One, LLC"); + cic.put(95, "Wicentric, Inc."); + cic.put(96, "RivieraWaves S.A.S"); + cic.put(97, "RDA Microelectronics"); + cic.put(98, "Gibson Guitars"); + cic.put(99, "MiCommand Inc."); + cic.put(100, "Band XI International, LLC"); + cic.put(101, "Hewlett-Packard Company"); + cic.put(102, "9Solutions Oy"); + cic.put(103, "GN Netcom A/S"); + cic.put(104, "General Motors"); + cic.put(105, "A&D Engineering, Inc."); + cic.put(106, "MindTree Ltd."); + cic.put(107, "Polar Electro OY"); + cic.put(108, "Beautiful Enterprise Co., Ltd."); + cic.put(109, "BriarTek, Inc"); + cic.put(110, "Summit Data Communications, Inc."); + cic.put(111, "Sound ID"); + cic.put(112, "Monster, LLC"); + cic.put(113, "connectBlue AB"); + cic.put(114, "ShangHai Super Smart Electronics Co. Ltd."); + cic.put(115, "Group Sense Ltd."); + cic.put(116, "Zomm, LLC"); + cic.put(117, "Samsung Electronics Co. Ltd."); + cic.put(118, "Creative Technology Ltd."); + cic.put(119, "Laird Technologies"); + cic.put(120, "Nike, Inc."); + cic.put(121, "lesswire AG"); + cic.put(122, "MStar Semiconductor, Inc."); + cic.put(123, "Hanlynn Technologies"); + cic.put(124, "A & R Cambridge"); + cic.put(125, "Seers Technology Co., Ltd."); + cic.put(126, "Sports Tracking Technologies Ltd."); + cic.put(127, "Autonet Mobile"); + cic.put(128, "DeLorme Publishing Company, Inc."); + cic.put(129, "WuXi Vimicro"); + cic.put(130, "Sennheiser Communications A/S"); + cic.put(131, "TimeKeeping Systems, Inc."); + cic.put(132, "Ludus Helsinki Ltd."); + cic.put(133, "BlueRadios, Inc."); + cic.put(134, "Equinux AG"); + cic.put(135, "Garmin International, Inc."); + cic.put(136, "Ecotest"); + cic.put(137, "GN ReSound A/S"); + cic.put(138, "Jawbone"); + cic.put(139, "Topcon Positioning Systems, LLC"); + cic.put(140, "Gimbal Inc. (formerly Qualcomm Labs, Inc. and Qualcomm Retail Solutions, Inc.)"); + cic.put(141, "Zscan Software"); + cic.put(142, "Quintic Corp"); + cic.put(143, "Telit Wireless Solutions GmbH (formerly Stollmann E+V GmbH)"); + cic.put(144, "Funai Electric Co., Ltd."); + cic.put(145, "Advanced PANMOBIL systems GmbH & Co. KG"); + cic.put(146, "ThinkOptics, Inc."); + cic.put(147, "Universal Electronics, Inc."); + cic.put(148, "Airoha Technology Corp."); + cic.put(149, "NEC Lighting, Ltd."); + cic.put(150, "ODM Technology, Inc."); + cic.put(151, "ConnecteDevice Ltd."); + cic.put(152, "zero1.tv GmbH"); + cic.put(153, "i.Tech Dynamic Global Distribution Ltd."); + cic.put(154, "Alpwise"); + cic.put(155, "Jiangsu Toppower Automotive Electronics Co., Ltd."); + cic.put(156, "Colorfy, Inc."); + cic.put(157, "Geoforce Inc."); + cic.put(158, "Bose Corporation"); + cic.put(159, "Suunto Oy"); + cic.put(160, "Kensington Computer Products Group"); + cic.put(161, "SR-Medizinelektronik"); + cic.put(162, "Vertu Corporation Limited"); + cic.put(163, "Meta Watch Ltd."); + cic.put(164, "LINAK A/S"); + cic.put(165, "OTL Dynamics LLC"); + cic.put(166, "Panda Ocean Inc."); + cic.put(167, "Visteon Corporation"); + cic.put(168, "ARP Devices Limited"); + cic.put(169, "Magneti Marelli S.p.A"); + cic.put(170, "CAEN RFID srl"); + cic.put(171, "Ingenieur-Systemgruppe Zahn GmbH"); + cic.put(172, "Green Throttle Games"); + cic.put(173, "Peter Systemtechnik GmbH"); + cic.put(174, "Omegawave Oy"); + cic.put(175, "Cinetix"); + cic.put(176, "Passif Semiconductor Corp"); + cic.put(177, "Saris Cycling Group, Inc"); + cic.put(178, "Bekey A/S"); + cic.put(179, "Clarinox Technologies Pty. Ltd."); + cic.put(180, "BDE Technology Co., Ltd."); + cic.put(181, "Swirl Networks"); + cic.put(182, "Meso international"); + cic.put(183, "TreLab Ltd"); + cic.put(184, "Qualcomm Innovation Center, Inc. (QuIC)"); + cic.put(185, "Johnson Controls, Inc."); + cic.put(186, "Starkey Laboratories Inc."); + cic.put(187, "S-Power Electronics Limited"); + cic.put(188, "Ace Sensor Inc"); + cic.put(189, "Aplix Corporation"); + cic.put(190, "AAMP of America"); + cic.put(191, "Stalmart Technology Limited"); + cic.put(192, "AMICCOM Electronics Corporation"); + cic.put(193, "Shenzhen Excelsecu Data Technology Co.,Ltd"); + cic.put(194, "Geneq Inc."); + cic.put(195, "adidas AG"); + cic.put(196, "LG Electronics"); + cic.put(197, "Onset Computer Corporation"); + cic.put(198, "Selfly BV"); + cic.put(199, "Quuppa Oy."); + cic.put(200, "GeLo Inc"); + cic.put(201, "Evluma"); + cic.put(202, "MC10"); + cic.put(203, "Binauric SE"); + cic.put(204, "Beats Electronics"); + cic.put(205, "Microchip Technology Inc."); + cic.put(206, "Elgato Systems GmbH"); + cic.put(207, "ARCHOS SA"); + cic.put(208, "Dexcom, Inc."); + cic.put(209, "Polar Electro Europe B.V."); + cic.put(210, "Dialog Semiconductor B.V."); + cic.put(211, "Taixingbang Technology (HK) Co,. LTD."); + cic.put(212, "Kawantech"); + cic.put(213, "Austco Communication Systems"); + cic.put(214, "Timex Group USA, Inc."); + cic.put(215, "Qualcomm Technologies, Inc."); + cic.put(216, "Qualcomm Connected Experiences, Inc."); + cic.put(217, "Voyetra Turtle Beach"); + cic.put(218, "txtr GmbH"); + cic.put(219, "Biosentronics"); + cic.put(220, "Procter & Gamble"); + cic.put(221, "Hosiden Corporation"); + cic.put(222, "Muzik LLC"); + cic.put(223, "Misfit Wearables Corp"); + cic.put(224, "Google"); + cic.put(225, "Danlers Ltd"); + cic.put(226, "Semilink Inc"); + cic.put(227, "inMusic Brands, Inc"); + cic.put(228, "L.S. Research Inc."); + cic.put(229, "Eden Software Consultants Ltd."); + cic.put(230, "Freshtemp"); + cic.put(231, "KS Technologies"); + cic.put(232, "ACTS Technologies"); + cic.put(233, "Vtrack Systems"); + cic.put(234, "Nielsen-Kellerman Company"); + cic.put(235, "Server Technology Inc."); + cic.put(236, "BioResearch Associates"); + cic.put(237, "Jolly Logic, LLC"); + cic.put(238, "Above Average Outcomes, Inc."); + cic.put(239, "Bitsplitters GmbH"); + cic.put(240, "PayPal, Inc."); + cic.put(241, "Witron Technology Limited"); + cic.put(242, "Morse Project Inc."); + cic.put(243, "Kent Displays Inc."); + cic.put(244, "Nautilus Inc."); + cic.put(245, "Smartifier Oy"); + cic.put(246, "Elcometer Limited"); + cic.put(247, "VSN Technologies, Inc."); + cic.put(248, "AceUni Corp., Ltd."); + cic.put(249, "StickNFind"); + cic.put(250, "Crystal Code AB"); + cic.put(251, "KOUKAAM a.s."); + cic.put(252, "Delphi Corporation"); + cic.put(253, "ValenceTech Limited"); + cic.put(254, "Stanley Black and Decker"); + cic.put(255, "Typo Products, LLC"); + cic.put(256, "TomTom International BV"); + cic.put(257, "Fugoo, Inc."); + cic.put(258, "Keiser Corporation"); + cic.put(259, "Bang & Olufsen A/S"); + cic.put(260, "PLUS Location Systems Pty Ltd"); + cic.put(261, "Ubiquitous Computing Technology Corporation"); + cic.put(262, "Innovative Yachtter Solutions"); + cic.put(263, "William Demant Holding A/S"); + cic.put(264, "Chicony Electronics Co., Ltd."); + cic.put(265, "Atus BV"); + cic.put(266, "Codegate Ltd"); + cic.put(267, "ERi, Inc"); + cic.put(268, "Transducers Direct, LLC"); + cic.put(269, "Fujitsu Ten LImited"); + cic.put(270, "Audi AG"); + cic.put(271, "HiSilicon Technologies Col, Ltd."); + cic.put(272, "Nippon Seiki Co., Ltd."); + cic.put(273, "Steelseries ApS"); + cic.put(274, "Visybl Inc."); + cic.put(275, "Openbrain Technologies, Co., Ltd."); + cic.put(276, "Xensr"); + cic.put(277, "e.solutions"); + cic.put(278, "10AK Technologies"); + cic.put(279, "Wimoto Technologies Inc"); + cic.put(280, "Radius Networks, Inc."); + cic.put(281, "Wize Technology Co., Ltd."); + cic.put(282, "Qualcomm Labs, Inc."); + cic.put(283, "Aruba Networks"); + cic.put(284, "Baidu"); + cic.put(285, "Arendi AG"); + cic.put(286, "Skoda Auto a.s."); + cic.put(287, "Volkswagen AG"); + cic.put(288, "Porsche AG"); + cic.put(289, "Sino Wealth Electronic Ltd."); + cic.put(290, "AirTurn, Inc."); + cic.put(291, "Kinsa, Inc"); + cic.put(292, "HID Global"); + cic.put(293, "SEAT es"); + cic.put(294, "Promethean Ltd."); + cic.put(295, "Salutica Allied Solutions"); + cic.put(296, "GPSI Group Pty Ltd"); + cic.put(297, "Nimble Devices Oy"); + cic.put(298, "Changzhou Yongse Infotech Co., Ltd."); + cic.put(299, "SportIQ"); + cic.put(300, "TEMEC Instruments B.V."); + cic.put(301, "Sony Corporation"); + cic.put(302, "ASSA ABLOY"); + cic.put(303, "Clarion Co. Inc."); + cic.put(304, "Warehouse Innovations"); + cic.put(305, "Cypress Semiconductor"); + cic.put(306, "MADS Inc"); + cic.put(307, "Blue Maestro Limited"); + cic.put(308, "Resolution Products, Ltd."); + cic.put(309, "Aireware LLC"); + cic.put(310, "Silvair, Inc."); + cic.put(311, "Prestigio Plaza Ltd."); + cic.put(312, "NTEO Inc."); + cic.put(313, "Focus Systems Corporation"); + cic.put(314, "Tencent Holdings Ltd."); + cic.put(315, "Allegion"); + cic.put(316, "Murata Manufacturing Co., Ltd."); + cic.put(317, "WirelessWERX"); + cic.put(318, "Nod, Inc."); + cic.put(319, "B&B Manufacturing Company"); + cic.put(320, "Alpine Electronics (China) Co., Ltd"); + cic.put(321, "FedEx Services"); + cic.put(322, "Grape Systems Inc."); + cic.put(323, "Bkon Connect"); + cic.put(324, "Lintech GmbH"); + cic.put(325, "Novatel Wireless"); + cic.put(326, "Ciright"); + cic.put(327, "Mighty Cast, Inc."); + cic.put(328, "Ambimat Electronics"); + cic.put(329, "Perytons Ltd."); + cic.put(330, "Tivoli Audio, LLC"); + cic.put(331, "Master Lock"); + cic.put(332, "Mesh-Net Ltd"); + cic.put(333, "HUIZHOU DESAY SV AUTOMOTIVE CO., LTD."); + cic.put(334, "Tangerine, Inc."); + cic.put(335, "B&W Group Ltd."); + cic.put(336, "Pioneer Corporation"); + cic.put(337, "OnBeep"); + cic.put(338, "Vernier Software & Technology"); + cic.put(339, "ROL Ergo"); + cic.put(340, "Pebble Technology"); + cic.put(341, "NETATMO"); + cic.put(342, "Accumulate AB"); + cic.put(343, "Anhui Huami Information Technology Co., Ltd."); + cic.put(344, "Inmite s.r.o."); + cic.put(345, "ChefSteps, Inc."); + cic.put(346, "micas AG"); + cic.put(347, "Biomedical Research Ltd."); + cic.put(348, "Pitius Tec S.L."); + cic.put(349, "Estimote, Inc."); + cic.put(350, "Unikey Technologies, Inc."); + cic.put(351, "Timer Cap Co."); + cic.put(352, "AwoX"); + cic.put(353, "yikes"); + cic.put(354, "MADSGlobalNZ Ltd."); + cic.put(355, "PCH International"); + cic.put(356, "Qingdao Yeelink Information Technology Co., Ltd."); + cic.put(357, "Milwaukee Tool (Formally Milwaukee Electric Tools)"); + cic.put(358, "MISHIK Pte Ltd"); + cic.put(359, "Ascensia Diabetes Care US Inc."); + cic.put(360, "Spicebox LLC"); + cic.put(361, "emberlight"); + cic.put(362, "Cooper-Atkins Corporation"); + cic.put(363, "Qblinks"); + cic.put(364, "MYSPHERA"); + cic.put(365, "LifeScan Inc"); + cic.put(366, "Volantic AB"); + cic.put(367, "Podo Labs, Inc"); + cic.put(368, "Roche Diabetes Care AG"); + cic.put(369, "Amazon Fulfillment Service"); + cic.put(370, "Connovate Technology Private Limited"); + cic.put(371, "Kocomojo, LLC"); + cic.put(372, "Everykey Inc."); + cic.put(373, "Dynamic Controls"); + cic.put(374, "SentriLock"); + cic.put(375, "I-SYST inc."); + cic.put(376, "CASIO COMPUTER CO., LTD."); + cic.put(377, "LAPIS Semiconductor Co., Ltd."); + cic.put(378, "Telemonitor, Inc."); + cic.put(379, "taskit GmbH"); + cic.put(380, "Daimler AG"); + cic.put(381, "BatAndCat"); + cic.put(382, "BluDotz Ltd"); + cic.put(383, "XTel Wireless ApS"); + cic.put(384, "Gigaset Communications GmbH"); + cic.put(385, "Gecko Health Innovations, Inc."); + cic.put(386, "HOP Ubiquitous"); + cic.put(387, "Walt Disney"); + cic.put(388, "Nectar"); + cic.put(389, "bel'apps LLC"); + cic.put(390, "CORE Lighting Ltd"); + cic.put(391, "Seraphim Sense Ltd"); + cic.put(392, "Unico RBC"); + cic.put(393, "Physical Enterprises Inc."); + cic.put(394, "Able Trend Technology Limited"); + cic.put(395, "Konica Minolta, Inc."); + cic.put(396, "Wilo SE"); + cic.put(397, "Extron Design Services"); + cic.put(398, "Fitbit, Inc."); + cic.put(399, "Fireflies Systems"); + cic.put(400, "Intelletto Technologies Inc."); + cic.put(401, "FDK CORPORATION"); + cic.put(402, "Cloudleaf, Inc"); + cic.put(403, "Maveric Automation LLC"); + cic.put(404, "Acoustic Stream Corporation"); + cic.put(405, "Zuli"); + cic.put(406, "Paxton Access Ltd"); + cic.put(407, "WiSilica Inc."); + cic.put(408, "VENGIT Korlatolt Felelossegu Tarsasag"); + cic.put(409, "SALTO SYSTEMS S.L."); + cic.put(410, "TRON Forum (formerly T-Engine Forum)"); + cic.put(411, "CUBETECH s.r.o."); + cic.put(412, "Cokiya Incorporated"); + cic.put(413, "CVS Health"); + cic.put(414, "Ceruus"); + cic.put(415, "Strainstall Ltd"); + cic.put(416, "Channel Enterprises (HK) Ltd."); + cic.put(417, "FIAMM"); + cic.put(418, "GIGALANE.CO.,LTD"); + cic.put(419, "EROAD"); + cic.put(420, "Mine Safety Appliances"); + cic.put(421, "Icon Health and Fitness"); + cic.put(422, "Asandoo GmbH"); + cic.put(423, "ENERGOUS CORPORATION"); + cic.put(424, "Taobao"); + cic.put(425, "Canon Inc."); + cic.put(426, "Geophysical Technology Inc."); + cic.put(427, "Facebook, Inc."); + cic.put(428, "Nipro Diagnostics, Inc."); + cic.put(429, "FlightSafety International"); + cic.put(430, "Earlens Corporation"); + cic.put(431, "Sunrise Micro Devices, Inc."); + cic.put(432, "Star Micronics Co., Ltd."); + cic.put(433, "Netizens Sp. z o.o."); + cic.put(434, "Nymi Inc."); + cic.put(435, "Nytec, Inc."); + cic.put(436, "Trineo Sp. z o.o."); + cic.put(437, "Nest Labs Inc."); + cic.put(438, "LM Technologies Ltd"); + cic.put(439, "General Electric Company"); + cic.put(440, "i+D3 S.L."); + cic.put(441, "HANA Micron"); + cic.put(442, "Stages Cycling LLC"); + cic.put(443, "Cochlear Bone Anchored Solutions AB"); + cic.put(444, "SenionLab AB"); + cic.put(445, "Syszone Co., Ltd"); + cic.put(446, "Pulsate Mobile Ltd."); + cic.put(447, "Hong Kong HunterSun Electronic Limited"); + cic.put(448, "pironex GmbH"); + cic.put(449, "BRADATECH Corp."); + cic.put(450, "Transenergooil AG"); + cic.put(451, "Bunch"); + cic.put(452, "DME Microelectronics"); + cic.put(453, "Bitcraze AB"); + cic.put(454, "HASWARE Inc."); + cic.put(455, "Abiogenix Inc."); + cic.put(456, "Poly-Control ApS"); + cic.put(457, "Avi-on"); + cic.put(458, "Laerdal Medical AS"); + cic.put(459, "Fetch My Pet"); + cic.put(460, "Sam Labs Ltd."); + cic.put(461, "Chengdu Synwing Technology Ltd"); + cic.put(462, "HOUWA SYSTEM DESIGN, k.k."); + cic.put(463, "BSH"); + cic.put(464, "Primus Inter Pares Ltd"); + cic.put(465, "August Home, Inc"); + cic.put(466, "Gill Electronics"); + cic.put(467, "Sky Wave Design"); + cic.put(468, "Newlab S.r.l."); + cic.put(469, "ELAD srl"); + cic.put(470, "G-wearables inc."); + cic.put(471, "Squadrone Systems Inc."); + cic.put(472, "Code Corporation"); + cic.put(473, "Savant Systems LLC"); + cic.put(474, "Logitech International SA"); + cic.put(475, "Innblue Consulting"); + cic.put(476, "iParking Ltd."); + cic.put(477, "Koninklijke Philips Electronics N.V."); + cic.put(478, "Minelab Electronics Pty Limited"); + cic.put(479, "Bison Group Ltd."); + cic.put(480, "Widex A/S"); + cic.put(481, "Jolla Ltd"); + cic.put(482, "Lectronix, Inc."); + cic.put(483, "Caterpillar Inc"); + cic.put(484, "Freedom Innovations"); + cic.put(485, "Dynamic Devices Ltd"); + cic.put(486, "Technology Solutions (UK) Ltd"); + cic.put(487, "IPS Group Inc."); + cic.put(488, "STIR"); + cic.put(489, "Sano, Inc."); + cic.put(490, "Advanced Application Design, Inc."); + cic.put(491, "AutoMap LLC"); + cic.put(492, "Spreadtrum Communications Shanghai Ltd"); + cic.put(493, "CuteCircuit LTD"); + cic.put(494, "Valeo Service"); + cic.put(495, "Fullpower Technologies, Inc."); + cic.put(496, "KloudNation"); + cic.put(497, "Zebra Technologies Corporation"); + cic.put(498, "Itron, Inc."); + cic.put(499, "The University of Tokyo"); + cic.put(500, "UTC Fire and Security"); + cic.put(501, "Cool Webthings Limited"); + cic.put(502, "DJO Global"); + cic.put(503, "Gelliner Limited"); + cic.put(504, "Anyka (Guangzhou) Microelectronics Technology Co, LTD"); + cic.put(505, "Medtronic Inc."); + cic.put(506, "Gozio Inc."); + cic.put(507, "Form Lifting, LLC"); + cic.put(508, "Wahoo Fitness, LLC"); + cic.put(509, "Kontakt Micro-Location Sp. z o.o."); + cic.put(510, "Radio Systems Corporation"); + cic.put(511, "Freescale Semiconductor, Inc."); + cic.put(512, "Verifone Systems Pte Ltd. Taiwan Branch"); + cic.put(513, "AR Timing"); + cic.put(514, "Rigado LLC"); + cic.put(515, "Kemppi Oy"); + cic.put(516, "Tapcentive Inc."); + cic.put(517, "Smartbotics Inc."); + cic.put(518, "Otter Products, LLC"); + cic.put(519, "STEMP Inc."); + cic.put(520, "LumiGeek LLC"); + cic.put(521, "InvisionHeart Inc."); + cic.put(522, "Macnica Inc."); + cic.put(523, "Jaguar Land Rover Limited"); + cic.put(524, "CoroWare Technologies, Inc"); + cic.put(525, "Simplo Technology Co., LTD"); + cic.put(526, "Omron Healthcare Co., LTD"); + cic.put(527, "Comodule GMBH"); + cic.put(528, "ikeGPS"); + cic.put(529, "Telink Semiconductor Co. Ltd"); + cic.put(530, "Interplan Co., Ltd"); + cic.put(531, "Wyler AG"); + cic.put(532, "IK Multimedia Production srl"); + cic.put(533, "Lukoton Experience Oy"); + cic.put(534, "MTI Ltd"); + cic.put(535, "Tech4home, Lda"); + cic.put(536, "Hiotech AB"); + cic.put(537, "DOTT Limited"); + cic.put(538, "Blue Speck Labs, LLC"); + cic.put(539, "Cisco Systems, Inc"); + cic.put(540, "Mobicomm Inc"); + cic.put(541, "Edamic"); + cic.put(542, "Goodnet, Ltd"); + cic.put(543, "Luster Leaf Products Inc"); + cic.put(544, "Manus Machina BV"); + cic.put(545, "Mobiquity Networks Inc"); + cic.put(546, "Praxis Dynamics"); + cic.put(547, "Philip Morris Products S.A."); + cic.put(548, "Comarch SA"); + cic.put(549, "Nestl Nespresso S.A."); + cic.put(550, "Merlinia A/S"); + cic.put(551, "LifeBEAM Technologies"); + cic.put(552, "Twocanoes Labs, LLC"); + cic.put(553, "Muoverti Limited"); + cic.put(554, "Stamer Musikanlagen GMBH"); + cic.put(555, "Tesla Motors"); + cic.put(556, "Pharynks Corporation"); + cic.put(557, "Lupine"); + cic.put(558, "Siemens AG"); + cic.put(559, "Huami (Shanghai) Culture Communication CO., LTD"); + cic.put(560, "Foster Electric Company, Ltd"); + cic.put(561, "ETA SA"); + cic.put(562, "x-Senso Solutions Kft"); + cic.put(563, "Shenzhen SuLong Communication Ltd"); + cic.put(564, "FengFan (BeiJing) Technology Co, Ltd"); + cic.put(565, "Qrio Inc"); + cic.put(566, "Pitpatpet Ltd"); + cic.put(567, "MSHeli s.r.l."); + cic.put(568, "Trakm8 Ltd"); + cic.put(569, "JIN CO, Ltd"); + cic.put(570, "Alatech Tehnology"); + cic.put(571, "Beijing CarePulse Electronic Technology Co, Ltd"); + cic.put(572, "Awarepoint"); + cic.put(573, "ViCentra B.V."); + cic.put(574, "Raven Industries"); + cic.put(575, "WaveWare Technologies Inc."); + cic.put(576, "Argenox Technologies"); + cic.put(577, "Bragi GmbH"); + cic.put(578, "16Lab Inc"); + cic.put(579, "Masimo Corp"); + cic.put(580, "Iotera Inc"); + cic.put(581, "Endress+Hauser"); + cic.put(582, "ACKme Networks, Inc."); + cic.put(583, "FiftyThree Inc."); + cic.put(584, "Parker Hannifin Corp"); + cic.put(585, "Transcranial Ltd"); + cic.put(586, "Uwatec AG"); + cic.put(587, "Orlan LLC"); + cic.put(588, "Blue Clover Devices"); + cic.put(589, "M-Way Solutions GmbH"); + cic.put(590, "Microtronics Engineering GmbH"); + cic.put(591, "Schneider Schreibgerte GmbH"); + cic.put(592, "Sapphire Circuits LLC"); + cic.put(593, "Lumo Bodytech Inc."); + cic.put(594, "UKC Technosolution"); + cic.put(595, "Xicato Inc."); + cic.put(596, "Playbrush"); + cic.put(597, "Dai Nippon Printing Co., Ltd."); + cic.put(598, "G24 Power Limited"); + cic.put(599, "AdBabble Local Commerce Inc."); + cic.put(600, "Devialet SA"); + cic.put(601, "ALTYOR"); + cic.put(602, "University of Applied Sciences Valais/Haute Ecole Valaisanne"); + cic.put(603, "Five Interactive, LLC dba Zendo"); + cic.put(604, "NetEaseHangzhouNetwork co.Ltd."); + cic.put(605, "Lexmark International Inc."); + cic.put(606, "Fluke Corporation"); + cic.put(607, "Yardarm Technologies"); + cic.put(608, "SensaRx"); + cic.put(609, "SECVRE GmbH"); + cic.put(610, "Glacial Ridge Technologies"); + cic.put(611, "Identiv, Inc."); + cic.put(612, "DDS, Inc."); + cic.put(613, "SMK Corporation"); + cic.put(614, "Schawbel Technologies LLC"); + cic.put(615, "XMI Systems SA"); + cic.put(616, "Cerevo"); + cic.put(617, "Torrox GmbH & Co KG"); + cic.put(618, "Gemalto"); + cic.put(619, "DEKA Research & Development Corp."); + cic.put(620, "Domster Tadeusz Szydlowski"); + cic.put(621, "Technogym SPA"); + cic.put(622, "FLEURBAEY BVBA"); + cic.put(623, "Aptcode Solutions"); + cic.put(624, "LSI ADL Technology"); + cic.put(625, "Animas Corp"); + cic.put(626, "Alps Electric Co., Ltd."); + cic.put(627, "OCEASOFT"); + cic.put(628, "Motsai Research"); + cic.put(629, "Geotab"); + cic.put(630, "E.G.O. Elektro-Gertebau GmbH"); + cic.put(631, "bewhere inc"); + cic.put(632, "Johnson Outdoors Inc"); + cic.put(633, "steute Schaltgerate GmbH & Co. KG"); + cic.put(634, "Ekomini inc."); + cic.put(635, "DEFA AS"); + cic.put(636, "Aseptika Ltd"); + cic.put(637, "HUAWEI Technologies Co., Ltd. ( )"); + cic.put(638, "HabitAware, LLC"); + cic.put(639, "ruwido austria gmbh"); + cic.put(640, "ITEC corporation"); + cic.put(641, "StoneL"); + cic.put(642, "Sonova AG"); + cic.put(643, "Maven Machines, Inc."); + cic.put(644, "Synapse Electronics"); + cic.put(645, "Standard Innovation Inc."); + cic.put(646, "RF Code, Inc."); + cic.put(647, "Wally Ventures S.L."); + cic.put(648, "Willowbank Electronics Ltd"); + cic.put(649, "SK Telecom"); + cic.put(650, "Jetro AS"); + cic.put(651, "Code Gears LTD"); + cic.put(652, "NANOLINK APS"); + cic.put(653, "IF, LLC"); + cic.put(654, "RF Digital Corp"); + cic.put(655, "Church & Dwight Co., Inc"); + cic.put(656, "Multibit Oy"); + cic.put(657, "CliniCloud Inc"); + cic.put(658, "SwiftSensors"); + cic.put(659, "Blue Bite"); + cic.put(660, "ELIAS GmbH"); + cic.put(661, "Sivantos GmbH"); + cic.put(662, "Petzl"); + cic.put(663, "storm power ltd"); + cic.put(664, "EISST Ltd"); + cic.put(665, "Inexess Technology Simma KG"); + cic.put(666, "Currant, Inc."); + cic.put(667, "C2 Development, Inc."); + cic.put(668, "Blue Sky Scientific, LLC"); + cic.put(669, "ALOTTAZS LABS, LLC"); + cic.put(670, "Kupson spol. s r.o."); + cic.put(671, "Areus Engineering GmbH"); + cic.put(672, "Impossible Camera GmbH"); + cic.put(673, "InventureTrack Systems"); + cic.put(674, "LockedUp"); + cic.put(675, "Itude"); + cic.put(676, "Pacific Lock Company"); + cic.put(677, "Tendyron Corporation ( )"); + cic.put(678, "Robert Bosch GmbH"); + cic.put(679, "Illuxtron international B.V."); + cic.put(680, "miSport Ltd."); + cic.put(681, "Chargelib"); + cic.put(682, "Doppler Lab"); + cic.put(683, "BBPOS Limited"); + cic.put(684, "RTB Elektronik GmbH & Co. KG"); + cic.put(685, "Rx Networks, Inc."); + cic.put(686, "WeatherFlow, Inc."); + cic.put(687, "Technicolor USA Inc."); + cic.put(688, "Bestechnic(Shanghai),Ltd"); + cic.put(689, "Raden Inc"); + cic.put(690, "JouZen Oy"); + cic.put(691, "CLABER S.P.A."); + cic.put(692, "Hyginex, Inc."); + cic.put(693, "HANSHIN ELECTRIC RAILWAY CO.,LTD."); + cic.put(694, "Schneider Electric"); + cic.put(695, "Oort Technologies LLC"); + cic.put(696, "Chrono Therapeutics"); + cic.put(697, "Rinnai Corporation"); + cic.put(698, "Swissprime Technologies AG"); + cic.put(699, "Koha.,Co.Ltd"); + cic.put(700, "Genevac Ltd"); + cic.put(701, "Chemtronics"); + cic.put(702, "Seguro Technology Sp. z o.o."); + cic.put(703, "Redbird Flight Simulations"); + cic.put(704, "Dash Robotics"); + cic.put(705, "LINE Corporation"); + cic.put(706, "Guillemot Corporation"); + cic.put(707, "Techtronic Power Tools Technology Limited"); + cic.put(708, "Wilson Sporting Goods"); + cic.put(709, "Lenovo (Singapore) Pte Ltd. ( )"); + cic.put(710, "Ayatan Sensors"); + cic.put(711, "Electronics Tomorrow Limited"); + cic.put(712, "VASCO Data Security International, Inc."); + cic.put(713, "PayRange Inc."); + cic.put(714, "ABOV Semiconductor"); + cic.put(715, "AINA-Wireless Inc."); + cic.put(716, "Eijkelkamp Soil & Water"); + cic.put(717, "BMA ergonomics b.v."); + cic.put(718, "Teva Branded Pharmaceutical Products R&D, Inc."); + cic.put(719, "Anima"); + cic.put(720, "3M"); + cic.put(721, "Empatica Srl"); + cic.put(722, "Afero, Inc."); + cic.put(723, "Powercast Corporation"); + cic.put(724, "Secuyou ApS"); + cic.put(725, "OMRON Corporation"); + cic.put(726, "Send Solutions"); + cic.put(727, "NIPPON SYSTEMWARE CO.,LTD."); + cic.put(728, "Neosfar"); + cic.put(729, "Fliegl Agrartechnik GmbH"); + cic.put(730, "Gilvader"); + cic.put(731, "Digi International Inc (R)"); + cic.put(732, "DeWalch Technologies, Inc."); + cic.put(733, "Flint Rehabilitation Devices, LLC"); + cic.put(734, "Samsung SDS Co., Ltd."); + cic.put(735, "Blur Product Development"); + cic.put(736, "University of Michigan"); + cic.put(737, "Victron Energy BV"); + cic.put(738, "NTT docomo"); + cic.put(739, "Carmanah Technologies Corp."); + cic.put(740, "Bytestorm Ltd."); + cic.put(741, "Espressif Incorporated ( () )"); + cic.put(742, "Unwire"); + cic.put(743, "Connected Yard, Inc."); + cic.put(744, "American Music Environments"); + cic.put(745, "Sensogram Technologies, Inc."); + cic.put(746, "Fujitsu Limited"); + cic.put(747, "Ardic Technology"); + cic.put(748, "Delta Systems, Inc"); + cic.put(749, "HTC Corporation"); + cic.put(750, "Citizen Holdings Co., Ltd."); + cic.put(751, "SMART-INNOVATION.inc"); + cic.put(752, "Blackrat Software"); + cic.put(753, "The Idea Cave, LLC"); + cic.put(754, "GoPro, Inc."); + cic.put(755, "AuthAir, Inc"); + cic.put(756, "Vensi, Inc."); + cic.put(757, "Indagem Tech LLC"); + cic.put(758, "Intemo Technologies"); + cic.put(759, "DreamVisions co., Ltd."); + cic.put(760, "Runteq Oy Ltd"); + cic.put(761, "IMAGINATION TECHNOLOGIES LTD"); + cic.put(762, "CoSTAR TEchnologies"); + cic.put(763, "Clarius Mobile Health Corp."); + cic.put(764, "Shanghai Frequen Microelectronics Co., Ltd."); + cic.put(765, "Uwanna, Inc."); + cic.put(766, "Lierda Science & Technology Group Co., Ltd."); + cic.put(767, "Silicon Laboratories"); + cic.put(768, "World Moto Inc."); + cic.put(769, "Giatec Scientific Inc."); + cic.put(770, "Loop Devices, Inc"); + cic.put(771, "IACA electronique"); + cic.put(772, "Martians Inc"); + cic.put(773, "Swipp ApS"); + cic.put(774, "Life Laboratory Inc."); + cic.put(775, "FUJI INDUSTRIAL CO.,LTD."); + cic.put(776, "Surefire, LLC"); + cic.put(777, "Dolby Labs"); + cic.put(778, "Ellisys"); + cic.put(779, "Magnitude Lighting Converters"); + cic.put(780, "Hilti AG"); + cic.put(781, "Devdata S.r.l."); + cic.put(782, "Deviceworx"); + cic.put(783, "Shortcut Labs"); + cic.put(784, "SGL Italia S.r.l."); + cic.put(785, "PEEQ DATA"); + cic.put(786, "Ducere Technologies Pvt Ltd"); + cic.put(787, "DiveNav, Inc."); + cic.put(788, "RIIG AI Sp. z o.o."); + cic.put(789, "Thermo Fisher Scientific"); + cic.put(790, "AG Measurematics Pvt. Ltd."); + cic.put(791, "CHUO Electronics CO., LTD."); + cic.put(792, "Aspenta International"); + cic.put(793, "Eugster Frismag AG"); + cic.put(794, "Amber wireless GmbH"); + cic.put(795, "HQ Inc"); + cic.put(796, "Lab Sensor Solutions"); + cic.put(797, "Enterlab ApS"); + cic.put(798, "Eyefi, Inc."); + cic.put(799, "MetaSystem S.p.A."); + cic.put(800, "SONO ELECTRONICS. CO., LTD"); + cic.put(801, "Jewelbots"); + cic.put(802, "Compumedics Limited"); + cic.put(803, "Rotor Bike Components"); + cic.put(804, "Astro, Inc."); + cic.put(805, "Amotus Solutions"); + cic.put(806, "Healthwear Technologies (Changzhou)Ltd"); + cic.put(807, "Essex Electronics"); + cic.put(808, "Grundfos A/S"); + cic.put(809, "Eargo, Inc."); + cic.put(810, "Electronic Design Lab"); + cic.put(811, "ESYLUX"); + cic.put(812, "NIPPON SMT.CO.,Ltd"); + cic.put(813, "BM innovations GmbH"); + cic.put(814, "indoormap"); + cic.put(815, "OttoQ Inc"); + cic.put(816, "North Pole Engineering"); + cic.put(817, "3flares Technologies Inc."); + cic.put(818, "Electrocompaniet A.S."); + cic.put(819, "Mul-T-Lock"); + cic.put(820, "Corentium AS"); + cic.put(821, "Enlighted Inc"); + cic.put(822, "GISTIC"); + cic.put(823, "AJP2 Holdings, LLC"); + cic.put(824, "COBI GmbH"); + cic.put(825, "Blue Sky Scientific, LLC"); + cic.put(826, "Appception, Inc."); + cic.put(827, "Courtney Thorne Limited"); + cic.put(828, "Virtuosys"); + cic.put(829, "TPV Technology Limited"); + cic.put(830, "Monitra SA"); + cic.put(831, "Automation Components, Inc."); + cic.put(832, "Letsense s.r.l."); + cic.put(833, "Etesian Technologies LLC"); + cic.put(834, "GERTEC BRASIL LTDA."); + cic.put(835, "Drekker Development Pty. Ltd."); + cic.put(836, "Whirl Inc"); + cic.put(837, "Locus Positioning"); + cic.put(838, "Acuity Brands Lighting, Inc"); + cic.put(839, "Prevent Biometrics"); + cic.put(840, "Arioneo"); + cic.put(841, "VersaMe"); + cic.put(842, "Vaddio"); + cic.put(843, "Libratone A/S"); + cic.put(844, "HM Electronics, Inc."); + cic.put(845, "TASER International, Inc."); + cic.put(846, "SafeTrust Inc."); + cic.put(847, "Heartland Payment Systems"); + cic.put(848, "Bitstrata Systems Inc."); + cic.put(849, "Pieps GmbH"); + cic.put(850, "iRiding(Xiamen)Technology Co.,Ltd."); + cic.put(851, "Alpha Audiotronics, Inc."); + cic.put(852, "TOPPAN FORMS CO.,LTD."); + cic.put(853, "Sigma Designs, Inc."); + cic.put(854, "Spectrum Brands, Inc."); + cic.put(855, "Polymap Wireless"); + cic.put(856, "MagniWare Ltd."); + cic.put(857, "Novotec Medical GmbH"); + cic.put(858, "Medicom Innovation Partner a/s"); + cic.put(859, "Matrix Inc."); + cic.put(860, "Eaton Corporation"); + cic.put(861, "KYS"); + cic.put(862, "Naya Health, Inc."); + cic.put(863, "Acromag"); + cic.put(864, "Insulet Corporation"); + cic.put(865, "Wellinks Inc."); + cic.put(866, "ON Semiconductor"); + cic.put(867, "FREELAP SA"); + cic.put(868, "Favero Electronics Srl"); + cic.put(869, "BioMech Sensor LLC"); + cic.put(870, "BOLTT Sports technologies Private limited"); + cic.put(871, "Saphe International"); + cic.put(872, "Metormote AB"); + cic.put(873, "littleBits"); + cic.put(874, "SetPoint Medical"); + cic.put(875, "BRControls Products BV"); + cic.put(876, "Zipcar"); + cic.put(877, "AirBolt Pty Ltd"); + cic.put(878, "KeepTruckin Inc"); + cic.put(879, "Motiv, Inc."); + cic.put(880, "Wazombi Labs O"); + cic.put(881, "ORBCOMM"); + cic.put(882, "Nixie Labs, Inc."); + cic.put(883, "AppNearMe Ltd"); + cic.put(884, "Holman Industries"); + cic.put(885, "Expain AS"); + cic.put(886, "Electronic Temperature Instruments Ltd"); + cic.put(887, "Plejd AB"); + cic.put(888, "Propeller Health"); + cic.put(889, "Shenzhen iMCO Electronic Technology Co.,Ltd"); + cic.put(890, "Algoria"); + cic.put(891, "Apption Labs Inc."); + cic.put(892, "Cronologics Corporation"); + cic.put(893, "MICRODIA Ltd."); + cic.put(894, "lulabytes S.L."); + cic.put(895, "Nestec S.A."); + cic.put(896, "LLC \"MEGA-F service\""); + cic.put(897, "Sharp Corporation"); + cic.put(898, "Precision Outcomes Ltd"); + cic.put(899, "Kronos Incorporated"); + cic.put(900, "OCOSMOS Co., Ltd."); + cic.put(901, "Embedded Electronic Solutions Ltd. dba e2Solutions"); + cic.put(902, "Aterica Inc."); + cic.put(903, "BluStor PMC, Inc."); + cic.put(904, "Kapsch TrafficCom AB"); + cic.put(905, "ActiveBlu Corporation"); + cic.put(906, "Kohler Mira Limited"); + cic.put(907, "Noke"); + cic.put(908, "Appion Inc."); + cic.put(909, "Resmed Ltd"); + cic.put(910, "Crownstone B.V."); + cic.put(911, "Xiaomi Inc."); + cic.put(912, "INFOTECH s.r.o."); + cic.put(913, "Thingsquare AB"); + cic.put(914, "T&D"); + cic.put(915, "LAVAZZA S.p.A."); + cic.put(916, "Netclearance Systems, Inc."); + cic.put(917, "SDATAWAY"); + cic.put(918, "BLOKS GmbH"); + cic.put(919, "LEGO System A/S"); + cic.put(920, "Thetatronics Ltd"); + cic.put(921, "Nikon Corporation"); + cic.put(922, "NeST"); + cic.put(923, "South Silicon Valley Microelectronics"); + cic.put(924, "ALE International"); + cic.put(925, "CareView Communications, Inc."); + cic.put(926, "SchoolBoard Limited"); + cic.put(927, "Molex Corporation"); + cic.put(928, "IVT Wireless Limited"); + cic.put(929, "Alpine Labs LLC"); + cic.put(930, "Candura Instruments"); + cic.put(931, "SmartMovt Technology Co., Ltd"); + cic.put(932, "Token Zero Ltd"); + cic.put(933, "ACE CAD Enterprise Co., Ltd. (ACECAD)"); + cic.put(934, "Medela, Inc"); + cic.put(935, "AeroScout"); + cic.put(936, "Esrille Inc."); + cic.put(937, "THINKERLY SRL"); + cic.put(938, "Exon Sp. z o.o."); + cic.put(939, "Meizu Technology Co., Ltd."); + cic.put(940, "Smablo LTD"); + cic.put(941, "XiQ"); + cic.put(942, "Allswell Inc."); + cic.put(943, "Comm-N-Sense Corp DBA Verigo"); + cic.put(944, "VIBRADORM GmbH"); + cic.put(945, "Otodata Wireless Network Inc."); + cic.put(946, "Propagation Systems Limited"); + cic.put(947, "Midwest Instruments & Controls"); + cic.put(948, "Alpha Nodus, inc."); + cic.put(949, "petPOMM, Inc"); + cic.put(950, "Mattel"); + cic.put(951, "Airbly Inc."); + cic.put(952, "A-Safe Limited"); + cic.put(953, "FREDERIQUE CONSTANT SA"); + cic.put(954, "Maxscend Microelectronics Company Limited"); + cic.put(955, "Abbott Diabetes Care"); + cic.put(956, "ASB Bank Ltd"); + cic.put(957, "amadas"); + cic.put(958, "Applied Science, Inc."); + cic.put(959, "iLumi Solutions Inc."); + cic.put(960, "Arch Systems Inc."); + cic.put(961, "Ember Technologies, Inc."); + cic.put(962, "Snapchat Inc"); + cic.put(963, "Casambi Technologies Oy"); + cic.put(964, "Pico Technology Inc."); + cic.put(965, "St. Jude Medical, Inc."); + cic.put(966, "Intricon"); + cic.put(967, "Structural Health Systems, Inc."); + cic.put(968, "Avvel International"); + cic.put(969, "Gallagher Group"); + cic.put(970, "In2things Automation Pvt. Ltd."); + cic.put(971, "SYSDEV Srl"); + cic.put(972, "Vonkil Technologies Ltd"); + cic.put(973, "Wynd Technologies, Inc."); + cic.put(974, "CONTRINEX S.A."); + cic.put(975, "MIRA, Inc."); + cic.put(976, "Watteam Ltd"); + cic.put(977, "Density Inc."); + cic.put(978, "IOT Pot India Private Limited"); + cic.put(979, "Sigma Connectivity AB"); + cic.put(980, "PEG PEREGO SPA"); + cic.put(981, "Wyzelink Systems Inc."); + cic.put(982, "Yota Devices LTD"); + cic.put(983, "FINSECUR"); + cic.put(984, "Zen-Me Labs Ltd"); + cic.put(985, "3IWare Co., Ltd."); + cic.put(986, "EnOcean GmbH"); + cic.put(987, "Instabeat, Inc"); + cic.put(988, "Nima Labs"); + cic.put(989, "Andreas Stihl AG & Co. KG"); + cic.put(990, "Nathan Rhoades LLC"); + cic.put(991, "Grob Technologies, LLC"); + cic.put(992, "Actions (Zhuhai) Technology Co., Limited"); + cic.put(993, "SPD Development Company Ltd"); + cic.put(994, "Sensoan Oy"); + cic.put(995, "Qualcomm Life Inc"); + cic.put(996, "Chip-ing AG"); + cic.put(997, "ffly4u"); + cic.put(998, "IoT Instruments Oy"); + cic.put(999, "TRUE Fitness Technology"); + cic.put(1000, "Reiner Kartengeraete GmbH & Co. KG."); + cic.put(1001, "SHENZHEN LEMONJOY TECHNOLOGY CO., LTD."); + cic.put(1002, "Hello Inc."); + cic.put(1003, "Evollve Inc."); + cic.put(1004, "Jigowatts Inc."); + cic.put(1005, "BASIC MICRO.COM,INC."); + cic.put(1006, "CUBE TECHNOLOGIES"); + cic.put(1007, "foolography GmbH"); + cic.put(1008, "CLINK"); + cic.put(1009, "Hestan Smart Cooking Inc."); + cic.put(1010, "WindowMaster A/S"); + cic.put(1011, "Flowscape AB"); + cic.put(1012, "PAL Technologies Ltd"); + cic.put(1013, "WHERE, Inc."); + cic.put(1014, "Iton Technology Corp."); + cic.put(1015, "Owl Labs Inc."); + cic.put(1016, "Rockford Corp."); + cic.put(1017, "Becon Technologies Co.,Ltd."); + cic.put(1018, "Vyassoft Technologies Inc"); + cic.put(1019, "Nox Medical"); + cic.put(1020, "Kimberly-Clark"); + cic.put(1021, "Trimble Navigation Ltd."); + cic.put(1022, "Littelfuse"); + cic.put(1023, "Withings"); + cic.put(1024, "i-developer IT Beratung UG"); + cic.put(1025, ""); + cic.put(1026, "Sears Holdings Corporation"); + cic.put(1027, "Gantner Electronic GmbH"); + cic.put(1028, "Authomate Inc"); + cic.put(1029, "Vertex International, Inc."); + cic.put(1030, "Airtago"); + cic.put(1031, "Swiss Audio SA"); + cic.put(1032, "ToGetHome Inc."); + cic.put(1033, "AXIS"); + cic.put(1034, "Openmatics"); + cic.put(1035, "Jana Care Inc."); + cic.put(1036, "Senix Corporation"); + cic.put(1037, "NorthStar Battery Company, LLC"); + cic.put(1038, "SKF (U.K.) Limited"); + cic.put(1039, "CO-AX Technology, Inc."); + cic.put(1040, "Fender Musical Instruments"); + cic.put(1041, "Luidia Inc"); + cic.put(1042, "SEFAM"); + cic.put(1043, "Wireless Cables Inc"); + cic.put(1044, "Lightning Protection International Pty Ltd"); + cic.put(1045, "Uber Technologies Inc"); + cic.put(1046, "SODA GmbH"); + cic.put(1047, "Fatigue Science"); + cic.put(1048, "Alpine Electronics Inc."); + cic.put(1049, "Novalogy LTD"); + cic.put(1050, "Friday Labs Limited"); + cic.put(1051, "OrthoAccel Technologies"); + cic.put(1052, "WaterGuru, Inc."); + cic.put(1053, "Benning Elektrotechnik und Elektronik GmbH & Co. KG"); + cic.put(1054, "Dell Computer Corporation"); + cic.put(1055, "Kopin Corporation"); + cic.put(1056, "TecBakery GmbH"); + cic.put(1057, "Backbone Labs, Inc."); + cic.put(1058, "DELSEY SA"); + cic.put(1059, "Chargifi Limited"); + cic.put(1060, "Trainesense Ltd."); + cic.put(1061, "Unify Software and Solutions GmbH & Co. KG"); + cic.put(1062, "Husqvarna AB"); + cic.put(1063, "Focus fleet and fuel management inc"); + cic.put(1064, "SmallLoop, LLC"); + cic.put(1065, "Prolon Inc."); + cic.put(1066, "BD Medical"); + cic.put(1067, "iMicroMed Incorporated"); + cic.put(1068, "Ticto N.V."); + cic.put(1069, "Meshtech AS"); + cic.put(1070, "MemCachier Inc."); + cic.put(1071, "Danfoss A/S"); + cic.put(1072, "SnapStyk Inc."); + cic.put(1073, "Amway Corporation"); + cic.put(1074, "Silk Labs, Inc."); + cic.put(1075, "Pillsy Inc."); + cic.put(1076, "Hatch Baby, Inc."); + cic.put(1077, "Blocks Wearables Ltd."); + cic.put(1078, "Drayson Technologies (Europe) Limited"); + cic.put(1079, "eBest IOT Inc."); + cic.put(1080, "Helvar Ltd"); + cic.put(1081, "Radiance Technologies"); + cic.put(1082, "Nuheara Limited"); + cic.put(1083, "Appside co., ltd."); + cic.put(1084, "DeLaval"); + cic.put(1085, "Coiler Corporation"); + cic.put(1086, "Thermomedics, Inc."); + cic.put(1087, "Tentacle Sync GmbH"); + cic.put(1088, "Valencell, Inc."); + cic.put(1089, "iProtoXi Oy"); + cic.put(1090, "SECOM CO., LTD."); + cic.put(1091, "Tucker International LLC"); + cic.put(1092, "Metanate Limited"); + cic.put(1093, "Kobian Canada Inc."); + cic.put(1094, "NETGEAR, Inc."); + cic.put(1095, "Fabtronics Australia Pty Ltd"); + cic.put(1096, "Grand Centrix GmbH"); + cic.put(1097, "1UP USA.com llc"); + cic.put(1098, "SHIMANO INC."); + cic.put(1099, "Nain Inc."); + cic.put(1100, "LifeStyle Lock, LLC"); + cic.put(1101, "VEGA Grieshaber KG"); + cic.put(1102, "Xtrava Inc."); + cic.put(1103, "TTS Tooltechnic Systems AG & Co. KG"); + cic.put(1104, "Teenage Engineering AB"); + cic.put(1105, "Tunstall Nordic AB"); + cic.put(1106, "Svep Design Center AB"); + cic.put(1107, "GreenPeak Technologies BV"); + cic.put(1108, "Sphinx Electronics GmbH & Co KG"); + cic.put(1109, "Atomation"); + cic.put(1110, "Nemik Consulting Inc"); + cic.put(1111, "RF INNOVATION"); + cic.put(1112, "Mini Solution Co., Ltd."); + cic.put(1113, "Lumenetix, Inc"); + cic.put(1114, "2048450 Ontario Inc"); + cic.put(1115, "SPACEEK LTD"); + cic.put(1116, "Delta T Corporation"); + cic.put(1117, "Boston Scientific Corporation"); + cic.put(1118, "Nuviz, Inc."); + cic.put(1119, "Real Time Automation, Inc."); + cic.put(1120, "Kolibree"); + cic.put(1121, "vhf elektronik GmbH"); + cic.put(1122, "Bonsai Systems GmbH"); + cic.put(1123, "Fathom Systems Inc."); + cic.put(1124, "Bellman & Symfon"); + cic.put(1125, "International Forte Group LLC"); + cic.put(1126, "CycleLabs Solutions inc."); + cic.put(1127, "Codenex Oy"); + cic.put(1128, "Kynesim Ltd"); + cic.put(1129, "Palago AB"); + cic.put(1130, "INSIGMA INC."); + cic.put(1131, "PMD Solutions"); + cic.put(1132, "Qingdao Realtime Technology Co., Ltd."); + cic.put(1133, "BEGA Gantenbrink-Leuchten KG"); + cic.put(1134, "Pambor Ltd."); + cic.put(1135, "Develco Products A/S"); + cic.put(1136, "iDesign s.r.l."); + cic.put(1137, "TiVo Corp"); + cic.put(1138, "Control-J Pty Ltd"); + cic.put(1139, "Steelcase, Inc."); + cic.put(1140, "iApartment co., ltd."); + cic.put(1141, "Icom inc."); + cic.put(1142, "Oxstren Wearable Technologies Private Limited"); + cic.put(1143, "Blue Spark Technologies"); + cic.put(1144, "FarSite Communications Limited"); + cic.put(1145, "mywerk system GmbH"); + cic.put(1146, "Sinosun Technology Co., Ltd."); + cic.put(1147, "MIYOSHI ELECTRONICS CORPORATION"); + cic.put(1148, "POWERMAT LTD"); + cic.put(1149, "Occly LLC"); + cic.put(1150, "OurHub Dev IvS"); + cic.put(1151, "Pro-Mark, Inc."); + cic.put(1152, "Dynometrics Inc."); + cic.put(1153, "Quintrax Limited"); + cic.put(1154, "POS Tuning Udo Vosshenrich GmbH & Co. KG"); + cic.put(1155, "Multi Care Systems B.V."); + cic.put(1156, "Revol Technologies Inc"); + cic.put(1157, "SKIDATA AG"); + cic.put(1158, "DEV TECNOLOGIA INDUSTRIA, COMERCIO E MANUTENCAO DE EQUIPAMENTOS LTDA. - ME"); + cic.put(1159, "Centrica Connected Home"); + cic.put(1160, "Automotive Data Solutions Inc"); + cic.put(1161, "Igarashi Engineering"); + cic.put(1162, "Taelek Oy"); + cic.put(1163, "CP Electronics Limited"); + cic.put(1164, "Vectronix AG"); + cic.put(1165, "S-Labs Sp. z o.o."); + cic.put(1166, "Companion Medical, Inc."); + cic.put(1167, "BlueKitchen GmbH"); + cic.put(1168, "Matting AB"); + cic.put(1169, "SOREX - Wireless Solutions GmbH"); + cic.put(1170, "ADC Technology, Inc."); + cic.put(1171, "Lynxemi Pte Ltd"); + cic.put(1172, "SENNHEISER electronic GmbH & Co. KG"); + cic.put(1173, "LMT Mercer Group, Inc"); + cic.put(1174, "Polymorphic Labs LLC"); + cic.put(1175, "Cochlear Limited"); + cic.put(1176, "METER Group, Inc. USA"); + cic.put(1177, "Ruuvi Innovations Ltd."); + cic.put(1178, "Situne AS"); + cic.put(1179, "nVisti, LLC"); + cic.put(1180, "DyOcean"); + cic.put(1181, "Uhlmann & Zacher GmbH"); + cic.put(1182, "AND!XOR LLC"); + cic.put(1183, "tictote AB"); + cic.put(1184, "Vypin, LLC"); + cic.put(1185, "PNI Sensor Corporation"); + cic.put(1186, "ovrEngineered, LLC"); + cic.put(1187, "GT-tronics HK Ltd"); + cic.put(1188, "Herbert Waldmann GmbH & Co. KG"); + cic.put(1189, "Guangzhou FiiO Electronics Technology Co.,Ltd"); + cic.put(1190, "Vinetech Co., Ltd"); + cic.put(1191, "Dallas Logic Corporation"); + cic.put(1192, "BioTex, Inc."); + cic.put(1193, "DISCOVERY SOUND TECHNOLOGY, LLC"); + cic.put(1194, "LINKIO SAS"); + cic.put(1195, "Harbortronics, Inc."); + cic.put(1196, "Undagrid B.V."); + cic.put(1197, "Shure Inc"); + cic.put(1198, "ERM Electronic Systems LTD"); + cic.put(1199, "BIOROWER Handelsagentur GmbH"); + cic.put(1200, "Weba Sport und Med. Artikel GmbH"); + cic.put(1201, "Kartographers Technologies Pvt. Ltd."); + cic.put(1202, "The Shadow on the Moon"); + cic.put(1203, "mobike (Hong Kong) Limited"); + cic.put(1204, "Inuheat Group AB"); + cic.put(1205, "Swiftronix AB"); + cic.put(1206, "Diagnoptics Technologies"); + cic.put(1207, "Analog Devices, Inc."); + cic.put(1208, "Soraa Inc."); + cic.put(1209, "CSR Building Products Limited"); + cic.put(1210, "Crestron Electronics, Inc."); + cic.put(1211, "Neatebox Ltd"); + cic.put(1212, "Draegerwerk AG & Co. KGaA"); + cic.put(1213, "AlbynMedical"); + cic.put(1214, "Averos FZCO"); + cic.put(1215, "VIT Initiative, LLC"); + cic.put(1216, "Statsports International"); + cic.put(1217, "Sospitas, s.r.o."); + cic.put(1218, "Dmet Products Corp."); + cic.put(1219, "Mantracourt Electronics Limited"); + cic.put(1220, "TeAM Hutchins AB"); + cic.put(1221, "Seibert Williams Glass, LLC"); + cic.put(1222, "Insta GmbH"); + cic.put(1223, "Svantek Sp. z o.o."); + cic.put(1224, "Shanghai Flyco Electrical Appliance Co., Ltd."); + cic.put(1225, "Thornwave Labs Inc"); + cic.put(1226, "Steiner-Optik GmbH"); + cic.put(1227, "Novo Nordisk A/S"); + cic.put(1228, "Enflux Inc."); + cic.put(1229, "Safetech Products LLC"); + cic.put(1230, "GOOOLED S.R.L."); + cic.put(1231, "DOM Sicherheitstechnik GmbH & Co. KG"); + cic.put(1232, "Olympus Corporation"); + cic.put(1233, "KTS GmbH"); + cic.put(1234, "Anloq Technologies Inc."); + cic.put(1235, "Queercon, Inc"); + cic.put(1236, "5th Element Ltd"); + cic.put(1237, "Gooee Limited"); + cic.put(1238, "LUGLOC LLC"); + cic.put(1239, "Blincam, Inc."); + cic.put(1240, "FUJIFILM Corporation"); + cic.put(1241, "RandMcNally"); + cic.put(1242, "Franceschi Marina snc"); + cic.put(1243, "Engineered Audio, LLC."); + cic.put(1244, "IOTTIVE (OPC) PRIVATE LIMITED"); + cic.put(1245, "4MOD Technology"); + cic.put(1246, "Lutron Electronics Co., Inc."); + cic.put(1247, "Emerson"); + cic.put(1248, "Guardtec, Inc."); + cic.put(1249, "REACTEC LIMITED"); + cic.put(1250, "EllieGrid"); + cic.put(1251, "Under Armour"); + cic.put(1252, "Woodenshark"); + cic.put(1253, "Avack Oy"); + cic.put(1254, "Smart Solution Technology, Inc."); + cic.put(1255, "REHABTRONICS INC."); + cic.put(1256, "STABILO International"); + cic.put(1257, "Busch Jaeger Elektro GmbH"); + cic.put(1258, "Pacific Bioscience Laboratories, Inc"); + cic.put(1259, "Bird Home Automation GmbH"); + cic.put(1260, "Motorola Solutions"); + cic.put(1261, "R9 Technology, Inc."); + cic.put(1262, "Auxivia"); + cic.put(1263, "DaisyWorks, Inc"); + cic.put(1264, "Kosi Limited"); + cic.put(1265, "Theben AG"); + cic.put(1266, "InDreamer Techsol Private Limited"); + cic.put(1267, "Cerevast Medical"); + cic.put(1268, "ZanCompute Inc."); + cic.put(1269, "Pirelli Tyre S.P.A."); + cic.put(1270, "McLear Limited"); + cic.put(1271, "Shenzhen Huiding Technology Co.,Ltd."); + cic.put(1272, "Convergence Systems Limited"); + cic.put(1273, "Interactio"); + cic.put(1274, "Androtec GmbH"); + cic.put(1275, "Benchmark Drives GmbH & Co. KG"); + cic.put(1276, "SwingLync L. L. C."); + cic.put(1277, "Tapkey GmbH"); + cic.put(1278, "Woosim Systems Inc."); + cic.put(1279, "Microsemi Corporation"); + cic.put(1280, "Wiliot LTD."); + cic.put(1281, "Polaris IND"); + cic.put(1282, "Specifi-Kali LLC"); + cic.put(1283, "Locoroll, Inc"); + cic.put(1284, "PHYPLUS Inc"); + cic.put(1285, "Inplay Technologies LLC"); + cic.put(1286, "Hager"); + cic.put(1287, "Yellowcog"); + cic.put(1288, "Axes System sp. z o. o."); + cic.put(1289, "myLIFTER Inc."); + cic.put(1290, "Shake-on B.V."); + cic.put(1291, "Vibrissa Inc."); + cic.put(1292, "OSRAM GmbH"); + cic.put(1293, "TRSystems GmbH"); + cic.put(1294, "Yichip Microelectronics (Hangzhou) Co.,Ltd."); + cic.put(1295, "Foundation Engineering LLC"); + cic.put(1296, "UNI-ELECTRONICS, INC."); + cic.put(1297, "Brookfield Equinox LLC"); + cic.put(1298, "Soprod SA"); + cic.put(1299, "9974091 Canada Inc."); + cic.put(1300, "FIBRO GmbH"); + cic.put(1301, "RB Controls Co., Ltd."); + cic.put(1302, "Footmarks"); + cic.put(1303, "Amcore AB"); + cic.put(1304, "MAMORIO.inc"); + cic.put(1305, "Tyto Life LLC"); + cic.put(1306, "Leica Camera AG"); + cic.put(1307, "Angee Technologies Ltd."); + cic.put(1308, "EDPS"); + cic.put(1309, "OFF Line Co., Ltd."); + cic.put(1310, "Detect Blue Limited"); + cic.put(1311, "Setec Pty Ltd"); + cic.put(1312, "Target Corporation"); + cic.put(1313, "IAI Corporation"); + cic.put(1314, "NS Tech, Inc."); + cic.put(1315, "MTG Co., Ltd."); + cic.put(1316, "Hangzhou iMagic Technology Co., Ltd"); + cic.put(1317, "HONGKONG NANO IC TECHNOLOGIES CO., LIMITED"); + cic.put(1318, "Honeywell International Inc."); + cic.put(1319, "Albrecht JUNG"); + cic.put(1320, "Lunera Lighting Inc."); + cic.put(1321, "Lumen UAB"); + cic.put(1322, "Keynes Controls Ltd"); + cic.put(1323, "Novartis AG"); + cic.put(1324, "Geosatis SA"); + cic.put(1325, "EXFO, Inc."); + cic.put(1326, "LEDVANCE GmbH"); + cic.put(1327, "Center ID Corp."); + cic.put(1328, "Adolene, Inc."); + cic.put(1329, "D&M Holdings Inc."); + cic.put(1330, "CRESCO Wireless, Inc."); + cic.put(1331, "Nura Operations Pty Ltd"); + cic.put(1332, "Frontiergadget, Inc."); + cic.put(1333, "Smart Component Technologies Limited"); + cic.put(1334, "ZTR Control Systems LLC"); + cic.put(1335, "MetaLogics Corporation"); + cic.put(1336, "Medela AG"); + cic.put(1337, "OPPLE Lighting Co., Ltd"); + cic.put(1338, "Savitech Corp.,"); + cic.put(1339, "prodigy"); + cic.put(1340, "Screenovate Technologies Ltd"); + cic.put(1341, "TESA SA"); + cic.put(1342, "CLIM8 LIMITED"); + cic.put(1343, "Silergy Corp"); + cic.put(1344, "SilverPlus, Inc"); + cic.put(1345, "Sharknet srl"); + cic.put(1346, "Mist Systems, Inc."); + cic.put(1347, "MIWA LOCK CO.,Ltd"); + cic.put(1348, "OrthoSensor, Inc."); + cic.put(1349, "Candy Hoover Group s.r.l"); + cic.put(1350, "Apexar Technologies S.A."); + cic.put(1351, "LOGICDATA d.o.o."); + cic.put(1352, "Knick Elektronische Messgeraete GmbH & Co. KG"); + cic.put(1353, "Smart Technologies and Investment Limited"); + cic.put(1354, "Linough Inc."); + cic.put(1355, "Advanced Electronic Designs, Inc."); + cic.put(1356, "Carefree Scott Fetzer Co Inc"); + cic.put(1357, "Sensome"); + cic.put(1358, "FORTRONIK storitve d.o.o."); + cic.put(1359, "Sinnoz"); + cic.put(1360, "Versa Networks, Inc."); + cic.put(1361, "Sylero"); + cic.put(1362, "Avempace SARL"); + cic.put(1363, "Nintendo Co., Ltd."); + cic.put(1364, "National Instruments"); + cic.put(1365, "KROHNE Messtechnik GmbH"); + cic.put(1366, "Otodynamics Ltd"); + cic.put(1367, "Arwin Technology Limited"); + cic.put(1368, "benegear, inc."); + cic.put(1369, "Newcon Optik"); + cic.put(1370, "CANDY HOUSE, Inc."); + cic.put(1371, "FRANKLIN TECHNOLOGY INC"); + cic.put(1372, "Lely"); + cic.put(1373, "Valve Corporation"); + cic.put(1374, "Hekatron Vertriebs GmbH"); + cic.put(1375, "PROTECH S.A.S. DI GIRARDI ANDREA & C."); + cic.put(1376, "Sarita CareTech IVS"); + cic.put(1377, "Finder S.p.A."); + cic.put(1378, "Thalmic Labs Inc."); + cic.put(1379, "Steinel Vertrieb GmbH"); + cic.put(1380, "Beghelli Spa"); + cic.put(1381, "Beijing Smartspace Technologies Inc."); + cic.put(1382, "CORE TRANSPORT TECHNOLOGIES NZ LIMITED"); + cic.put(1383, "Xiamen Everesports Goods Co., Ltd"); + cic.put(1384, "Bodyport Inc."); + cic.put(1385, "Audionics System, INC."); + cic.put(1386, "Flipnavi Co.,Ltd."); + cic.put(1387, "Rion Co., Ltd."); + cic.put(1388, "Long Range Systems, LLC"); + cic.put(1389, "Redmond Industrial Group LLC"); + cic.put(1390, "VIZPIN INC."); + cic.put(1391, "BikeFinder AS"); + cic.put(1392, "Consumer Sleep Solutions LLC"); + cic.put(1393, "PSIKICK, INC."); + cic.put(1394, "AntTail.com"); + cic.put(1395, "Lighting Science Group Corp."); + cic.put(1396, "AFFORDABLE ELECTRONICS INC"); + cic.put(1397, "Integral Memroy Plc"); + cic.put(1398, "Globalstar, Inc."); + cic.put(1399, "True Wearables, Inc."); + cic.put(1400, "Wellington Drive Technologies Ltd"); + cic.put(1401, "Ensemble Tech Private Limited"); + cic.put(1402, "OMNI Remotes"); + cic.put(1403, "Duracell U.S. Operations Inc."); + cic.put(1404, "Toor Technologies LLC"); + cic.put(1405, "Instinct Performance"); + cic.put(1406, "Beco, Inc"); + cic.put(1407, "Scuf Gaming International, LLC"); + cic.put(1408, "ARANZ Medical Limited"); + cic.put(1409, "LYS TECHNOLOGIES LTD"); + cic.put(1410, "Breakwall Analytics, LLC"); + cic.put(1411, "Code Blue Communications"); + cic.put(1412, "Gira Giersiepen GmbH & Co. KG"); + cic.put(1413, "Hearing Lab Technology"); + cic.put(1414, "LEGRAND"); + cic.put(1415, "Derichs GmbH"); + cic.put(1416, "ALT-TEKNIK LLC"); + cic.put(1417, "Star Technologies"); + } + + /** + * Returns the company name as a String + * + * @param id the Bluetooth company identifier + * @return The company name + */ + public static @Nullable String get(@Nullable Integer id) { + if (id != null) { + return cic.get(id); + } else { + return null; + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompletionStatus.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompletionStatus.java new file mode 100644 index 00000000000..35ef1cf9d6d --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothCompletionStatus.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +/** + * An enumeration of transaction completion status values + * + * @author Chris Jackson - Initial Implementation + * + */ +public enum BluetoothCompletionStatus { + SUCCESS, + ERROR +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDescriptor.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDescriptor.java new file mode 100644 index 00000000000..ba03fb460c1 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDescriptor.java @@ -0,0 +1,140 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * The {@link BluetoothDescriptor} class defines the Bluetooth descriptor. + *

+ * Descriptors are defined attributes that describe a characteristic value. + *

+ * https://www.bluetooth.com/specifications/gatt/descriptors + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - added constructor and fixed setValue method + */ +public class BluetoothDescriptor { + + protected final BluetoothCharacteristic characteristic; + protected final UUID uuid; + protected byte[] value; + + /** + * The main constructor + * + * @param characteristic the characteristic that this class describes + * @param uuid the uuid of the descriptor + */ + public BluetoothDescriptor(BluetoothCharacteristic characteristic, UUID uuid) { + this.characteristic = characteristic; + this.uuid = uuid; + } + + /** + * Returns the characteristic this descriptor belongs to. + * + * @return + */ + BluetoothCharacteristic getCharacteristic() { + return characteristic; + + } + + /** + * Returns the permissions for this descriptor. + * + * @return the permissions + */ + public int getPermissions() { + return 0; + } + + /** + * Returns the UUID of this descriptor. + * + * @return the UUID + */ + public UUID getUuid() { + return uuid; + + } + + /** + * Returns the stored value for this descriptor. It doesn't read remote data. + * + * @return the value of the descriptor + */ + public byte[] getValue() { + return value; + } + + /** + * Sets the stored value for this descriptor. It doesn't update remote data. + * + * @param value the value for this descriptor instance + */ + public void setValue(byte[] value) { + this.value = value; + } + + public GattDescriptor getDescriptor() { + return GattDescriptor.getDescriptor(uuid); + } + + public enum GattDescriptor { + // Descriptors + CHARACTERISTIC_EXTENDED_PROPERTIES(0x2900), + CHARACTERISTIC_USER_DESCRIPTION(0x2901), + CLIENT_CHARACTERISTIC_CONFIGURATION(0x2902), + SERVER_CHARACTERISTIC_CONFIGURATION(0x2903), + CHARACTERISTIC_PRESENTATION_FORMAT(0x2904), + CHARACTERISTIC_AGGREGATE_FORMAT(0x2905), + VALID_RANGE(0x2906), + EXTERNAL_REPORT_REFERENCE(0x2907), + REPORT_REFERENCE(0x2908), + NUMBER_OF_DIGITALS(0x2909), + TRIGGER_SETTING(0x290A); + + private static Map uuidToServiceMapping; + + private final UUID uuid; + + private GattDescriptor(long key) { + this.uuid = new UUID((key << 32) | 0x1000, BluetoothBindingConstants.BLUETOOTH_BASE_UUID); + } + + private static void initMapping() { + uuidToServiceMapping = new HashMap(); + for (GattDescriptor s : values()) { + uuidToServiceMapping.put(s.uuid, s); + } + } + + public static GattDescriptor getDescriptor(UUID uuid) { + if (uuidToServiceMapping == null) { + initMapping(); + } + return uuidToServiceMapping.get(uuid); + } + + /** + * @return the key + */ + public UUID getUUID() { + return uuid; + } + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDevice.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDevice.java new file mode 100644 index 00000000000..c29e39878e3 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDevice.java @@ -0,0 +1,552 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link BluetoothDevice} class provides a base implementation of a Bluetooth Low Energy device + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Refactored class to use Integer instead of int, fixed bugs, diverse improvements + */ +public abstract class BluetoothDevice { + + private final Logger logger = LoggerFactory.getLogger(BluetoothDevice.class); + + /** + * Enumeration of Bluetooth connection states + * + */ + public enum ConnectionState { + /** + * Device is still being discovered and is not available for use. + */ + DISCOVERING, + /** + * Device has been discovered. This is used for the initial notification that the device is available. + */ + DISCOVERED, + /** + * Device is disconnected. + */ + DISCONNECTED, + /** + * A connection is in progress. + */ + CONNECTING, + /** + * The device is connected. + */ + CONNECTED, + /** + * A disconnection is in progress. + */ + DISCONNECTING + } + + protected enum BluetoothEventType { + CONNECTION_STATE, + SCAN_RECORD, + CHARACTERISTIC_READ_COMPLETE, + CHARACTERISTIC_WRITE_COMPLETE, + CHARACTERISTIC_UPDATED, + DESCRIPTOR_UPDATED, + SERVICES_DISCOVERED + } + + /** + * Current connection state + */ + protected ConnectionState connectionState = ConnectionState.DISCOVERING; + + /** + * The adapter the device is accessed through + */ + protected final BluetoothAdapter adapter; + + /** + * Devices Bluetooth address + */ + protected final BluetoothAddress address; + + /** + * Manufacturer id + */ + protected Integer manufacturer = null; + + /** + * Device name. + *

+ * Uses the devices long name if known, otherwise the short name if known + */ + protected String name; + + /** + * List of supported services + */ + protected final Map supportedServices = new HashMap(); + + /** + * Last known RSSI + */ + protected Integer rssi = null; + + /** + * Last reported transmitter power + */ + protected Integer txPower = null; + + /** + * The event listeners will be notified of device updates + */ + private final List eventListeners = new CopyOnWriteArrayList(); + + /** + * Construct a Bluetooth device taking the Bluetooth address + * + * @param adapter + * + * @param sender + */ + public BluetoothDevice(BluetoothAdapter adapter, BluetoothAddress address) { + this.address = address; + this.adapter = adapter; + } + + /** + * Returns the the name of the Bluetooth device. + * + * @return The devices name + */ + public String getName() { + return name; + } + + /** + * Returns the physical address of the device. + * + * @return The physical address of the device + */ + public BluetoothAddress getAddress() { + return address; + } + + /** + * Returns the adapter through which the device is accessed + * + * @return The adapter through which the device is accessed + */ + public BluetoothAdapter getAdapter() { + return adapter; + } + + /** + * Sets the manufacturer id for the device + * + * @param manufacturer the manufacturer id + */ + public void setManufacturerId(int manufacturer) { + this.manufacturer = manufacturer; + } + + /** + * Returns the manufacturer ID of the device + * + * @return an integer with manufacturer ID of the device, or null if not known + */ + public Integer getManufacturerId() { + return manufacturer; + } + + /** + * Returns a {@link BluetoothService} if the requested service is supported + * + * @return the {@link BluetoothService} or null if the service is not supported. + */ + public BluetoothService getServices(UUID uuid) { + return supportedServices.get(uuid); + } + + /** + * Returns a list of supported service UUIDs + * + * @return list of supported {@link BluetoothService}s. + */ + public Collection getServices() { + return supportedServices.values(); + } + + /** + * Sets the device transmit power + * + * @param power the current transmitter power in dBm + */ + public void setTxPower(int txPower) { + this.txPower = txPower; + } + + /** + * Returns the last Transmit Power value or null if no transmit power has been received + * + * @return the last reported transmitter power value in dBm + */ + public Integer getTxPower() { + return txPower; + } + + /** + * Sets the current Receive Signal Strength Indicator (RSSI) value + * + * @param rssi the current RSSI value in dBm + * @return true if the RSSI has changed, false if it was the same as previous + */ + public boolean setRssi(int rssi) { + boolean changed = (this.rssi == null || this.rssi != rssi); + this.rssi = rssi; + + return changed; + } + + /** + * Returns the last Receive Signal Strength Indicator (RSSI) value or null if no RSSI has been received + * + * @return the last RSSI value in dBm + */ + public Integer getRssi() { + return rssi; + } + + /** + * Set the name of the device + * + * @param name a {@link String} defining the device name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Check if the device supports the specified service + * + * @param uuid the service {@link UUID} + * @return true if the service is supported + */ + public boolean supportsService(UUID uuid) { + return supportedServices.containsKey(uuid); + } + + /** + * Get the current connection state for this device + * + * @return the current {@link ConnectionState} + */ + public ConnectionState getConnectionState() { + return connectionState; + } + + /** + * Connects to a device. This is an asynchronous method. Once the connection state is updated, the + * {@link BluetoothDeviceListener.onConnectionState} method will be called with the connection state. + *

+ * If the device is already connected, this will return false. + * + * @return true if the connection process is started successfully + */ + public boolean connect() { + return false; + } + + /** + * Disconnects from a device. Once the connection state is updated, the + * {@link BluetoothDeviceListener.onConnectionState} + * method will be called with the connection state. + *

+ * If the device is not currently connected, this will return false. + * + * @return true if the disconnection process is started successfully + */ + public boolean disconnect() { + return false; + } + + /** + * Starts a discovery on a device. This will iterate through all services and characteristics to build up a view of + * the device. + *

+ * This method should be called before attempting to read or write characteristics. + * + * @return true if the discovery process is started successfully + */ + public boolean discoverServices() { + return false; + } + + /** + * Gets a Bluetooth characteristic if it is known. + *

+ * Note that this method will not search for a characteristic in the remote device if it is not known. + * You must have previously connected to the device so that the device services and characteristics can + * be retrieved. + * + * @param uuid the {@link UUID} of the characteristic to return + * @return the {@link BluetoothCharacteristic} or null if the characteristic is not found in the device + */ + public BluetoothCharacteristic getCharacteristic(UUID uuid) { + for (BluetoothService service : supportedServices.values()) { + if (service.providesCharacteristic(uuid)) { + return service.getCharacteristic(uuid); + } + } + return null; + } + + /** + * Reads a characteristic. Only a single read or write operation can be requested at once. Attempting to perform an + * operation when one is already in progress will result in subsequent calls returning false. + *

+ * This is an asynchronous method. Once the read is complete + * {@link BluetoothDeviceListener.onCharacteristicReadComplete} + * method will be called with the completion state. + *

+ * Note that {@link BluetoothDeviceListener.onCharacteristicUpdate} will be called when the read value is received. + * + * @param characteristic the {@link BluetoothCharacteristic} to read. + * @return true if the characteristic read is started successfully + */ + public boolean readCharacteristic(BluetoothCharacteristic characteristic) { + return false; + } + + /** + * Writes a characteristic. Only a single read or write operation can be requested at once. Attempting to perform an + * operation when one is already in progress will result in subsequent calls returning false. + *

+ * This is an asynchronous method. Once the write is complete + * {@link BluetoothDeviceListener.onCharacteristicWriteComplete} method will be called with the completion state. + * + * @param characteristic the {@link BluetoothCharacteristic} to read. + * @return true if the characteristic write is started successfully + */ + public boolean writeCharacteristic(BluetoothCharacteristic characteristic) { + return false; + } + + /** + * Enables notifications for a characteristic. Only a single read or write operation can be requested at once. + * Attempting to perform an operation when one is already in progress will result in subsequent calls returning + * false. + *

+ * Notifications result in CHARACTERISTIC_UPDATED events to the listeners. + * + * @param characteristic the {@link BluetoothCharacteristic} to receive notifications for. + * @return true if the characteristic notification is started successfully + */ + public boolean enableNotifications(BluetoothCharacteristic characteristic) { + return false; + } + + /** + * Disables notifications for a characteristic. Only a single read or write operation can be requested at once. + * Attempting to perform an operation when one is already in progress will result in subsequent calls returning + * false. + * + * @param characteristic the {@link BluetoothCharacteristic} to disable notifications for. + * @return true if the characteristic notification is stopped successfully + */ + public boolean disableNotifications(BluetoothCharacteristic characteristic) { + return false; + } + + /** + * Enables notifications for a descriptor. Only a single read or write operation can be requested at once. + * Attempting to perform an operation when one is already in progress will result in subsequent calls returning + * false. + *

+ * Notifications result in DESCRIPTOR_UPDATED events to the listeners. + * + * @param descriptor the {@link BluetoothDescriptor} to receive notifications for. + * @return true if the descriptor notification is started successfully + */ + public boolean enableNotifications(BluetoothDescriptor descriptor) { + return false; + } + + /** + * Disables notifications for a descriptor. Only a single read or write operation can be requested at once. + * Attempting to perform an operation when one is already in progress will result in subsequent calls returning + * false. + * + * @param descriptor the {@link BluetoothDescriptor} to disable notifications for. + * @return true if the descriptor notification is stopped successfully + */ + public boolean disableNotifications(BluetoothDescriptor descriptor) { + return false; + } + + /** + * Adds a service to the device. + * + * @param service the new {@link BluetoothService} to add + * @return true if the service was added or false if the service was already supported + */ + protected boolean addService(BluetoothService service) { + if (supportedServices.containsKey(service.getUuid())) { + return false; + } + logger.trace("Adding new service to device {}: {}", address, service); + supportedServices.put(service.getUuid(), service); + return true; + } + + /** + * Adds a list of services to the device + * + * @param uuids + */ + protected void addServices(List uuids) { + for (UUID uuid : uuids) { + // Check if we already know about this service + if (supportsService(uuid)) { + continue; + } + + // Create a new service and add it to the device + addService(new BluetoothService(uuid)); + } + } + + /** + * Gets a service based on the handle. + * This will return a service if the handle falls within the start and end handles for the service. + * + * @param handle the handle for the service + * @return the {@link BluetoothService} or null if the service was not found + */ + protected BluetoothService getServiceByHandle(int handle) { + synchronized (supportedServices) { + for (BluetoothService service : supportedServices.values()) { + if (service.getHandleStart() <= handle && service.getHandleEnd() >= handle) { + return service; + } + } + } + return null; + } + + /** + * Gets a characteristic based on the handle. + * + * @param handle the handle for the characteristic + * @return the {@link BluetoothCharacteristic} or null if the characteristic was not found + */ + protected BluetoothCharacteristic getCharacteristicByHandle(int handle) { + BluetoothService service = getServiceByHandle(handle); + if (service != null) { + return service.getCharacteristicByHandle(handle); + } + + return null; + } + + /** + * Adds a device listener + * + * @param listener the {@link BluetoothDeviceListener} to add + */ + public void addListener(BluetoothDeviceListener listener) { + if (listener == null) { + return; + } + eventListeners.add(listener); + } + + /** + * Removes a device listener + * + * @param listener the {@link BluetoothDeviceListener} to remove + */ + public void removeListener(BluetoothDeviceListener listener) { + eventListeners.remove(listener); + } + + /** + * Notify the listeners of an event + * + * @param event the {@link BluetoothEventType} of this event + * @param args an array of arguments to pass to the callback + */ + protected void notifyListeners(BluetoothEventType event, Object... args) { + for (BluetoothDeviceListener listener : eventListeners) { + try { + switch (event) { + case SCAN_RECORD: + listener.onScanRecordReceived((BluetoothScanNotification) args[0]); + break; + case CONNECTION_STATE: + listener.onConnectionStateChange((BluetoothConnectionStatusNotification) args[0]); + break; + case SERVICES_DISCOVERED: + listener.onServicesDiscovered(); + break; + case CHARACTERISTIC_READ_COMPLETE: + listener.onCharacteristicReadComplete((BluetoothCharacteristic) args[0], + (BluetoothCompletionStatus) args[1]); + break; + case CHARACTERISTIC_WRITE_COMPLETE: + listener.onCharacteristicWriteComplete((BluetoothCharacteristic) args[0], + (BluetoothCompletionStatus) args[1]); + break; + case CHARACTERISTIC_UPDATED: + listener.onCharacteristicUpdate((BluetoothCharacteristic) args[0]); + break; + case DESCRIPTOR_UPDATED: + listener.onDescriptorUpdate((BluetoothDescriptor) args[0]); + break; + } + } catch (Exception e) { + logger.error("Failed to inform listener '{}': {}", listener, e.getMessage(), e); + } + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("BluetoothDevice [address="); + builder.append(address); + builder.append(", name="); + builder.append(name); + builder.append(", rssi="); + builder.append(rssi); + builder.append(", manufacturer="); + builder.append(manufacturer); + if (BluetoothCompanyIdentifiers.get(manufacturer) != null) { + builder.append(" ("); + builder.append(BluetoothCompanyIdentifiers.get(manufacturer)); + builder.append(')'); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDeviceListener.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDeviceListener.java new file mode 100644 index 00000000000..d191c38a8bf --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDeviceListener.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothScanNotification; + +/** + * The {@link BluetoothDeviceListener} class defines the a callback interface where devices are notified of updates to a + * BLE device + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Added descriptor updates + */ +@NonNullByDefault +public interface BluetoothDeviceListener { + + /** + * Called when a scan record is received for the device + * + * @param scanNotification the {@link BluetoothScanNotification} providing the scan packet information + */ + void onScanRecordReceived(BluetoothScanNotification scanNotification); + + /** + * Called when the connection status changes + * + * @param connectionNotification the {@link BluetoothConnectionStatusNotification} providing the updated connection + * information + */ + void onConnectionStateChange(BluetoothConnectionStatusNotification connectionNotification); + + /** + * Called when a devices services and characteristics have been completely read + */ + void onServicesDiscovered(); + + /** + * Called when a read request completes + * + * @param characteristic the {@link BluetoothCharacteristic} that has completed the read request + * @param status the {@link BluetoothCompletionStatus} of the read request + */ + void onCharacteristicReadComplete(BluetoothCharacteristic characteristic, BluetoothCompletionStatus status); + + /** + * Called when a write request completes + * + * @param characteristic the {@link BluetoothCharacteristic} that has completed the write request + * @param status the {@link BluetoothCompletionStatus} of the write request + */ + void onCharacteristicWriteComplete(BluetoothCharacteristic characteristic, BluetoothCompletionStatus status); + + /** + * Called when a characteristic value is received. Implementations should call this whenever a value + * is received from the BLE device even if there is no change to the value. + * + * @param characteristic the updated {@link BluetoothCharacteristic} + */ + void onCharacteristicUpdate(BluetoothCharacteristic characteristic); + + /** + * Called when a descriptor value is received. Implementations should call this whenever a value + * is received from the BLE device even if there is no change to the value. + * + * @param characteristic the updated {@link BluetoothCharacteristic} + */ + void onDescriptorUpdate(BluetoothDescriptor bluetoothDescriptor); +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDiscoveryListener.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDiscoveryListener.java new file mode 100644 index 00000000000..89abbb4c6f0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothDiscoveryListener.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +/** + * This is a listener interface that is e.g. used by {@link BluetoothAdapter}s after discovering new devices. + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +public interface BluetoothDiscoveryListener { + + /** + * Reports the discovery of a new device. + * + * @param device the newly discovered {@link BluetoothDevice} + */ + void deviceDiscovered(BluetoothDevice device); + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothService.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothService.java new file mode 100644 index 00000000000..fe1ff281fb0 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/BluetoothService.java @@ -0,0 +1,286 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The {@link BluetoothCharacteristic} class defines the BLE Service. + *

+ * Services are collections of characteristics and relationships to other services that encapsulate the behavior of part + * of a device. + *

+ * https://www.bluetooth.com/specifications/gatt/services + * + * @author Chris Jackson - Initial contribution + * @author Kai Kreuzer - Cleaned up code + */ +public class BluetoothService { + + // The service UUID + private final UUID uuid; + + /** + * The start handle for this service + */ + private final int handleStart; + + /** + * The end handle for this service + */ + private final int handleEnd; + + protected int instanceId; + + /** + * Indicates if this is a primary service (true) or secondary service (false) + */ + protected boolean primaryService; + + /** + * Map of {@link BluetoothCharacteristic}s supported in this service + */ + protected final Map supportedCharacteristics = new ConcurrentHashMap<>(); + + /** + * Constructor + * + * @param uuid the uuid of the service + */ + public BluetoothService(UUID uuid) { + this(uuid, true, 0, 0); + } + + /** + * Constructor + * + * @param uuid the uuid of the service + * @param primaryService true, if this service is a primary service + */ + public BluetoothService(UUID uuid, boolean primaryService) { + this(uuid, primaryService, 0, 0); + } + + /** + * Constructor + * + * @param uuid the uuid of the service + * @param primaryService true, if this service is a primary service + * @param handleStart id of the lowest handle + * @param handleEnd id of the highest handle + */ + public BluetoothService(UUID uuid, boolean primaryService, int handleStart, int handleEnd) { + this.uuid = uuid; + this.primaryService = primaryService; + this.handleStart = handleStart; + this.handleEnd = handleEnd; + } + + /** + * Get characteristic based on {@link UUID} + * + * @return the {@link BluetoothCharacteristic} with the requested {@link UUID} + */ + public BluetoothCharacteristic getCharacteristic(UUID uuid) { + return supportedCharacteristics.get(uuid); + } + + /** + * Get list of characteristics of the service + * + * @return the list of {@link BluetoothCharacteristic}s + */ + public List getCharacteristics() { + return new ArrayList(supportedCharacteristics.values()); + } + + /** + * Return the UUID of this service + * + * @return the {@link UUID} of the service + */ + public UUID getUuid() { + return uuid; + } + + /** + * Gets the starting handle for this service + * + * @return the start handle + */ + public int getHandleStart() { + return handleStart; + } + + /** + * Gets the end handle for this service + * + * @return the end handle + */ + public int getHandleEnd() { + return handleEnd; + } + + /** + * Get the type of this service (primary/secondary) + * + * @return true if this is a primary service + */ + public boolean isPrimary() { + return primaryService; + } + + /** + * Returns the instance ID for this service + * + * @return Instance ID of this service + */ + public int getInstanceId() { + return instanceId; + } + + /** + * Checks if the service provides a specific characteristic + * + * @return true if the characteristic is provided in this service + */ + public boolean providesCharacteristic(UUID uuid) { + return supportedCharacteristics.containsKey(uuid); + } + + /** + * Add a characteristic to this service + * + * @param characteristic The characteristics to be added + * @return true, if the characteristic was added to the service + */ + public boolean addCharacteristic(BluetoothCharacteristic characteristic) { + if (supportedCharacteristics.get(characteristic.getUuid()) != null) { + return false; + } + + supportedCharacteristics.put(characteristic.getUuid(), characteristic); + characteristic.setService(this); + return true; + } + + /** + * Gets a characteristic by the handle + * + * @param handle the handle of the characteristic to return + * @return return the {@link BluetoothCharacteristic} or null if not found + */ + public BluetoothCharacteristic getCharacteristicByHandle(int handle) { + synchronized (supportedCharacteristics) { + for (BluetoothCharacteristic characteristic : supportedCharacteristics.values()) { + if (characteristic.getHandle() == handle) { + return characteristic; + } + } + } + return null; + } + + /** + * Gets the {@link GattService} for this service. This is an enum defining the available GATT services. + * + * @return the {@link GattService} relating to this service + */ + public GattService getService() { + return GattService.getService(uuid); + } + + public enum GattService { + + // List of GATT Services + ALERT_NOTIFICATION_SERVICE(0x1811), + AUTOMATION_IO(0x1815), + BATTERY_SERVICE(0x180F), + BLOOD_PRESSURE(0x1810), + BODY_COMPOSITION(0x181B), + BOND_MANAGEMENT(0x181E), + CONTINUOUS_GLUCOSE_MONITORING(0x181F), + CURRENT_TIME_SERVICE(0x1805), + CYCLING_POWER(0x1818), + CYCLING_SPEED_AND_CADENCE(0x1816), + DEVICE_INFORMATION(0x180A), + ENVIRONMENTAL_SENSING(0x181A), + GENERIC_ACCESS(0x1800), + GENERIC_ATTRIBUTE(0x1801), + GLUCOSE(0x1808), + HEALTH_THERMOMETER(0x1809), + HEART_RATE(0x180D), + HTTP_PROXY(0x1823), + HUMAN_INTERFACE_DEVICE(0x1812), + IMMEDIATE_ALERT(0x1802), + INDOOR_POSITIONING(0x1821), + INTERNET_PROTOCOL_SUPPORT(0x1820), + LINK_LOSS(0x1803L), + LOCATION_AND_NAVIGATION(0x1819), + NEXT_DST_CHANGE_SERVICE(0x1807), + PHONE_ALERT_STATUS_SERVICE(0x180E), + REFERENCE_TIME_UPDATE_SERVICE(0x1806), + RUNNING_SPEED_AND_CADENCE(0x1814), + SCAN_PARAMETERS(0x1813), + TX_POWER(0x1804), + USER_DATA(0x181C), + WEIGHT_SCALE(0x181D); + + private static Map uuidToServiceMapping; + + private UUID uuid; + + private GattService(long key) { + this.uuid = new UUID((key << 32) | 0x1000, BluetoothBindingConstants.BLUETOOTH_BASE_UUID); + } + + private static void initMapping() { + uuidToServiceMapping = new HashMap(); + for (GattService s : values()) { + uuidToServiceMapping.put(s.uuid, s); + } + } + + public static GattService getService(UUID uuid) { + if (uuidToServiceMapping == null) { + initMapping(); + } + return uuidToServiceMapping.get(uuid); + } + + /** + * @return the key + */ + public UUID getUUID() { + return uuid; + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("BluetoothService [uuid="); + builder.append(uuid); + builder.append(", handleStart="); + builder.append(handleStart); + builder.append(", handleEnd="); + builder.append(handleEnd); + builder.append(']'); + return builder.toString(); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/ConnectedBluetoothHandler.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/ConnectedBluetoothHandler.java new file mode 100644 index 00000000000..6ded9b8b8b1 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/ConnectedBluetoothHandler.java @@ -0,0 +1,245 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth; + +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jdt.annotation.DefaultLocation; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic.GattCharacteristic; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice.ConnectionState; +import org.eclipse.smarthome.binding.bluetooth.notification.BluetoothConnectionStatusNotification; +import org.eclipse.smarthome.core.library.types.DecimalType; +import org.eclipse.smarthome.core.thing.Channel; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.DefaultSystemChannelTypeProvider; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.ThingStatusDetail; +import org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder; +import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder; +import org.eclipse.smarthome.core.thing.type.ChannelTypeUID; +import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.RefreshType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is a handler for generic Bluetooth devices in connected mode, which at the same time can be used + * as a base implementation for more specific thing handlers. + * + * @author Kai Kreuzer - Initial contribution and API + * + */ +@NonNullByDefault({ DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.ARRAY_CONTENTS, + DefaultLocation.TYPE_ARGUMENT, DefaultLocation.TYPE_BOUND, DefaultLocation.TYPE_PARAMETER }) +public class ConnectedBluetoothHandler extends BeaconBluetoothHandler { + + private final Logger logger = LoggerFactory.getLogger(ConnectedBluetoothHandler.class); + private ScheduledFuture connectionJob; + + // internal flag for the service resolution status + protected volatile Boolean resolved = false; + + protected final Set deviceCharacteristics = new CopyOnWriteArraySet<>(); + + public ConnectedBluetoothHandler(Thing thing) { + super(thing); + } + + @Override + public void initialize() { + super.initialize(); + + connectionJob = scheduler.scheduleWithFixedDelay(() -> { + if (device.getConnectionState() != ConnectionState.CONNECTED) { + device.connect(); + // we do not set the Thing status here, because we will anyhow receive a call to onConnectionStateChange + } + updateRSSI(); + }, 0, 30, TimeUnit.SECONDS); + } + + @Override + public void dispose() { + if (connectionJob != null) { + connectionJob.cancel(true); + } + if (device != null) { + scheduler.submit(() -> device.disconnect()); + } + super.dispose(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + super.handleCommand(channelUID, command); + + // Handle REFRESH + if (command == RefreshType.REFRESH) { + for (BluetoothCharacteristic characteristic : deviceCharacteristics) { + if (characteristic.getGattCharacteristic() != null + && channelUID.getId().equals(characteristic.getGattCharacteristic().name())) { + device.readCharacteristic(characteristic); + break; + } + } + } + } + + @Override + public void channelLinked(ChannelUID channelUID) { + super.channelLinked(channelUID); + } + + @Override + protected void updateStatusBasedOnRssi(boolean receivedSignal) { + // if there is no signal, we can be sure we are OFFLINE, but if there is a signal, we also have to check whether + // we are connected. + if (receivedSignal) { + if (device.getConnectionState() == ConnectionState.CONNECTED) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Device is not connected."); + } + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); + } + } + + @Override + public void onConnectionStateChange(BluetoothConnectionStatusNotification connectionNotification) { + switch (connectionNotification.getConnectionState()) { + case DISCOVERED: + // The device is now known on the Bluetooth network, so we can do something... + scheduler.submit(() -> { + synchronized (connectionJob) { + if (device.getConnectionState() != ConnectionState.CONNECTED) { + if (!device.connect()) { + logger.debug("Error connecting to device after discovery."); + } + } + } + }); + break; + case CONNECTED: + updateStatus(ThingStatus.ONLINE); + scheduler.submit(() -> { + synchronized (resolved) { + if (!resolved) { + if (!device.discoverServices()) { + logger.debug("Error while discovering services"); + } + } + } + }); + break; + case DISCONNECTED: + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); + break; + default: + break; + } + } + + @Override + public void onServicesDiscovered() { + if (!resolved) { + resolved = true; + logger.debug("Service discovery completed for '{}'", address); + for (BluetoothService service : device.getServices()) { + for (BluetoothCharacteristic characteristic : service.getCharacteristics()) { + if (characteristic.getGattCharacteristic() != null) { + if (characteristic.getGattCharacteristic().equals(GattCharacteristic.BATTERY_LEVEL)) { + activateChannel(characteristic, + DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_BATTERY_LEVEL.getUID()); + continue; + } + logger.debug("Added GATT characteristic '{}'", characteristic.getGattCharacteristic().name()); + } + } + } + } + } + + @Override + public void onCharacteristicReadComplete(BluetoothCharacteristic characteristic, BluetoothCompletionStatus status) { + if (status == BluetoothCompletionStatus.SUCCESS) { + if (GattCharacteristic.BATTERY_LEVEL.equals(characteristic.getGattCharacteristic())) { + updateBatteryLevel(characteristic); + } else { + logger.debug("Characteristic {} from {} has been read - value {}", characteristic.getUuid(), address, + characteristic.getValue()); + } + } else { + logger.debug("Characteristic {} from {} has been read - ERROR", characteristic.getUuid(), address); + return; + } + } + + @Override + public void onCharacteristicWriteComplete(BluetoothCharacteristic characteristic, + BluetoothCompletionStatus status) { + logger.debug("Wrote {} to characteristic {} of device {}: {}", characteristic.getByteValue(), + characteristic.getUuid(), address, status); + } + + @Override + public void onCharacteristicUpdate(BluetoothCharacteristic characteristic) { + if (GattCharacteristic.BATTERY_LEVEL.equals(characteristic.getGattCharacteristic())) { + updateBatteryLevel(characteristic); + } + } + + protected void updateBatteryLevel(BluetoothCharacteristic characteristic) { + // the byte has values from 0-255, which we need to map to 0-100 + Double level = characteristic.getValue()[0] / 2.55; + updateState(characteristic.getGattCharacteristic().name(), new DecimalType(level.intValue())); + } + + protected void activateChannel(@Nullable BluetoothCharacteristic characteristic, ChannelTypeUID channelTypeUID, + @Nullable String name) { + if (characteristic != null) { + String channelId = name != null ? name : characteristic.getGattCharacteristic().name(); + if (channelId == null) { + // use the type id as a fallback + channelId = channelTypeUID.getId(); + } + if (getThing().getChannel(channelId) == null) { + // the channel does not exist yet, so let's add it + ThingBuilder updatedThing = editThing(); + Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelId), "Number") + .withType(channelTypeUID).build(); + updatedThing.withChannel(channel); + updateThing(updatedThing.build()); + logger.debug("Added channel '{}' to Thing '{}'", channelId, getThing().getUID()); + } + deviceCharacteristics.add(characteristic); + device.enableNotifications(characteristic); + if (isLinked(channelId)) { + device.readCharacteristic(characteristic); + } + } else { + logger.debug("Characteristic is null - not activating any channel."); + } + } + + protected void activateChannel(@Nullable BluetoothCharacteristic characteristic, ChannelTypeUID channelTypeUID) { + activateChannel(characteristic, channelTypeUID, null); + } + +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/BluetoothDiscoveryParticipant.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/BluetoothDiscoveryParticipant.java new file mode 100644 index 00000000000..cb197b1e8ba --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/BluetoothDiscoveryParticipant.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.discovery; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.config.discovery.DiscoveryResult; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; + +/** + * A {@link BluetoothDiscoveryParticipant} that is registered as a service is picked up by the BluetoothDiscoveryService + * and can thus contribute {@link DiscoveryResult}s from Bluetooth scans. + * + * @author Kai Kreuzer - Initial contribution + * + */ +@NonNullByDefault +public interface BluetoothDiscoveryParticipant { + + /** + * Defines the list of thing types that this participant can identify + * + * @return a set of thing type UIDs for which results can be created + */ + public Set getSupportedThingTypeUIDs(); + + /** + * Creates a discovery result for a Bluetooth device + * + * @param device the Bluetooth device found on the network + * + * @return the according discovery result or null, if device is not + * supported by this participant + */ + @Nullable + public DiscoveryResult createResult(BluetoothDevice device); + + /** + * Returns the thing UID for a Bluetooth device + * + * @param device the Bluetooth device + * + * @return a thing UID or null, if the device is not supported by this participant + */ + @Nullable + public ThingUID getThingUID(BluetoothDevice device); +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java new file mode 100644 index 00000000000..b153ae78d7f --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.discovery.internal; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothAdapter; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.BluetoothCompanyIdentifiers; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice; +import org.eclipse.smarthome.binding.bluetooth.BluetoothDiscoveryListener; +import org.eclipse.smarthome.binding.bluetooth.discovery.BluetoothDiscoveryParticipant; +import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService; +import org.eclipse.smarthome.config.discovery.DiscoveryResult; +import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; +import org.eclipse.smarthome.config.discovery.DiscoveryService; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.UID; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Modified; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link BluetoothDiscoveryService} handles searching for BLE devices. + * + * @author Chris Jackson - Initial Contribution + * @author Kai Kreuzer - Introduced BluetoothAdapters and BluetoothDiscoveryParticipants + * + */ +@Component(immediate = true, service = DiscoveryService.class, configurationPid = "discovery.bluetooth") +public class BluetoothDiscoveryService extends AbstractDiscoveryService { + + private final Logger logger = LoggerFactory.getLogger(BluetoothDiscoveryService.class); + + private final static int SEARCH_TIME = 15; + + private final Set adapters = new CopyOnWriteArraySet<>(); + private final Set participants = new CopyOnWriteArraySet<>(); + private final Map registeredListeners = new ConcurrentHashMap<>(); + + private final Set supportedThingTypes = new CopyOnWriteArraySet<>(); + + public BluetoothDiscoveryService() { + super(SEARCH_TIME); + supportedThingTypes.add(BluetoothBindingConstants.THING_TYPE_BEACON); + } + + @Override + @Activate + protected void activate(Map configProperties) { + logger.debug("Activating Bluetooth discovery service"); + super.activate(configProperties); + startScan(); + } + + @Override + @Modified + protected void modified(Map configProperties) { + super.modified(configProperties); + } + + @Override + @Deactivate + public void deactivate() { + logger.debug("Deactivating Bluetooth discovery service"); + } + + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) + protected void addBluetoothAdapter(BluetoothAdapter adapter) { + this.adapters.add(adapter); + BluetoothDiscoveryListener listener = new BluetoothDiscoveryListener() { + + @Override + public void deviceDiscovered(BluetoothDevice device) { + BluetoothDiscoveryService.this.deviceDiscovered(adapter, device); + + } + }; + adapter.addDiscoveryListener(listener); + registeredListeners.put(adapter.getUID(), listener); + } + + protected void removeBluetoothAdapter(BluetoothAdapter adapter) { + this.adapters.remove(adapter); + adapter.removeDiscoveryListener(registeredListeners.remove(adapter.getUID())); + } + + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) + protected void addBluetoothDiscoveryParticipant(BluetoothDiscoveryParticipant participant) { + this.participants.add(participant); + supportedThingTypes.addAll(participant.getSupportedThingTypeUIDs()); + } + + protected void removeBluetoothDiscoveryParticipant(BluetoothDiscoveryParticipant participant) { + supportedThingTypes.removeAll(participant.getSupportedThingTypeUIDs()); + this.participants.remove(participant); + } + + @Override + public Set getSupportedThingTypes() { + return supportedThingTypes; + } + + @Override + public void startScan() { + for (BluetoothAdapter adapter : adapters) { + adapter.scanStart(); + } + } + + @Override + public void stopScan() { + for (BluetoothAdapter adapter : adapters) { + adapter.scanStop(); + } + removeOlderResults(getTimestampOfLastScan()); + } + + private void deviceDiscovered(BluetoothAdapter adapter, BluetoothDevice device) { + for (BluetoothDiscoveryParticipant participant : participants) { + try { + DiscoveryResult result = participant.createResult(device); + if (result != null) { + thingDiscovered(result); + return; + } + } catch (Exception e) { + logger.error("Participant '{}' threw an exception", participant.getClass().getName(), e); + } + } + + // We did not find a thing type for this device, so let's treat it as a generic one + String label = device.getName(); + if (label == null || label.length() == 0 || label.equals(device.getAddress().toString().replace(':', '-'))) { + label = "Bluetooth Device"; + } + + Map properties = new HashMap<>(); + properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString()); + Integer txPower = device.getTxPower(); + if (txPower != null && txPower > 0) { + properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower)); + } + String manufacturer = BluetoothCompanyIdentifiers.get(device.getManufacturerId()); + if (manufacturer != null) { + properties.put(Thing.PROPERTY_VENDOR, manufacturer); + label += " (" + manufacturer + ")"; + } else { + label += " (" + device.getAddress() + ")"; + } + + ThingUID thingUID = new ThingUID(BluetoothBindingConstants.THING_TYPE_BEACON, adapter.getUID(), + device.getAddress().toString().toLowerCase().replace(":", "")); + + // Create the discovery result and add to the inbox + DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) + .withBridge(adapter.getUID()).withLabel(label).build(); + thingDiscovered(discoveryResult); + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/internal/BluetoothHandlerFactory.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/internal/BluetoothHandlerFactory.java new file mode 100644 index 00000000000..abd18c059c2 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/internal/BluetoothHandlerFactory.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.internal; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.smarthome.binding.bluetooth.BeaconBluetoothHandler; +import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants; +import org.eclipse.smarthome.binding.bluetooth.ConnectedBluetoothHandler; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * The {@link BluetoothHandlerFactory} is responsible for creating things and thing handlers. + * + * @author Kai Kreuzer - Initial contribution and API + */ +@Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.bluetooth", configurationPolicy = ConfigurationPolicy.OPTIONAL) +public class BluetoothHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet<>(); + static { + SUPPORTED_THING_TYPES_UIDS.add(BluetoothBindingConstants.THING_TYPE_BEACON); + SUPPORTED_THING_TYPES_UIDS.add(BluetoothBindingConstants.THING_TYPE_CONNECTED); + } + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (thingTypeUID.equals(BluetoothBindingConstants.THING_TYPE_BEACON)) { + return new BeaconBluetoothHandler(thing); + } else if (thingTypeUID.equals(BluetoothBindingConstants.THING_TYPE_CONNECTED)) { + return new ConnectedBluetoothHandler(thing); + } + + return null; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothConnectionStatusNotification.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothConnectionStatusNotification.java new file mode 100644 index 00000000000..fa6968d9e6b --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothConnectionStatusNotification.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.notification; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothDevice.ConnectionState; + +/** + * The {@link BluetoothConnectionStatusNotification} provides a notification of a change in the device connection state. + * + * @author Chris Jackson - Initial contribution + */ +public class BluetoothConnectionStatusNotification extends BluetoothNotification { + private ConnectionState connectionState; + + public BluetoothConnectionStatusNotification(ConnectionState connectionState) { + this.connectionState = connectionState; + } + + /** + * Returns the connection state for this notification + * + * @return the {@link ConnectionState} + */ + public ConnectionState getConnectionState() { + return connectionState; + }; +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothNotification.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothNotification.java new file mode 100644 index 00000000000..195587e7462 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothNotification.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.notification; + +import org.eclipse.smarthome.binding.bluetooth.BluetoothAddress; + +/** + * The {@link BluetoothNotification} is the base class for Bluetooth device notifications + * + * @author Chris Jackson - Initial contribution + */ +public abstract class BluetoothNotification { + protected BluetoothAddress address; + + /** + * Returns the bluetooth address for this frame + */ + public BluetoothAddress getAddress() { + return address; + } +} diff --git a/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothScanNotification.java b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothScanNotification.java new file mode 100644 index 00000000000..d53f40dd618 --- /dev/null +++ b/extensions/binding/org.eclipse.smarthome.binding.bluetooth/src/main/java/org/eclipse/smarthome/binding/bluetooth/notification/BluetoothScanNotification.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.binding.bluetooth.notification; + +/** + * The {@link BluetoothScanNotification} provides a notification of a received scan packet + * + * @author Chris Jackson - Initial contribution + */ +public class BluetoothScanNotification extends BluetoothNotification { + /** + * The receive signal strength for this beacon packet + */ + private int rssi = Integer.MIN_VALUE; + + /** + * The raw data + */ + private byte[] data = null; + + /** + * The manufacturer specific data + */ + private byte[] manufacturerData = null; + + /** + * The beacon type + */ + private BluetoothBeaconType beaconType = BluetoothBeaconType.BEACON_UNKNOWN; + + /** + * The device name + */ + private String name = new String(); + + /** + * An enumeration of basic beacon types + */ + public enum BluetoothBeaconType { + BEACON_UNKNOWN, + BEACON_ADVERTISEMENT, + BEACON_SCANRESPONSE + } + + /** + * Sets the receive signal strength RSSI value for the scan + * + * param rssi the RSSI value for the scan packet in dBm + */ + public void setRssi(int rssi) { + this.rssi = rssi; + } + + /** + * Gets the receive signal strength RSSI value for the scan + * + * @return the RSSI value for the scan packet in dBm or Integer.MIN_VALUE if no RSSI is available. + */ + public int getRssi() { + return rssi; + } + + /** + * Sets the scan packet data + * + * @param data a byte array containing the raw packet data; + */ + public void setData(byte[] data) { + this.data = data; + } + + /** + * Gets the scan packet data + * + * @return a byte array containing the data or null if none is set + */ + public byte[] getData() { + return data; + } + + /** + * Sets the scan packet manufacturer specific data + * + * @param manufacturerData a byte array containing the manufacturer specific data + */ + public void setManufacturerData(byte[] manufacturerData) { + this.manufacturerData = manufacturerData; + } + + /** + * Gets the scan packet manufacturer specific data + * + * @return a byte array containing the manufacturer specific data or null if none is set + */ + public byte[] getManufacturerData() { + return manufacturerData; + } + + /** + * Sets the beacon type for this packet + * + * @beaconType the {@link BluetoothBeaconType} for this packet + */ + public void setBeaconType(BluetoothBeaconType beaconType) { + this.beaconType = beaconType; + } + + /** + * Gets the beacon type for this packet + * + * @return the {@link BluetoothBeaconType} for this packet + */ + public BluetoothBeaconType getBeaconType() { + return beaconType; + } + + /** + * Sets the device name + * + * @param name {@link String} containing the device name + */ + public void setDeviceName(String name) { + this.name = name; + } + + /** + * Gets the device name + * + * @return {@link String} containing the device name + */ + public String getDeviceName() { + return name; + } +} diff --git a/extensions/binding/pom.xml b/extensions/binding/pom.xml index c9045c9d8a6..0972cea6c17 100644 --- a/extensions/binding/pom.xml +++ b/extensions/binding/pom.xml @@ -18,10 +18,12 @@ org.eclipse.smarthome.binding.astro org.eclipse.smarthome.binding.astro.test + org.eclipse.smarthome.binding.bluetooth + org.eclipse.smarthome.binding.bluetooth.bluez + org.eclipse.smarthome.binding.bluetooth.test org.eclipse.smarthome.binding.digitalstrom org.eclipse.smarthome.binding.dmx org.eclipse.smarthome.binding.dmx.test - org.eclipse.smarthome.binding.hue org.eclipse.smarthome.binding.hue.test org.eclipse.smarthome.binding.fsinternetradio diff --git a/features/karaf/esh-ext/src/main/feature/feature.xml b/features/karaf/esh-ext/src/main/feature/feature.xml index 8ff55a941bf..e698964bd6d 100644 --- a/features/karaf/esh-ext/src/main/feature/feature.xml +++ b/features/karaf/esh-ext/src/main/feature/feature.xml @@ -20,6 +20,17 @@ mvn:org.eclipse.smarthome.binding/org.eclipse.smarthome.binding.astro/${project.version} + + esh-base + mvn:org.eclipse.smarthome.binding/org.eclipse.smarthome.binding.bluetooth/${project.version} + + + + esh-base + esh-binding-bluetooth + mvn:org.eclipse.smarthome.binding/org.eclipse.smarthome.binding.bluetooth.bluez/${project.version} + + esh-base esh-io-transport-mdns diff --git a/features/org.eclipse.smarthome.feature.runtime.binding/feature.xml b/features/org.eclipse.smarthome.feature.runtime.binding/feature.xml index b1ff5da14f4..967d6e758e7 100644 --- a/features/org.eclipse.smarthome.feature.runtime.binding/feature.xml +++ b/features/org.eclipse.smarthome.feature.runtime.binding/feature.xml @@ -24,7 +24,7 @@ - Copyright (c) 2014-2016 by the respective copyright holders. + Copyright (c) 2014-2018 by the respective copyright holders. @@ -38,6 +38,20 @@ version="0.0.0" unpack="false"/> + + + +