added migrated 2.x add-ons
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
32
bundles/org.openhab.binding.bluetooth.bluegiga/.classpath
Normal file
32
bundles/org.openhab.binding.bluetooth.bluegiga/.classpath
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
bundles/org.openhab.binding.bluetooth.bluegiga/.project
Normal file
23
bundles/org.openhab.binding.bluetooth.bluegiga/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openhab.binding.bluetooth.bluegiga</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
24
bundles/org.openhab.binding.bluetooth.bluegiga/NOTICE
Normal file
24
bundles/org.openhab.binding.bluetooth.bluegiga/NOTICE
Normal file
@@ -0,0 +1,24 @@
|
||||
This content is produced and maintained by the Eclipse SmartHome project.
|
||||
|
||||
* Project home: https://openhab.org/
|
||||
|
||||
== 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
|
||||
|
||||
Some code of this bundle originates from the Z-Smart Systems Bluegiga Java Library,
|
||||
the source of which can be found at -:
|
||||
|
||||
https://github.com/zsmartsystems/com.zsmartsystems.bluetooth.bluegiga
|
||||
|
||||
== 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.
|
||||
29
bundles/org.openhab.binding.bluetooth.bluegiga/README.md
Normal file
29
bundles/org.openhab.binding.bluetooth.bluegiga/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Bluetooth BlueGiga Adapter
|
||||
|
||||
This extension supports Bluetooth access via a BlueGiga (BLED112) USB dongle.
|
||||
|
||||
## Supported Things
|
||||
|
||||
It defines the following bridge type:
|
||||
|
||||
| Bridge Type ID | Description |
|
||||
|----------------|---------------------------------------------------------------------------|
|
||||
| bluegiga | A BlueGiga USB dongle using a BLED112 chip |
|
||||
|
||||
|
||||
## Discovery
|
||||
|
||||
The adapter cannot be discovered; its serial port must be manually configured.
|
||||
|
||||
## Bridge Configuration
|
||||
|
||||
The bluegiga bridge requires the configuration parameter `port`, which corresponds to the serial port the dongle is connected to.
|
||||
Additionally, the parameter `backgroundDiscovery` 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 BlueGiga adapter can be configured textually in a *.things file:
|
||||
|
||||
```
|
||||
Bridge bluetooth:bluegiga:1 [ port="/dev/ttyS0", backgroundDiscovery=false ]
|
||||
```
|
||||
25
bundles/org.openhab.binding.bluetooth.bluegiga/pom.xml
Normal file
25
bundles/org.openhab.binding.bluetooth.bluegiga/pom.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.bluetooth.bluegiga</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Bundles :: BlueGiga Bluetooth Adapter</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.bluetooth</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<features name="org.openhab.binding.bluetooth.bluegiga-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
|
||||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
|
||||
|
||||
<feature name="openhab-binding-bluetooth-bluegiga" description="Bluetooth Binding Bluegiga" version="${project.version}">
|
||||
<feature>openhab-runtime-base</feature>
|
||||
<feature>openhab-transport-serial</feature>
|
||||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.bluetooth/${project.version}</bundle>
|
||||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.bluetooth.bluegiga/${project.version}</bundle>
|
||||
</feature>
|
||||
|
||||
</features>
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.BluetoothBindingConstants;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
|
||||
/**
|
||||
* The {@link BlueGigaAdapterConstants} class defines common constants, which are
|
||||
* used across the whole binding.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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";
|
||||
}
|
||||
@@ -0,0 +1,568 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.bluetooth.BaseBluetoothDevice;
|
||||
import org.openhab.binding.bluetooth.BluetoothAddress;
|
||||
import org.openhab.binding.bluetooth.BluetoothCharacteristic;
|
||||
import org.openhab.binding.bluetooth.BluetoothCompletionStatus;
|
||||
import org.openhab.binding.bluetooth.BluetoothDescriptor;
|
||||
import org.openhab.binding.bluetooth.BluetoothDevice;
|
||||
import org.openhab.binding.bluetooth.BluetoothService;
|
||||
import org.openhab.binding.bluetooth.bluegiga.handler.BlueGigaBridgeHandler;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaEventListener;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeValueEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationFoundEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaGroupFoundEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaProcedureCompletedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.eir.EirDataType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.eir.EirPacket;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag;
|
||||
import org.openhab.binding.bluetooth.notification.BluetoothConnectionStatusNotification;
|
||||
import org.openhab.binding.bluetooth.notification.BluetoothScanNotification;
|
||||
import org.openhab.binding.bluetooth.notification.BluetoothScanNotification.BluetoothBeaconType;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* An extended {@link BluetoothDevice} class to handle BlueGiga specific information
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements BlueGigaEventListener {
|
||||
private final long TIMEOUT_SEC = 60;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(BlueGigaBluetoothDevice.class);
|
||||
|
||||
// BlueGiga needs to know the address type when connecting
|
||||
private BluetoothAddressType addressType = BluetoothAddressType.UNKNOWN;
|
||||
|
||||
// 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 @Nullable BluetoothCharacteristic procedureCharacteristic;
|
||||
|
||||
// The connection handle if the device is connected
|
||||
private int connection = -1;
|
||||
|
||||
private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("bluetooth");
|
||||
|
||||
private @Nullable ScheduledFuture<?> connectTimer;
|
||||
private @Nullable ScheduledFuture<?> procedureTimer;
|
||||
|
||||
private Runnable connectTimeoutTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connectionState == ConnectionState.CONNECTING) {
|
||||
logger.debug("Connection timeout for device {}", address);
|
||||
connectionState = ConnectionState.DISCONNECTED;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable procedureTimeoutTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("Procedure {} timeout for device {}", procedureProgress, address);
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
procedureCharacteristic = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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);
|
||||
updateLastSeenTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean connect() {
|
||||
if (connection != -1) {
|
||||
// We're already connected
|
||||
return false;
|
||||
}
|
||||
|
||||
cancelTimer(connectTimer);
|
||||
if (bgHandler.bgConnect(address, addressType)) {
|
||||
connectionState = ConnectionState.CONNECTING;
|
||||
connectTimer = startTimer(connectTimeoutTask, TIMEOUT_SEC);
|
||||
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() {
|
||||
if (procedureProgress != BlueGigaProcedure.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
if (!bgHandler.bgFindPrimaryServices(connection)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
procedureTimer = startTimer(procedureTimeoutTask, TIMEOUT_SEC);
|
||||
procedureProgress = BlueGigaProcedure.GET_SERVICES;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableNotifications(BluetoothCharacteristic characteristic) {
|
||||
// TODO will be implemented in a followup PR
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableNotifications(BluetoothCharacteristic characteristic) {
|
||||
// TODO will be implemented in a followup PR
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableNotifications(BluetoothDescriptor descriptor) {
|
||||
// TODO will be implemented in a followup PR
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableNotifications(BluetoothDescriptor descriptor) {
|
||||
// TODO will be implemented in a followup PR
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readCharacteristic(@Nullable BluetoothCharacteristic characteristic) {
|
||||
if (characteristic == null || characteristic.getHandle() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (procedureProgress != BlueGigaProcedure.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
if (!bgHandler.bgReadCharacteristic(connection, characteristic.getHandle())) {
|
||||
return false;
|
||||
}
|
||||
procedureTimer = startTimer(procedureTimeoutTask, TIMEOUT_SEC);
|
||||
procedureProgress = BlueGigaProcedure.CHARACTERISTIC_READ;
|
||||
procedureCharacteristic = characteristic;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeCharacteristic(@Nullable BluetoothCharacteristic characteristic) {
|
||||
if (characteristic == null || characteristic.getHandle() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (procedureProgress != BlueGigaProcedure.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
if (!bgHandler.bgWriteCharacteristic(connection, characteristic.getHandle(), characteristic.getValue())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
procedureTimer = startTimer(procedureTimeoutTask, TIMEOUT_SEC);
|
||||
procedureProgress = BlueGigaProcedure.CHARACTERISTIC_WRITE;
|
||||
procedureCharacteristic = characteristic;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bluegigaEventReceived(BlueGigaResponse event) {
|
||||
if (event instanceof BlueGigaScanResponseEvent) {
|
||||
handleScanEvent((BlueGigaScanResponseEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaGroupFoundEvent) {
|
||||
handleGroupFoundEvent((BlueGigaGroupFoundEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaFindInformationFoundEvent) {
|
||||
// A Characteristic has been discovered
|
||||
handleFindInformationFoundEvent((BlueGigaFindInformationFoundEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaProcedureCompletedEvent) {
|
||||
handleProcedureCompletedEvent((BlueGigaProcedureCompletedEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaConnectionStatusEvent) {
|
||||
handleConnectionStatusEvent((BlueGigaConnectionStatusEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaDisconnectedEvent) {
|
||||
handleDisconnectedEvent((BlueGigaDisconnectedEvent) event);
|
||||
}
|
||||
|
||||
else if (event instanceof BlueGigaAttributeValueEvent) {
|
||||
handleAttributeValueEvent((BlueGigaAttributeValueEvent) event);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScanEvent(BlueGigaScanResponseEvent event) {
|
||||
// Check if this is addressed to this device
|
||||
if (!address.equals(new BluetoothAddress(event.getSender()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.trace("scanEvent: {}", event);
|
||||
updateLastSeenTime();
|
||||
|
||||
// Set device properties
|
||||
rssi = event.getRssi();
|
||||
addressType = event.getAddressType();
|
||||
|
||||
byte[] manufacturerData = null;
|
||||
|
||||
// If the packet contains data, then process it and add anything relevant to the device...
|
||||
if (event.getData().length > 0) {
|
||||
EirPacket eir = new EirPacket(event.getData());
|
||||
for (EirDataType record : eir.getRecords().keySet()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(" EirDataType: {}={}", record, eir.getRecord(record));
|
||||
}
|
||||
Object obj;
|
||||
switch (record) {
|
||||
case EIR_FLAGS:
|
||||
break;
|
||||
case EIR_MANUFACTURER_SPECIFIC:
|
||||
obj = eir.getRecord(EirDataType.EIR_MANUFACTURER_SPECIFIC);
|
||||
if (obj != null) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Short, int[]> eirRecord = (Map<Short, int[]>) obj;
|
||||
Map.Entry<Short, int[]> eirEntry = eirRecord.entrySet().iterator().next();
|
||||
|
||||
manufacturer = eirEntry.getKey().intValue();
|
||||
|
||||
int[] manufacturerInt = eirEntry.getValue();
|
||||
manufacturerData = new byte[manufacturerInt.length + 2];
|
||||
// Convert short Company ID to bytes and add it to manufacturerData
|
||||
manufacturerData[0] = (byte) (manufacturer & 0xff);
|
||||
manufacturerData[1] = (byte) ((manufacturer >> 8) & 0xff);
|
||||
// Add Convert int custom data nd add it to manufacturerData
|
||||
for (int i = 0; i < manufacturerInt.length; i++) {
|
||||
manufacturerData[i + 2] = (byte) manufacturerInt[i];
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
logger.debug("Unsupported manufacturer specific record received from device {}",
|
||||
address);
|
||||
}
|
||||
}
|
||||
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<UUID>) eir.getRecord(record));
|
||||
break;
|
||||
case EIR_TXPOWER:
|
||||
obj = eir.getRecord(EirDataType.EIR_TXPOWER);
|
||||
if (obj != null) {
|
||||
txPower = (int) obj;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (connectionState == ConnectionState.DISCOVERING) {
|
||||
// TODO: It could make sense to wait with discovery for non-connectable devices until scan response is
|
||||
// received to eventually retrieve more about the device before it gets discovered. Anyhow, devices
|
||||
// that don't send a scan response at all also have to be supported. See also PR #6995.
|
||||
|
||||
// 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(event.getRssi());
|
||||
|
||||
switch (event.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);
|
||||
}
|
||||
|
||||
private void handleGroupFoundEvent(BlueGigaGroupFoundEvent event) {
|
||||
// If this is not our connection handle then ignore.
|
||||
if (connection != event.getConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.trace("BlueGiga Group: {} svcs={}", this, supportedServices);
|
||||
updateLastSeenTime();
|
||||
|
||||
BluetoothService service = new BluetoothService(event.getUuid(), true, event.getStart(), event.getEnd());
|
||||
addService(service);
|
||||
}
|
||||
|
||||
private void handleFindInformationFoundEvent(BlueGigaFindInformationFoundEvent event) {
|
||||
// If this is not our connection handle then ignore.
|
||||
if (connection != event.getConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.trace("BlueGiga FindInfo: {} svcs={}", this, supportedServices);
|
||||
updateLastSeenTime();
|
||||
|
||||
BluetoothCharacteristic characteristic = new BluetoothCharacteristic(event.getUuid(), event.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);
|
||||
}
|
||||
|
||||
private void handleProcedureCompletedEvent(BlueGigaProcedureCompletedEvent event) {
|
||||
// If this is not our connection handle then ignore.
|
||||
if (connection != event.getConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (procedureProgress == BlueGigaProcedure.NONE) {
|
||||
logger.debug("BlueGiga procedure completed but procedure is null with connection {}, address {}",
|
||||
connection, address);
|
||||
return;
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
updateLastSeenTime();
|
||||
|
||||
// The current procedure is now complete - move on...
|
||||
switch (procedureProgress) {
|
||||
case GET_SERVICES:
|
||||
// We've downloaded all services, now get the characteristics
|
||||
if (bgHandler.bgFindCharacteristics(connection)) {
|
||||
procedureTimer = startTimer(procedureTimeoutTask, TIMEOUT_SEC);
|
||||
procedureProgress = BlueGigaProcedure.GET_CHARACTERISTICS;
|
||||
} else {
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
}
|
||||
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 = event.getResult() == BgApiResponse.SUCCESS
|
||||
? BluetoothCompletionStatus.SUCCESS
|
||||
: BluetoothCompletionStatus.ERROR;
|
||||
notifyListeners(BluetoothEventType.CHARACTERISTIC_WRITE_COMPLETE, procedureCharacteristic, result);
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
procedureCharacteristic = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConnectionStatusEvent(BlueGigaConnectionStatusEvent event) {
|
||||
// Check if this is addressed to this device
|
||||
if (!address.equals(new BluetoothAddress(event.getAddress()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancelTimer(connectTimer);
|
||||
updateLastSeenTime();
|
||||
|
||||
// If we're connected, then remember the connection handle
|
||||
if (event.getFlags().contains(ConnectionStatusFlag.CONNECTION_CONNECTED)) {
|
||||
connectionState = ConnectionState.CONNECTED;
|
||||
connection = event.getConnection();
|
||||
notifyListeners(BluetoothEventType.CONNECTION_STATE,
|
||||
new BluetoothConnectionStatusNotification(connectionState));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDisconnectedEvent(BlueGigaDisconnectedEvent event) {
|
||||
// If this is not our connection handle then ignore.
|
||||
if (connection != event.getConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
connectionState = ConnectionState.DISCONNECTED;
|
||||
connection = -1;
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
|
||||
notifyListeners(BluetoothEventType.CONNECTION_STATE,
|
||||
new BluetoothConnectionStatusNotification(connectionState));
|
||||
}
|
||||
|
||||
private void handleAttributeValueEvent(BlueGigaAttributeValueEvent event) {
|
||||
// If this is not our connection handle then ignore.
|
||||
if (connection != event.getConnection()) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateLastSeenTime();
|
||||
|
||||
BluetoothCharacteristic characteristic = getCharacteristicByHandle(event.getAttHandle());
|
||||
if (characteristic == null) {
|
||||
logger.debug("BlueGiga didn't find characteristic for event {}", event);
|
||||
} else {
|
||||
characteristic.setValue(event.getValue().clone());
|
||||
|
||||
// If this is the characteristic we were reading, then send a read completion
|
||||
if (procedureProgress == BlueGigaProcedure.CHARACTERISTIC_READ && procedureCharacteristic != null
|
||||
&& procedureCharacteristic.getHandle() == event.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, characteristic);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up and release memory.
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (connectionState == ConnectionState.CONNECTED) {
|
||||
disconnect();
|
||||
}
|
||||
cancelTimer(connectTimer);
|
||||
cancelTimer(procedureTimer);
|
||||
bgHandler.removeEventListener(this);
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
connectionState = ConnectionState.DISCOVERING;
|
||||
connection = -1;
|
||||
}
|
||||
|
||||
private void cancelTimer(@Nullable ScheduledFuture<?> task) {
|
||||
if (task != null) {
|
||||
task.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledFuture<?> startTimer(Runnable command, long timeout) {
|
||||
return scheduler.schedule(command, timeout, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,741 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.handler;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.bluetooth.AbstractBluetoothBridgeHandler;
|
||||
import org.openhab.binding.bluetooth.BluetoothAddress;
|
||||
import org.openhab.binding.bluetooth.BluetoothBindingConstants;
|
||||
import org.openhab.binding.bluetooth.bluegiga.BlueGigaAdapterConstants;
|
||||
import org.openhab.binding.bluetooth.bluegiga.BlueGigaBluetoothDevice;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaConfiguration;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaEventListener;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaException;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaHandlerListener;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaSerialHandler;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaTransactionManager;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaDiscoverCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaDiscoverResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetScanParametersCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetScanParametersResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.openhab.core.io.transport.serial.PortInUseException;
|
||||
import org.openhab.core.io.transport.serial.SerialPort;
|
||||
import org.openhab.core.io.transport.serial.SerialPortIdentifier;
|
||||
import org.openhab.core.io.transport.serial.SerialPortManager;
|
||||
import org.openhab.core.io.transport.serial.UnsupportedCommOperationException;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
import org.openhab.core.thing.ThingStatusDetail;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <p>
|
||||
* The handler provides the serial interface to the dongle via the BlueGiga BG-API library.
|
||||
* <p>
|
||||
* 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
|
||||
* @author Pauli Anttila - Many improvements
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaBridgeHandler extends AbstractBluetoothBridgeHandler<BlueGigaBluetoothDevice>
|
||||
implements BlueGigaEventListener, BlueGigaHandlerListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(BlueGigaBridgeHandler.class);
|
||||
|
||||
private final int COMMAND_TIMEOUT_MS = 5000;
|
||||
private final int INITIALIZATION_INTERVAL_SEC = 60;
|
||||
|
||||
private final SerialPortManager serialPortManager;
|
||||
|
||||
private final ScheduledExecutorService executor = ThreadPoolManager.getScheduledPool("BlueGiga");
|
||||
|
||||
// The serial port.
|
||||
private Optional<SerialPort> serialPort = Optional.empty();
|
||||
|
||||
private BlueGigaConfiguration configuration = new BlueGigaConfiguration();
|
||||
|
||||
// The serial port input stream.
|
||||
private Optional<InputStream> inputStream = Optional.empty();
|
||||
|
||||
// The serial port output stream.
|
||||
private Optional<OutputStream> outputStream = Optional.empty();
|
||||
|
||||
// The BlueGiga API handler
|
||||
private Optional<BlueGigaSerialHandler> serialHandler = Optional.empty();
|
||||
|
||||
// The BlueGiga transaction manager
|
||||
private Optional<BlueGigaTransactionManager> transactionManager = Optional.empty();
|
||||
|
||||
// The maximum number of connections this interface supports
|
||||
private int maxConnections = 0;
|
||||
|
||||
// Our BT address
|
||||
private @Nullable BluetoothAddress address;
|
||||
|
||||
// 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<BluetoothAddress, BlueGigaBluetoothDevice> devices = new ConcurrentHashMap<>();
|
||||
|
||||
// Map of open connections
|
||||
private final Map<Integer, BluetoothAddress> connections = new ConcurrentHashMap<>();
|
||||
|
||||
private volatile boolean initComplete = false;
|
||||
|
||||
private @Nullable ScheduledFuture<?> initTask;
|
||||
private @Nullable ScheduledFuture<?> removeInactiveDevicesTask;
|
||||
private @Nullable ScheduledFuture<?> discoveryTask;
|
||||
|
||||
private @Nullable Future<?> passiveScanIdleTimer;
|
||||
|
||||
public BlueGigaBridgeHandler(Bridge bridge, SerialPortManager serialPortManager) {
|
||||
super(bridge);
|
||||
this.serialPortManager = serialPortManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
Optional<BlueGigaConfiguration> cfg = Optional.of(getConfigAs(BlueGigaConfiguration.class));
|
||||
if (cfg.isPresent()) {
|
||||
configuration = cfg.get();
|
||||
initTask = executor.scheduleWithFixedDelay(this::start, 0, INITIALIZATION_INTERVAL_SEC, TimeUnit.SECONDS);
|
||||
} else {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stop();
|
||||
stopScheduledTasks();
|
||||
if (initTask != null) {
|
||||
initTask.cancel(true);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
try {
|
||||
if (!initComplete) {
|
||||
logger.debug("Initialize BlueGiga");
|
||||
logger.debug("Using configuration: {}", configuration);
|
||||
stop();
|
||||
if (openSerialPort(configuration.port, 115200)) {
|
||||
serialHandler = Optional.of(new BlueGigaSerialHandler(inputStream.get(), outputStream.get()));
|
||||
transactionManager = Optional.of(new BlueGigaTransactionManager(serialHandler.get(), executor));
|
||||
serialHandler.get().addHandlerListener(this);
|
||||
transactionManager.get().addEventListener(this);
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
|
||||
try {
|
||||
// Stop any procedures that are running
|
||||
bgEndProcedure();
|
||||
|
||||
// Set mode to non-discoverable etc.
|
||||
bgSetMode();
|
||||
|
||||
// Get maximum parallel connections
|
||||
maxConnections = readMaxConnections().getMaxconn();
|
||||
|
||||
// Close all connections so we start from a known position
|
||||
for (int connection = 0; connection < maxConnections; connection++) {
|
||||
sendCommandWithoutChecks(
|
||||
new BlueGigaDisconnectCommand.CommandBuilder().withConnection(connection).build(),
|
||||
BlueGigaDisconnectResponse.class);
|
||||
}
|
||||
|
||||
// Get our Bluetooth address
|
||||
address = new BluetoothAddress(readAddress().getAddress());
|
||||
|
||||
updateThingProperties();
|
||||
|
||||
initComplete = true;
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
startScheduledTasks();
|
||||
} catch (BlueGigaException e) {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
|
||||
"Initialization of BlueGiga controller failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
// Avoid scheduled task to shutdown
|
||||
// e.g. when BlueGiga module is detached
|
||||
logger.debug("Start failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
if (transactionManager.isPresent()) {
|
||||
transactionManager.get().removeEventListener(this);
|
||||
transactionManager.get().close();
|
||||
transactionManager = Optional.empty();
|
||||
}
|
||||
if (serialHandler.isPresent()) {
|
||||
serialHandler.get().removeHandlerListener(this);
|
||||
serialHandler.get().close();
|
||||
serialHandler = Optional.empty();
|
||||
}
|
||||
address = null;
|
||||
initComplete = false;
|
||||
connections.clear();
|
||||
closeSerialPort();
|
||||
}
|
||||
|
||||
private void schedulePassiveScan() {
|
||||
cancelScheduledPassiveScan();
|
||||
passiveScanIdleTimer = executor.schedule(() -> {
|
||||
if (!activeScanEnabled) {
|
||||
logger.debug("Activate passive scan");
|
||||
bgEndProcedure();
|
||||
bgStartScanning(false, configuration.passiveScanInterval, configuration.passiveScanWindow);
|
||||
} else {
|
||||
logger.debug("Ignore passive scan activation as active scan is active");
|
||||
}
|
||||
}, configuration.passiveScanIdleTime, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void cancelScheduledPassiveScan() {
|
||||
if (passiveScanIdleTimer != null) {
|
||||
passiveScanIdleTimer.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startScheduledTasks() {
|
||||
schedulePassiveScan();
|
||||
logger.debug("Start scheduled task to remove inactive devices");
|
||||
discoveryTask = scheduler.scheduleWithFixedDelay(this::refreshDiscoveredDevices, 0, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void stopScheduledTasks() {
|
||||
cancelScheduledPassiveScan();
|
||||
if (removeInactiveDevicesTask != null) {
|
||||
removeInactiveDevicesTask.cancel(true);
|
||||
removeInactiveDevicesTask = null;
|
||||
}
|
||||
if (discoveryTask != null) {
|
||||
discoveryTask.cancel(true);
|
||||
discoveryTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
private BlueGigaGetConnectionsResponse readMaxConnections() throws BlueGigaException {
|
||||
return sendCommandWithoutChecks(new BlueGigaGetConnectionsCommand(), BlueGigaGetConnectionsResponse.class);
|
||||
}
|
||||
|
||||
private BlueGigaAddressGetResponse readAddress() throws BlueGigaException {
|
||||
return sendCommandWithoutChecks(new BlueGigaAddressGetCommand(), BlueGigaAddressGetResponse.class);
|
||||
}
|
||||
|
||||
private BlueGigaGetInfoResponse readInfo() throws BlueGigaException {
|
||||
return sendCommandWithoutChecks(new BlueGigaGetInfoCommand(), BlueGigaGetInfoResponse.class);
|
||||
}
|
||||
|
||||
private void updateThingProperties() throws BlueGigaException {
|
||||
BlueGigaGetInfoResponse infoResponse = readInfo();
|
||||
|
||||
Map<String, String> 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);
|
||||
}
|
||||
|
||||
private boolean openSerialPort(final String serialPortName, int baudRate) {
|
||||
logger.debug("Connecting to serial port '{}'", serialPortName);
|
||||
try {
|
||||
SerialPortIdentifier portIdentifier = serialPortManager.getIdentifier(serialPortName);
|
||||
if (portIdentifier == null) {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Port does not exist");
|
||||
return false;
|
||||
}
|
||||
SerialPort sp = portIdentifier.open("org.openhab.binding.bluetooth.bluegiga", 2000);
|
||||
sp.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||
|
||||
sp.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT);
|
||||
sp.enableReceiveThreshold(1);
|
||||
sp.enableReceiveTimeout(2000);
|
||||
|
||||
// RXTX serial port library causes high CPU load
|
||||
// Start event listener, which will just sleep and slow down event loop
|
||||
sp.notifyOnDataAvailable(true);
|
||||
|
||||
logger.info("Connected to serial port '{}'.", serialPortName);
|
||||
|
||||
try {
|
||||
inputStream = Optional.of(new BufferedInputStream(sp.getInputStream()));
|
||||
outputStream = Optional.of(new BufferedOutputStream(sp.getOutputStream()));
|
||||
} catch (IOException e) {
|
||||
logger.error("Error getting serial streams", e);
|
||||
return false;
|
||||
}
|
||||
serialPort = Optional.of(sp);
|
||||
return true;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
private void closeSerialPort() {
|
||||
serialPort.ifPresent(sp -> {
|
||||
sp.removeEventListener();
|
||||
try {
|
||||
sp.disableReceiveTimeout();
|
||||
} catch (Exception e) {
|
||||
// Ignore all as RXTX seems to send arbitrary exceptions when BlueGiga module is detached
|
||||
} finally {
|
||||
outputStream.ifPresent(output -> {
|
||||
IOUtils.closeQuietly(output);
|
||||
});
|
||||
inputStream.ifPresent(input -> {
|
||||
IOUtils.closeQuietly(input);
|
||||
});
|
||||
sp.close();
|
||||
logger.debug("Closed serial port.");
|
||||
serialPort = Optional.empty();
|
||||
inputStream = Optional.empty();
|
||||
outputStream = Optional.empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanStart() {
|
||||
super.scanStart();
|
||||
logger.debug("Start active scan");
|
||||
// Stop the passive scan
|
||||
cancelScheduledPassiveScan();
|
||||
bgEndProcedure();
|
||||
|
||||
// Start a active scan
|
||||
bgStartScanning(true, configuration.activeScanInterval, configuration.activeScanWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanStop() {
|
||||
super.scanStop();
|
||||
logger.debug("Stop active scan");
|
||||
|
||||
// Stop the active scan
|
||||
bgEndProcedure();
|
||||
|
||||
// Start a passive scan after idle delay
|
||||
schedulePassiveScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BluetoothAddress getAddress() {
|
||||
BluetoothAddress addr = address;
|
||||
if (addr != null) {
|
||||
return addr;
|
||||
} else {
|
||||
throw new IllegalStateException("Adapter has not been initialized yet!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlueGigaBluetoothDevice createDevice(BluetoothAddress address) {
|
||||
return new BlueGigaBluetoothDevice(this, address, BluetoothAddressType.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a device.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
logger.debug("BlueGiga Connect: address {}.", address);
|
||||
|
||||
// @formatter:off
|
||||
BlueGigaConnectDirectCommand command = new BlueGigaConnectDirectCommand.CommandBuilder()
|
||||
.withAddress(address.toString())
|
||||
.withAddrType(addressType)
|
||||
.withConnIntervalMin(configuration.connIntervalMin)
|
||||
.withConnIntervalMax(configuration.connIntervalMax)
|
||||
.withLatency(configuration.connLatency)
|
||||
.withTimeout(configuration.connTimeout)
|
||||
.build();
|
||||
// @formatter:on
|
||||
try {
|
||||
return sendCommand(command, BlueGigaConnectDirectResponse.class, true).getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending connect command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a connection using {@link BlueGigaDisconnectCommand}
|
||||
*
|
||||
* @param connectionHandle
|
||||
* @return
|
||||
*/
|
||||
public boolean bgDisconnect(int connectionHandle) {
|
||||
logger.debug("BlueGiga Disconnect: connection {}", connectionHandle);
|
||||
BlueGigaDisconnectCommand command = new BlueGigaDisconnectCommand.CommandBuilder()
|
||||
.withConnection(connectionHandle).build();
|
||||
|
||||
try {
|
||||
return sendCommand(command, BlueGigaDisconnectResponse.class, true).getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending disconnect command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// @formatter:off
|
||||
BlueGigaReadByGroupTypeCommand command = new BlueGigaReadByGroupTypeCommand.CommandBuilder()
|
||||
.withConnection(connectionHandle)
|
||||
.withStart(1)
|
||||
.withEnd(65535)
|
||||
.withUuid(UUID.fromString("00002800-0000-1000-8000-00805F9B34FB"))
|
||||
.build();
|
||||
// @formatter:on
|
||||
try {
|
||||
return sendCommand(command, BlueGigaReadByGroupTypeResponse.class, true)
|
||||
.getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending read primary services command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// @formatter:off
|
||||
BlueGigaFindInformationCommand command = new BlueGigaFindInformationCommand.CommandBuilder()
|
||||
.withConnection(connectionHandle)
|
||||
.withStart(1)
|
||||
.withEnd(65535)
|
||||
.build();
|
||||
// @formatter:on
|
||||
try {
|
||||
return sendCommand(command, BlueGigaFindInformationResponse.class, true)
|
||||
.getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending read characteristics command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// @formatter:off
|
||||
BlueGigaReadByHandleCommand command = new BlueGigaReadByHandleCommand.CommandBuilder()
|
||||
.withConnection(connectionHandle)
|
||||
.withChrHandle(handle)
|
||||
.build();
|
||||
// @formatter:on
|
||||
try {
|
||||
return sendCommand(command, BlueGigaReadByHandleResponse.class, true).getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending read characteristics command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// @formatter:off
|
||||
BlueGigaAttributeWriteCommand command = new BlueGigaAttributeWriteCommand.CommandBuilder()
|
||||
.withConnection(connectionHandle)
|
||||
.withAttHandle(handle)
|
||||
.withData(value)
|
||||
.build();
|
||||
// @formatter:on
|
||||
try {
|
||||
return sendCommand(command, BlueGigaAttributeWriteResponse.class, true)
|
||||
.getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending write characteristics command to device {}, reason: {}.", address,
|
||||
e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The following methods are private methods for handling the BlueGiga protocol
|
||||
*/
|
||||
private boolean bgEndProcedure() {
|
||||
try {
|
||||
return sendCommandWithoutChecks(new BlueGigaEndProcedureCommand(), BlueGigaEndProcedureResponse.class)
|
||||
.getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending end procedure command.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean bgSetMode() {
|
||||
try {
|
||||
// @formatter:off
|
||||
BlueGigaSetModeCommand command = new BlueGigaSetModeCommand.CommandBuilder()
|
||||
.withConnect(GapConnectableMode.GAP_NON_CONNECTABLE)
|
||||
.withDiscover(GapDiscoverableMode.GAP_NON_DISCOVERABLE)
|
||||
.build();
|
||||
// @formatter:on
|
||||
return sendCommandWithoutChecks(command, BlueGigaSetModeResponse.class)
|
||||
.getResult() == BgApiResponse.SUCCESS;
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending set mode command, reason: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts scanning on the dongle
|
||||
*
|
||||
* @param active true for active scanning
|
||||
*/
|
||||
private boolean bgStartScanning(boolean active, int interval, int window) {
|
||||
try {
|
||||
// @formatter:off
|
||||
BlueGigaSetScanParametersCommand scanCommand = new BlueGigaSetScanParametersCommand.CommandBuilder()
|
||||
.withActiveScanning(active)
|
||||
.withScanInterval(interval)
|
||||
.withScanWindow(window)
|
||||
.build();
|
||||
// @formatter:on
|
||||
if (sendCommand(scanCommand, BlueGigaSetScanParametersResponse.class, false)
|
||||
.getResult() == BgApiResponse.SUCCESS) {
|
||||
BlueGigaDiscoverCommand discoverCommand = new BlueGigaDiscoverCommand.CommandBuilder()
|
||||
.withMode(GapDiscoverMode.GAP_DISCOVER_OBSERVATION).build();
|
||||
if (sendCommand(discoverCommand, BlueGigaDiscoverResponse.class, false)
|
||||
.getResult() == BgApiResponse.SUCCESS) {
|
||||
logger.debug("{} scanning succesfully started.", active ? "Active" : "Passive");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (BlueGigaException e) {
|
||||
logger.debug("Error occured when sending start scan command, reason: {}", e.getMessage());
|
||||
}
|
||||
logger.debug("Scan start failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send command only if initialization phase is successfully done
|
||||
*/
|
||||
private <T extends BlueGigaResponse> T sendCommand(BlueGigaCommand command, Class<T> expectedResponse,
|
||||
boolean schedulePassiveScan) throws BlueGigaException {
|
||||
if (!initComplete) {
|
||||
throw new BlueGigaException("BlueGiga not initialized");
|
||||
}
|
||||
|
||||
if (schedulePassiveScan) {
|
||||
cancelScheduledPassiveScan();
|
||||
}
|
||||
try {
|
||||
return sendCommandWithoutChecks(command, expectedResponse);
|
||||
} finally {
|
||||
if (schedulePassiveScan) {
|
||||
schedulePassiveScan();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully send command without any checks
|
||||
*/
|
||||
private <T extends BlueGigaResponse> T sendCommandWithoutChecks(BlueGigaCommand command, Class<T> expectedResponse)
|
||||
throws BlueGigaException {
|
||||
if (transactionManager.isPresent()) {
|
||||
return transactionManager.get().sendTransaction(command, expectedResponse, COMMAND_TIMEOUT_MS);
|
||||
} else {
|
||||
throw new BlueGigaException("Transaction manager missing");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener for the BlueGiga events
|
||||
*
|
||||
* @param listener the {@link BlueGigaEventListener} to add
|
||||
*/
|
||||
public void addEventListener(BlueGigaEventListener listener) {
|
||||
transactionManager.ifPresent(manager -> {
|
||||
manager.addEventListener(listener);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an event listener for the BlueGiga events
|
||||
*
|
||||
* @param listener the {@link BlueGigaEventListener} to remove
|
||||
*/
|
||||
public void removeEventListener(BlueGigaEventListener listener) {
|
||||
transactionManager.ifPresent(manager -> {
|
||||
manager.removeEventListener(listener);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bluegigaEventReceived(@Nullable BlueGigaResponse event) {
|
||||
if (event instanceof BlueGigaScanResponseEvent) {
|
||||
if (initComplete) {
|
||||
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());
|
||||
if (!devices.containsKey(sender)) {
|
||||
BlueGigaBluetoothDevice device;
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
logger.trace("Ignore BlueGigaScanResponseEvent as initialization is not complete");
|
||||
}
|
||||
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 bluegigaClosed(Exception reason) {
|
||||
logger.debug("BlueGiga connection closed, request reinitialization");
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, reason.getMessage());
|
||||
initComplete = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode;
|
||||
import org.openhab.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 - Initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.BaseBluetoothBridgeHandlerConfiguration;
|
||||
|
||||
/**
|
||||
* Configuration class for {@link BlueGigaConfiguration} device.
|
||||
*
|
||||
* @author Pauli Anttila - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaConfiguration extends BaseBluetoothBridgeHandlerConfiguration {
|
||||
public String port = "";
|
||||
public int passiveScanIdleTime;
|
||||
public int passiveScanInterval;
|
||||
public int passiveScanWindow;
|
||||
public int activeScanInterval;
|
||||
public int activeScanWindow;
|
||||
public int connIntervalMin;
|
||||
public int connIntervalMax;
|
||||
public int connLatency;
|
||||
public int connTimeout;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"[discovery=%b, port=%s, passiveScanIdleTime=%d, passiveScanInterval=%d, passiveScanWindow=%d"
|
||||
+ ", activeScanInterval=%d, activeScanWindow=%d, connIntervalMin=%d, connIntervalMax=%d"
|
||||
+ ", connLatency=%d, connTimeout=%d]",
|
||||
backgroundDiscovery, port, passiveScanIdleTime, passiveScanInterval, passiveScanWindow,
|
||||
activeScanInterval, activeScanWindow, connIntervalMin, connIntervalMax, connLatency, connTimeout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Abstract base class for all device commands.
|
||||
*
|
||||
* @author Pauli Anttila - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class BlueGigaDeviceCommand extends BlueGigaCommand {
|
||||
|
||||
/**
|
||||
* Connection handle.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
protected int connection;
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public final void setConnection(int connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connection handle.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current connection as {@link int}
|
||||
*/
|
||||
public final int getConnection() {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Abstract base class for all device responses.
|
||||
*
|
||||
* @author Pauli Anttila - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class BlueGigaDeviceResponse extends BlueGigaResponse {
|
||||
|
||||
/**
|
||||
* Connection handle.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
protected int connection;
|
||||
|
||||
protected BlueGigaDeviceResponse(int[] inputBuffer) {
|
||||
super(inputBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connection handle.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current connection as {@link int}
|
||||
*/
|
||||
public final int getConnection() {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Listener interface for events
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface BlueGigaEventListener {
|
||||
/**
|
||||
* Called when an event is received
|
||||
*
|
||||
* @param event the {@link BlueGigaResponse} just received
|
||||
*/
|
||||
void bluegigaEventReceived(BlueGigaResponse event);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* A runtime exception used in the internal code of this bundle.
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 58882813509800169L;
|
||||
|
||||
public BlueGigaException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BlueGigaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BlueGigaException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.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);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Base class from which both commands and responses (and events) are derived.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class BlueGigaPacket {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.AttributeChangeReason;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.AttributeValueType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag;
|
||||
import org.openhab.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 - Initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract 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:
|
||||
// 0000xxxx-0000-1000-8000-00805F9B34FB
|
||||
low = 0x800000805f9b34fbL;
|
||||
high = ((long) buffer[position++] << 32) + ((long) buffer[position++] << 40) + 0x00001000L;
|
||||
break;
|
||||
case 4:
|
||||
// xxxxxxxx-0000-1000-8000-00805F9B34FB
|
||||
low = 0x800000805f9b34fbL;
|
||||
high = ((long) buffer[position++] << 32) + ((long) buffer[position++] << 40)
|
||||
+ ((long) buffer[position++] << 48) + ((long) buffer[position++] << 56) + 0x00001000L;
|
||||
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<ConnectionStatusFlag> deserializeConnectionStatusFlag() {
|
||||
int val = deserializeUInt8();
|
||||
Set<ConnectionStatusFlag> 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.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.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeValueEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaAttributeWriteResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaExecuteWriteResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindByTypeValueResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationFoundEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaGroupFoundEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaIndicateConfirmResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaIndicatedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaPrepareWriteResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaProcedureCompletedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByGroupTypeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByHandleResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadByTypeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadLongResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadMultipleResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaReadMultipleResponseEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaWriteCommandResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaAttributeStatusEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaReadResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaReadTypeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaSendAttributesResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserReadRequestEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserReadResponseResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaUserWriteResponseResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaValueEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.attributedb.BlueGigaWriteResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaChannelMapGetResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaConnectionStatusEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaDisconnectedEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaFeatureIndEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaGetRssiResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaGetStatusResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaUpdateResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.connection.BlueGigaVersionIndEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectDirectResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaConnectSelectiveResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaDiscoverResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaScanResponseEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetAdvDataResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetAdvParametersResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetModeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaSetScanParametersResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaBondStatusEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaBondingFailEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaDeleteBondingResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaEncryptStartResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaGetBondsResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPassKeyResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPasskeyDisplayEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaPasskeyRequestEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaSetBondableModeResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaSetParametersResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.security.BlueGigaWhitelistBondsResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaAddressGetResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaBootEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaEndpointWatermarkRxEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaEndpointWatermarkTxEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetConnectionsResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetCountersResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaGetInfoResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaHelloResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaNoLicenseKeyEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaProtocolErrorEvent;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaResetResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaWhitelistAppendResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.system.BlueGigaWhitelistClearResponse;
|
||||
import org.openhab.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 (i.e. packets that we will receive).
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution and API
|
||||
*/
|
||||
@NonNullByDefault
|
||||
class BlueGigaResponsePackets {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(BlueGigaResponsePackets.class);
|
||||
|
||||
private static final Map<Integer, Class<?>> 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);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "null", "unused" })
|
||||
@Nullable
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Listener interface for events
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution and API
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface BlueGigaSerialEventListener {
|
||||
/**
|
||||
* Called when an event is received
|
||||
*
|
||||
* @param event the {@link BlueGigaResponse} just received
|
||||
*/
|
||||
void bluegigaFrameReceived(BlueGigaResponse event);
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.command.gap.BlueGigaEndProcedureCommand;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The main handler class for interacting with the BlueGiga serial API. This class provides conversion of packets from
|
||||
* the serial stream into command and response classes.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution and API
|
||||
* @author Pauli Anttila - Split serial handler and transaction management
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaSerialHandler {
|
||||
|
||||
private static final int BLE_MAX_LENGTH = 64;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(BlueGigaSerialHandler.class);
|
||||
|
||||
/**
|
||||
* The event listeners will be notified of any asynchronous events
|
||||
*/
|
||||
private final Set<BlueGigaSerialEventListener> eventListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
/**
|
||||
* The event listeners will be notified of any life-cycle events of the handler.
|
||||
*/
|
||||
private final Set<BlueGigaHandlerListener> handlerListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
/**
|
||||
* Flag reflecting that parser has been closed and parser parserThread
|
||||
* should exit.
|
||||
*/
|
||||
private boolean close = false;
|
||||
|
||||
private final OutputStream outputStream;
|
||||
private final InputStream inputStream;
|
||||
private final Thread parserThread;
|
||||
|
||||
public BlueGigaSerialHandler(final InputStream inputStream, final OutputStream outputStream) {
|
||||
this.outputStream = outputStream;
|
||||
this.inputStream = inputStream;
|
||||
|
||||
flush();
|
||||
parserThread = createBlueGigaBLEHandler();
|
||||
parserThread.setDaemon(true);
|
||||
parserThread.start();
|
||||
int tries = 0;
|
||||
|
||||
// wait until the daemon thread kicks off, e.g. when it is ready to receive any commands
|
||||
while (parserThread.getState() == Thread.State.NEW) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
tries++;
|
||||
if (tries > 10) {
|
||||
throw new IllegalStateException("BlueGiga handler thread failed to start");
|
||||
}
|
||||
} catch (InterruptedException ignore) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void flush() {
|
||||
// Send End Procedure command to end all activity and flush input buffer to start from know state
|
||||
logger.trace("Flush input stream");
|
||||
sendFrame(new BlueGigaEndProcedureCommand(), false);
|
||||
try {
|
||||
// Wait BlueGiga controller have stopped all activity
|
||||
Thread.sleep(100);
|
||||
logger.trace("Bytes available: {}", inputStream.available());
|
||||
IOUtils.skipFully(inputStream, inputStream.available());
|
||||
} catch (InterruptedException e) {
|
||||
close = true;
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
logger.trace("Flush done");
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests parser thread to shutdown. Waits forever while the parser thread is getting shut down.
|
||||
*/
|
||||
public void close() {
|
||||
close(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests parser thread to shutdown. Waits specified milliseconds while the parser thread is getting shut down.
|
||||
*
|
||||
* @param timeout milliseconds to wait
|
||||
*/
|
||||
public void close(long timeout) {
|
||||
close = true;
|
||||
try {
|
||||
parserThread.interrupt();
|
||||
// Give a fair chance to shutdown nicely
|
||||
Thread.sleep(50);
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
parserThread.join(0);
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn("Interrupted in packet parser thread shutdown join.");
|
||||
}
|
||||
|
||||
handlerListeners.clear();
|
||||
eventListeners.clear();
|
||||
logger.debug("Closed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if parser thread is alive.
|
||||
*
|
||||
* @return true if parser thread is alive.
|
||||
*/
|
||||
public boolean isAlive() {
|
||||
return parserThread.isAlive() && !close;
|
||||
}
|
||||
|
||||
public void sendFrame(BlueGigaCommand bleFrame) throws IllegalStateException {
|
||||
sendFrame(bleFrame, true);
|
||||
}
|
||||
|
||||
private void sendFrame(BlueGigaCommand bleFrame, boolean checkIsAlive) throws IllegalStateException {
|
||||
if (checkIsAlive) {
|
||||
checkIfAlive();
|
||||
}
|
||||
|
||||
// Send the data
|
||||
logger.trace("sendFrame: {}", bleFrame);
|
||||
try {
|
||||
int[] payload = bleFrame.serialize();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("BLE TX: {}", printHex(payload, payload.length));
|
||||
}
|
||||
for (int b : payload) {
|
||||
outputStream.write(b);
|
||||
}
|
||||
outputStream.flush();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new BlueGigaException("Error sending BLE frame", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEventListener(BlueGigaSerialEventListener listener) {
|
||||
eventListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeEventListener(BlueGigaSerialEventListener listener) {
|
||||
eventListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addHandlerListener(BlueGigaHandlerListener listener) {
|
||||
handlerListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeHandlerListener(BlueGigaHandlerListener listener) {
|
||||
handlerListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify any transaction listeners when we receive a response.
|
||||
*
|
||||
* @param response the response data received
|
||||
*/
|
||||
private void notifyEventListeners(final BlueGigaResponse response) {
|
||||
// Notify the listeners
|
||||
for (final BlueGigaSerialEventListener listener : eventListeners) {
|
||||
try {
|
||||
listener.bluegigaFrameReceived(response);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Execution error of a BlueGigaHandlerListener listener.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 notifyEventListeners(final 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 immediately
|
||||
for (final BlueGigaHandlerListener listener : handlerListeners) {
|
||||
try {
|
||||
listener.bluegigaClosed(reason);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Execution error of a BlueGigaHandlerListener listener.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
private Thread createBlueGigaBLEHandler() {
|
||||
final int framecheckParams[] = new int[] { 0x00, 0x7F, 0xC0, 0xF8, 0xE0 };
|
||||
return 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;
|
||||
}
|
||||
|
||||
inputBuffer[inputCount++] = val;
|
||||
|
||||
if (inputCount == 1) {
|
||||
if (inputStream.markSupported()) {
|
||||
inputStream.mark(BLE_MAX_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (inputStream.markSupported()) {
|
||||
inputStream.reset();
|
||||
}
|
||||
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.debug("BLE length larger than 64 bytes ({})", inputLength);
|
||||
}
|
||||
}
|
||||
if (inputCount == inputLength) {
|
||||
// End of packet reached - process
|
||||
BlueGigaResponse responsePacket = BlueGigaResponsePackets.getPacket(inputBuffer);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("BLE RX: {}", printHex(inputBuffer, inputLength));
|
||||
logger.trace("BLE RX: {}", responsePacket);
|
||||
}
|
||||
if (responsePacket != null) {
|
||||
notifyEventListeners(responsePacket);
|
||||
}
|
||||
|
||||
inputCount = 0;
|
||||
exceptionCnt = 0;
|
||||
}
|
||||
|
||||
} catch (final IOException e) {
|
||||
logger.debug("BlueGiga BLE IOException: ", e);
|
||||
|
||||
if (exceptionCnt++ > 10) {
|
||||
logger.error("BlueGiga BLE exception count exceeded, closing handler");
|
||||
close = true;
|
||||
notifyEventListeners(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.debug("BlueGiga BLE exited.");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This class provides transaction management and queuing of {@link BlueGigaCommand} frames.
|
||||
*
|
||||
* @author Pauli Anttila - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaTransactionManager implements BlueGigaSerialEventListener {
|
||||
|
||||
private static final int TRANSACTION_TIMEOUT_PERIOD_MS = 100;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(BlueGigaTransactionManager.class);
|
||||
|
||||
/**
|
||||
* Unique transaction id for request and response correlation
|
||||
*/
|
||||
private AtomicInteger transactionId = new AtomicInteger();
|
||||
|
||||
/**
|
||||
* Ongoing transaction id. If not present, no ongoing transaction.
|
||||
*/
|
||||
private volatile Optional<Integer> ongoingTransactionId = Optional.empty();
|
||||
|
||||
/**
|
||||
* Transaction listeners are used internally to correlate the commands and responses
|
||||
*/
|
||||
private final List<BluetoothListener<? extends BlueGigaResponse>> transactionListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* The event listeners will be notified of any asynchronous events
|
||||
*/
|
||||
private final Set<BlueGigaEventListener> eventListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
private final Queue<BlueGigaUniqueCommand> sendQueue = new LinkedList<>();
|
||||
private final ScheduledExecutorService executor;
|
||||
private final BlueGigaSerialHandler serialHandler;
|
||||
|
||||
private @Nullable Future<?> transactionTimeoutTimer;
|
||||
|
||||
/**
|
||||
* Internal interface for transaction listeners.
|
||||
*/
|
||||
interface BluetoothListener<T extends BlueGigaResponse> {
|
||||
boolean transactionEvent(BlueGigaResponse response, int transactionId);
|
||||
|
||||
boolean transactionTimeout(int transactionId);
|
||||
}
|
||||
|
||||
public BlueGigaTransactionManager(BlueGigaSerialHandler serialHandler, ScheduledExecutorService executor) {
|
||||
this.serialHandler = serialHandler;
|
||||
this.executor = executor;
|
||||
serialHandler.addEventListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close transaction manager.
|
||||
*/
|
||||
public void close() {
|
||||
serialHandler.removeEventListener(this);
|
||||
cancelTransactionTimer();
|
||||
sendQueue.clear();
|
||||
transactionListeners.clear();
|
||||
eventListeners.clear();
|
||||
logger.debug("Closed");
|
||||
}
|
||||
|
||||
private void startTransactionTimer() {
|
||||
transactionTimeoutTimer = executor.schedule(() -> {
|
||||
notifyTransactionTimeout(ongoingTransactionId);
|
||||
}, TRANSACTION_TIMEOUT_PERIOD_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void cancelTransactionTimer() {
|
||||
if (transactionTimeoutTimer != null) {
|
||||
transactionTimeoutTimer.cancel(true);
|
||||
transactionTimeoutTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendNextFrame() {
|
||||
getNextFrame().ifPresent(frame -> {
|
||||
cancelTransactionTimer();
|
||||
logger.debug("Send frame #{}: {}", frame.getTransactionId(), frame.getMessage());
|
||||
ongoingTransactionId = Optional.of(frame.getTransactionId());
|
||||
serialHandler.sendFrame(frame.getMessage());
|
||||
startTransactionTimer();
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "null", "unused" })
|
||||
private Optional<BlueGigaUniqueCommand> getNextFrame() {
|
||||
while (!sendQueue.isEmpty()) {
|
||||
BlueGigaUniqueCommand frame = sendQueue.poll();
|
||||
if (frame != null) {
|
||||
if (frame.getMessage() != null) {
|
||||
return Optional.of(frame);
|
||||
} else {
|
||||
logger.debug("Null message found from queue, skip it");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
logger.debug("Null frame found from queue, skip it");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link BlueGigaUniqueCommand} 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 BlueGigaUniqueCommand}
|
||||
*/
|
||||
public void queueFrame(BlueGigaUniqueCommand request) {
|
||||
logger.trace("Queue TX BLE frame: {}", request);
|
||||
sendQueue.add(request);
|
||||
logger.trace("TX BLE queue size: {}", sendQueue.size());
|
||||
}
|
||||
|
||||
private void sendNextTransactionIfNoOngoing() {
|
||||
synchronized (this) {
|
||||
logger.trace("Send next transaction if no ongoing");
|
||||
if (!ongoingTransactionId.isPresent()) {
|
||||
sendNextFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearOngoingTransactionAndSendNext() {
|
||||
synchronized (this) {
|
||||
logger.trace("Clear ongoing transaction and send next frame from queue");
|
||||
ongoingTransactionId = Optional.empty();
|
||||
sendNextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
private void addTransactionListener(BluetoothListener<? extends BlueGigaResponse> listener) {
|
||||
if (transactionListeners.contains(listener)) {
|
||||
return;
|
||||
}
|
||||
|
||||
transactionListeners.add(listener);
|
||||
}
|
||||
|
||||
private void removeTransactionListener(BluetoothListener<?> listener) {
|
||||
transactionListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an BlueGiga request without waiting for the response.
|
||||
*
|
||||
* @param bleCommand {@link BlueGigaCommand}
|
||||
* @return response {@link Future} {@link BlueGigaResponse}
|
||||
*/
|
||||
private <T extends BlueGigaResponse> Future<T> sendBleRequestAsync(final BlueGigaCommand bleCommand,
|
||||
final Class<T> expected) {
|
||||
class TransactionWaiter implements Callable<T>, BluetoothListener<T> {
|
||||
private volatile boolean complete;
|
||||
private Optional<BlueGigaResponse> response = Optional.empty();
|
||||
private BlueGigaUniqueCommand query = new BlueGigaUniqueCommand(bleCommand,
|
||||
transactionId.getAndIncrement());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T call() throws TimeoutException {
|
||||
// Register a listener
|
||||
addTransactionListener(this);
|
||||
|
||||
// Send the transaction
|
||||
queueFrame(query);
|
||||
sendNextTransactionIfNoOngoing();
|
||||
|
||||
// Wait transaction completed or timeout
|
||||
synchronized (this) {
|
||||
while (!complete) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cancelTransactionTimer();
|
||||
|
||||
// Remove the listener
|
||||
removeTransactionListener(this);
|
||||
|
||||
// Send next transaction if any
|
||||
executor.submit(BlueGigaTransactionManager.this::clearOngoingTransactionAndSendNext);
|
||||
|
||||
if (response.isPresent()) {
|
||||
return (T) response.get();
|
||||
} else {
|
||||
throw new TimeoutException("No response from BlueGiga controller");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transactionEvent(BlueGigaResponse bleResponse, int transactionId) {
|
||||
logger.trace("Expected transactionId: {}, received transactionId: {}", query.getTransactionId(),
|
||||
transactionId);
|
||||
|
||||
if (transactionId != query.getTransactionId()) {
|
||||
logger.trace("Ignore frame as received transaction Id {} doesn't match expected transaction Id {}.",
|
||||
transactionId, query.getTransactionId());
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.trace("Expected frame: {}, received frame: {}", expected.getSimpleName(), bleResponse);
|
||||
|
||||
if (bleCommand instanceof BlueGigaDeviceCommand && bleResponse instanceof BlueGigaDeviceResponse) {
|
||||
BlueGigaDeviceCommand devCommand = (BlueGigaDeviceCommand) bleCommand;
|
||||
BlueGigaDeviceResponse devResponse = (BlueGigaDeviceResponse) bleResponse;
|
||||
|
||||
logger.trace("Expected connection id: {}, received connection id: {}", devCommand.getConnection(),
|
||||
devResponse.getConnection());
|
||||
|
||||
if (devCommand.getConnection() != devResponse.getConnection()) {
|
||||
logger.trace("Ignore response as received connection id {} doesn't match expected id {}.",
|
||||
devResponse.getConnection(), devCommand.getConnection());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!expected.isInstance(bleResponse)) {
|
||||
logger.trace("Ignoring {} frame which has not been requested.",
|
||||
bleResponse.getClass().getSimpleName());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Response received, notify waiter
|
||||
response = Optional.of(bleResponse);
|
||||
complete = true;
|
||||
logger.debug("Received frame #{}: {}", transactionId, bleResponse);
|
||||
synchronized (this) {
|
||||
notify();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transactionTimeout(int transactionId) {
|
||||
if (transactionId != query.getTransactionId()) {
|
||||
return false;
|
||||
}
|
||||
logger.debug("Timeout, no response received for transaction {}", query.getTransactionId());
|
||||
complete = true;
|
||||
synchronized (this) {
|
||||
notify();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Callable<T> worker = new TransactionWaiter();
|
||||
return executor.submit(worker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link BlueGigaCommand} request to the NCP and waits for the response for specified period of time.
|
||||
* The response is correlated with the request and the returned {@link BlueGigaResponse}
|
||||
* contains the request and response data.
|
||||
*
|
||||
* @param bleCommand {@link BlueGigaCommand}
|
||||
* @param timeout milliseconds to wait until {@link TimeoutException} is thrown
|
||||
* @return response {@link BlueGigaResponse}
|
||||
* @throws BlueGigaException when any error occurred
|
||||
*/
|
||||
public <T extends BlueGigaResponse> T sendTransaction(BlueGigaCommand bleCommand, Class<T> expected, long timeout)
|
||||
throws BlueGigaException {
|
||||
Future<T> futureResponse = sendBleRequestAsync(bleCommand, expected);
|
||||
try {
|
||||
return futureResponse.get(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (TimeoutException | InterruptedException | ExecutionException e) {
|
||||
futureResponse.cancel(true);
|
||||
throw new BlueGigaException(String.format("Error sending BLE transaction: %s", e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEventListener(BlueGigaEventListener listener) {
|
||||
eventListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeEventListener(BlueGigaEventListener listener) {
|
||||
eventListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bluegigaFrameReceived(BlueGigaResponse event) {
|
||||
if (event.isEvent()) {
|
||||
notifyEventListeners(event);
|
||||
} else {
|
||||
notifyTransactionComplete(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify any event 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) {
|
||||
// Notify the listeners
|
||||
for (final BlueGigaEventListener listener : eventListeners) {
|
||||
executor.submit(() -> listener.bluegigaEventReceived(response));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify any internal transaction listeners when we receive a response.
|
||||
*
|
||||
* @param response
|
||||
* the response data received
|
||||
*/
|
||||
private void notifyTransactionComplete(final BlueGigaResponse response) {
|
||||
ongoingTransactionId.ifPresent(id -> {
|
||||
boolean processed = false;
|
||||
for (BluetoothListener<? extends BlueGigaResponse> listener : transactionListeners) {
|
||||
if (listener.transactionEvent(response, id)) {
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
if (!processed) {
|
||||
logger.debug("No listener found for received response: {}", response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyTransactionTimeout(final Optional<Integer> transactionId) {
|
||||
transactionId.ifPresent(id -> {
|
||||
boolean processed = false;
|
||||
for (BluetoothListener<? extends BlueGigaResponse> listener : transactionListeners) {
|
||||
if (listener.transactionTimeout(id)) {
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
if (!processed) {
|
||||
logger.debug("No listener found for transaction timeout event, transaction id {}", id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Container class to hold {@link BlueGigaCommand} and transaction id.
|
||||
*
|
||||
* @author Pauli Anttila - Initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUniqueCommand {
|
||||
private BlueGigaCommand msg;
|
||||
private int transactionId;
|
||||
|
||||
BlueGigaUniqueCommand(BlueGigaCommand message, int transactionId) {
|
||||
this.msg = message;
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
int getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
BlueGigaCommand getMessage() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("BlueGigaUniqueCommand [transactionId=");
|
||||
builder.append(transactionId);
|
||||
builder.append(", BlueGigaCommand=");
|
||||
builder.append(msg);
|
||||
builder.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.AttributeValueType;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>attributeValueEvent</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaAttributeValueEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x05;
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attHandle;
|
||||
|
||||
/**
|
||||
* Attribute type
|
||||
* <p>
|
||||
* BlueGiga API type is <i>AttributeValueType</i> - Java type is {@link AttributeValueType}
|
||||
*/
|
||||
private AttributeValueType type;
|
||||
|
||||
/**
|
||||
* Attribute value (data)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current att_handle as {@link int}
|
||||
*/
|
||||
public int getAttHandle() {
|
||||
return attHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute type
|
||||
* <p>
|
||||
* BlueGiga API type is <i>AttributeValueType</i> - Java type is {@link AttributeValueType}
|
||||
*
|
||||
* @return the current type as {@link AttributeValueType}
|
||||
*/
|
||||
public AttributeValueType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute value (data)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>attributeWrite</b>.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaAttributeWriteCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x05;
|
||||
|
||||
private BlueGigaAttributeWriteCommand(CommandBuilder builder) {
|
||||
super.setConnection(builder.connection);
|
||||
this.attHandle = builder.attHandle;
|
||||
this.data = builder.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle to write to
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attHandle;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int connection;
|
||||
private int attHandle;
|
||||
private int[] data = new int[0];
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withConnection(int connection) {
|
||||
this.connection = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle to write to
|
||||
*
|
||||
* @param attHandle the attHandle to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withAttHandle(int attHandle) {
|
||||
this.attHandle = attHandle;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
*
|
||||
* @param data the data to set as {@link int[]}
|
||||
*/
|
||||
public CommandBuilder withData(int[] data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaAttributeWriteCommand build() {
|
||||
return new BlueGigaAttributeWriteCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>attributeWrite</b>.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaAttributeWriteResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x05;
|
||||
|
||||
/**
|
||||
* 0 : write was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : write was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>executeWrite</b>.
|
||||
* <p>
|
||||
* This command can be used to execute or cancel a previously queued prepare_write command on a
|
||||
* remote device
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaExecuteWriteCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x0A;
|
||||
|
||||
/**
|
||||
* 1: commits queued writes, 0: cancels queued writes
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int commit;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>executeWrite</b>.
|
||||
* <p>
|
||||
* This command can be used to execute or cancel a previously queued prepare_write command on a
|
||||
* remote device
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaExecuteWriteResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x0A;
|
||||
|
||||
/**
|
||||
* 0 : write was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : write was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>findByTypeValue</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFindByTypeValueCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* First requested handle number
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int start;
|
||||
|
||||
/**
|
||||
* Last requested handle number
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int end;
|
||||
|
||||
/**
|
||||
* 2 octet UUID to find
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
|
||||
*/
|
||||
private UUID uuid = new UUID(0, 0);
|
||||
|
||||
/**
|
||||
* Attribute value to find
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] value = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>findByTypeValue</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFindByTypeValueResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* 0 : the operation was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the operation was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>findInformation</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFindInformationCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x03;
|
||||
|
||||
private BlueGigaFindInformationCommand(CommandBuilder builder) {
|
||||
super.setConnection(builder.connection);
|
||||
this.start = builder.start;
|
||||
this.end = builder.end;
|
||||
}
|
||||
|
||||
/**
|
||||
* First attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int start;
|
||||
|
||||
/**
|
||||
* Last attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int connection;
|
||||
private int start;
|
||||
private int end;
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withConnection(int connection) {
|
||||
this.connection = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* First requested handle number
|
||||
*
|
||||
* @param start the start to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withStart(int start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Last requested handle number
|
||||
*
|
||||
* @param end the end to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withEnd(int end) {
|
||||
this.end = end;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaFindInformationCommand build() {
|
||||
return new BlueGigaFindInformationCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>findInformationFoundEvent</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFindInformationFoundEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* Characteristics handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int chrHandle;
|
||||
|
||||
/**
|
||||
* Characteristics type (UUID)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Characteristics handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current chr_handle as {@link int}
|
||||
*/
|
||||
public int getChrHandle() {
|
||||
return chrHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Characteristics type (UUID)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>findInformation</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFindInformationResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x03;
|
||||
|
||||
/**
|
||||
* 0 : the operation was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the operation was successful. Otherwise error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>groupFoundEvent</b>.
|
||||
* <p>
|
||||
* This event is produced when an attribute group (a service) is found. Typically this event is
|
||||
* produced after Read by Group Type command.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaGroupFoundEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Starting handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int start;
|
||||
|
||||
/**
|
||||
* Ending handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int end;
|
||||
|
||||
/**
|
||||
* UUID of a service. Length is 0 if no services are found.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starting handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current start as {@link int}
|
||||
*/
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ending handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>indicateConfirm</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaIndicateConfirmCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x07;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>indicateConfirm</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaIndicateConfirmResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x07;
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>indicatedEvent</b>.
|
||||
* <p>
|
||||
* 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).
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaIndicatedEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>prepareWrite</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaPrepareWriteCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x09;
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attHandle;
|
||||
|
||||
/**
|
||||
* Offset to write to
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] data = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>prepareWrite</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaPrepareWriteResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x09;
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>procedureCompletedEvent</b>.
|
||||
* <p>
|
||||
* This event is produced at the GATT client when an attribute protocol event is completed a and
|
||||
* new operation can be issued
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaProcedureCompletedEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* 0: The operation was successful. Otherwise: attribute protocol error code returned by
|
||||
* remote device
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*/
|
||||
private BgApiResponse result;
|
||||
|
||||
/**
|
||||
* Characteristic handle at which the event ended
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0: The operation was successful. Otherwise: attribute protocol error code returned by
|
||||
* remote device
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*
|
||||
* @return the current result as {@link BgApiResponse}
|
||||
*/
|
||||
public BgApiResponse getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Characteristic handle at which the event ended
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByGroupType</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByGroupTypeCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
private BlueGigaReadByGroupTypeCommand(CommandBuilder builder) {
|
||||
super.setConnection(builder.connection);
|
||||
this.start = builder.start;
|
||||
this.end = builder.end;
|
||||
this.uuid = builder.uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* First requested handle number
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int start;
|
||||
|
||||
/**
|
||||
* Last requested handle number
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int end;
|
||||
|
||||
/**
|
||||
* Group UUID to find
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
|
||||
*/
|
||||
private 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int connection;
|
||||
private int start;
|
||||
private int end;
|
||||
private UUID uuid = new UUID(0, 0);
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withConnection(int connection) {
|
||||
this.connection = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* First requested handle number
|
||||
*
|
||||
* @param start the start to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withStart(int start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Last requested handle number
|
||||
*
|
||||
* @param end the end to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withEnd(int end) {
|
||||
this.end = end;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group UUID to find
|
||||
*
|
||||
* @param uuid the uuid to set as {@link UUID}
|
||||
*/
|
||||
public CommandBuilder withUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaReadByGroupTypeCommand build() {
|
||||
return new BlueGigaReadByGroupTypeCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByGroupType</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByGroupTypeResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Command result.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByHandle</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByHandleCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
private BlueGigaReadByHandleCommand(CommandBuilder builder) {
|
||||
super.setConnection(builder.connection);
|
||||
this.chrHandle = builder.chrHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int connection;
|
||||
private int chrHandle;
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withConnection(int connection) {
|
||||
this.connection = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
*
|
||||
* @param chrHandle the chrHandle to set as {@link int}
|
||||
*/
|
||||
public CommandBuilder withChrHandle(int chrHandle) {
|
||||
this.chrHandle = chrHandle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaReadByHandleCommand build() {
|
||||
return new BlueGigaReadByHandleCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByHandle</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByHandleResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByType</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByTypeCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* First attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int start;
|
||||
|
||||
/**
|
||||
* Last attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int end;
|
||||
|
||||
/**
|
||||
* Attribute type (UUID)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uuid</i> - Java type is {@link UUID}
|
||||
*/
|
||||
private UUID uuid = new UUID(0, 0);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readByType</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadByTypeResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readLong</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadLongCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x08;
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int chrHandle;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readLong</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadLongResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x08;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readMultiple</b>.
|
||||
* <p>
|
||||
* This command can be used to read multiple attributes from a server.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadMultipleCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x0B;
|
||||
|
||||
/**
|
||||
* List of attribute handles to read from the remote device
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] handles = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readMultiple</b>.
|
||||
* <p>
|
||||
* This command can be used to read multiple attributes from a server.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadMultipleResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x0B;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readMultipleResponseEvent</b>.
|
||||
* <p>
|
||||
* This event is a response to a Read Multiple request.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadMultipleResponseEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* This array contains the concatenated data from the multiple attributes that have been read,
|
||||
* up to 22 bytes.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* This array contains the concatenated data from the multiple attributes that have been read,
|
||||
* up to 22 bytes.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>writeCommand</b>.
|
||||
* <p>
|
||||
* Writes the value of a remote devices attribute. The handle and the new value of the attribute
|
||||
* are gives as parameters.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaWriteCommandCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x06;
|
||||
|
||||
/**
|
||||
* Attribute handle to write
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attHandle;
|
||||
|
||||
/**
|
||||
* Value for the attribute
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] data = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributeclient;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>writeCommand</b>.
|
||||
* <p>
|
||||
* Writes the value of a remote devices attribute. The handle and the new value of the attribute
|
||||
* are gives as parameters.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaWriteCommandResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x04;
|
||||
public static int COMMAND_METHOD = 0x06;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>attributeStatusEvent</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaAttributeStatusEvent extends BlueGigaResponse {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Attribute handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Attribute status flags. See: Attribute Status Flags
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current handle as {@link int}
|
||||
*/
|
||||
public int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute status flags. See: Attribute Status Flags
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>read</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* Handle of the attribute to read
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Offset to read from. Maximum of 32 bytes can be read at a time.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>read</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadResponse extends BlueGigaResponse {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* Handle of the attribute which was read
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Offset read from
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int offset;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*/
|
||||
private BgApiResponse result;
|
||||
|
||||
/**
|
||||
* Value of the attribute
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current handle as {@link int}
|
||||
*/
|
||||
public int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset read from
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*
|
||||
* @return the current result as {@link BgApiResponse}
|
||||
*/
|
||||
public BgApiResponse getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of the attribute
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readType</b>.
|
||||
* <p>
|
||||
* This command reads the given attribute's type (UUID) from the local database.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadTypeCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Handle of the attribute to read
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>readType</b>.
|
||||
* <p>
|
||||
* This command reads the given attribute's type (UUID) from the local database.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaReadTypeResponse extends BlueGigaResponse {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Handle of the attribute which was read
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* 0 : the command was successful. Otherwise an error occurred
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*/
|
||||
private BgApiResponse result;
|
||||
|
||||
/**
|
||||
* Value of the attribute type (UUID)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*
|
||||
* @return the current result as {@link BgApiResponse}
|
||||
*/
|
||||
public BgApiResponse getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of the attribute type (UUID)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>sendAttributes</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaSendAttributesCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Attribute handle to send.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Data to send
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] value = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>sendAttributes</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>userReadRequestEvent</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUserReadRequestEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* Attribute handle requested
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Attribute offset to send data from
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle requested
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current handle as {@link int}
|
||||
*/
|
||||
public int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute offset to send data from
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>userReadResponse</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUserReadResponseCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x03;
|
||||
|
||||
/**
|
||||
* 0: User Read Request is responded with data. In case of an error an application specific error
|
||||
* code can be sent.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attError;
|
||||
|
||||
/**
|
||||
* Data to send
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] value = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>userReadResponse</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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 []";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>userWriteResponse</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUserWriteResponseCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* 0: User Read Request is responded with data. In case of an error an application specific error
|
||||
* code can be sent.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int attError;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>userWriteResponse</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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 []";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.AttributeChangeReason;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>valueEvent</b>.
|
||||
* <p>
|
||||
* This event is produced at the GATT server when a local attribute value was written by a remote
|
||||
* device.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaValueEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* Reason why value has changed see: enum Attribute Change Reason
|
||||
* <p>
|
||||
* BlueGiga API type is <i>AttributeChangeReason</i> - Java type is {@link AttributeChangeReason}
|
||||
*/
|
||||
private AttributeChangeReason reason;
|
||||
|
||||
/**
|
||||
* Attribute handle, which was changed
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Offset into attribute value where data starts
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int offset;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reason why value has changed see: enum Attribute Change Reason
|
||||
* <p>
|
||||
* BlueGiga API type is <i>AttributeChangeReason</i> - Java type is {@link AttributeChangeReason}
|
||||
*
|
||||
* @return the current reason as {@link AttributeChangeReason}
|
||||
*/
|
||||
public AttributeChangeReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute handle, which was changed
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current handle as {@link int}
|
||||
*/
|
||||
public int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset into attribute value where data starts
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current offset as {@link int}
|
||||
*/
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>write</b>.
|
||||
* <p>
|
||||
* This command writes an attribute's value to the local database.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaWriteCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x02;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* Handle of the attribute to write.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int handle;
|
||||
|
||||
/**
|
||||
* Attribute offset to write data
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int offset;
|
||||
|
||||
/**
|
||||
* Value of the attribute to write
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] value = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.attributedb;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>write</b>.
|
||||
* <p>
|
||||
* This command writes an attribute's value to the local database.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>channelMapGet</b>.
|
||||
* <p>
|
||||
* This command can be used to read the current Channel Map.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaChannelMapGetCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>channelMapGet</b>.
|
||||
* <p>
|
||||
* This command can be used to read the current Channel Map.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaChannelMapGetResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>connectionStatusEvent</b>.
|
||||
* <p>
|
||||
* This event indicates the connection status and parameters.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaConnectionStatusEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* Connection status flags use connstatus-enumerator
|
||||
* <p>
|
||||
* BlueGiga API type is <i>ConnectionStatusFlag</i> - Java type is {@link ConnectionStatusFlag}
|
||||
* Parameter allows multiple options so implemented as a {@link Set}.
|
||||
*/
|
||||
private Set<ConnectionStatusFlag> flags = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Remote devices Bluetooth address
|
||||
* <p>
|
||||
* BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* Remote address type see: Bluetooth Address Types--gap
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
|
||||
*/
|
||||
private BluetoothAddressType addressType;
|
||||
|
||||
/**
|
||||
* Current connection interval (units of 1.25ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int connInterval;
|
||||
|
||||
/**
|
||||
* Current supervision timeout (units of 10ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* Slave latency which tells how many connection intervals the slave may skip.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int latency;
|
||||
|
||||
/**
|
||||
* Bonding handle if the device has been bonded with. Otherwise: 0xFF
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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 status flags use connstatus-enumerator
|
||||
* <p>
|
||||
* BlueGiga API type is <i>ConnectionStatusFlag</i> - Java type is {@link ConnectionStatusFlag}
|
||||
*
|
||||
* @return the current flags as {@link Set} of {@link ConnectionStatusFlag}
|
||||
*/
|
||||
public Set<ConnectionStatusFlag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote devices Bluetooth address
|
||||
* <p>
|
||||
* BlueGiga API type is <i>bd_addr</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BluetoothAddressType</i> - 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)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current conn_interval as {@link int}
|
||||
*/
|
||||
public int getConnInterval() {
|
||||
return connInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current supervision timeout (units of 10ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>disconnect</b>.
|
||||
* <p>
|
||||
* This command disconnects an active connection. Bluetooth When link is disconnected a
|
||||
* Disconnected event is produced.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaDisconnectCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
private BlueGigaDisconnectCommand(CommandBuilder builder) {
|
||||
super.setConnection(builder.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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int connection;
|
||||
|
||||
/**
|
||||
* Set connection handle.
|
||||
*
|
||||
* @param connection the connection to set as {@link int}
|
||||
*/
|
||||
public final CommandBuilder withConnection(int connection) {
|
||||
this.connection = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaDisconnectCommand build() {
|
||||
return new BlueGigaDisconnectCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>disconnect</b>.
|
||||
* <p>
|
||||
* This command disconnects an active connection. Bluetooth When link is disconnected a
|
||||
* Disconnected event is produced.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaDisconnectResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* 0 : the update was successful. Non-zero: An error occurred.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the update was successful. Non-zero: An error occurred.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>disconnectedEvent</b>.
|
||||
* <p>
|
||||
* This event is produced when a connection is disconnected.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaDisconnectedEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* Disconnection reason code. 0 : disconnected by local user
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnection reason code. 0 : disconnected by local user
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>featureIndEvent</b>.
|
||||
* <p>
|
||||
* This event indicates the remote devices features.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaFeatureIndEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* CtrData field from LL_FEATURE_RSP - packet
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* CtrData field from LL_FEATURE_RSP - packet
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>getRssi</b>.
|
||||
* <p>
|
||||
* This command disconnects an active connection. Bluetooth When link is disconnected a
|
||||
* Disconnected event is produced.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaGetRssiCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>getRssi</b>.
|
||||
* <p>
|
||||
* This command disconnects an active connection. Bluetooth When link is disconnected a
|
||||
* Disconnected event is produced.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaGetRssiResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* RSSI value of the connection in dBm. Range: -103 to -38
|
||||
* <p>
|
||||
* BlueGiga API type is <i>int8</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* RSSI value of the connection in dBm. Range: -103 to -38
|
||||
* <p>
|
||||
* BlueGiga API type is <i>int8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>getStatus</b>.
|
||||
* <p>
|
||||
* This command returns the status of the given connection. Status is returned in a event.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaGetStatusCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x07;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>getStatus</b>.
|
||||
* <p>
|
||||
* This command returns the status of the given connection. Status is returned in a event.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaGetStatusResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x07;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("BlueGigaGetStatusResponse [connection=");
|
||||
builder.append(connection);
|
||||
builder.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>update</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUpdateCommand extends BlueGigaDeviceCommand {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* Minimum connection interval (units of 1.25ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int intervalMin;
|
||||
|
||||
/**
|
||||
* Maximum connection interval (units of 1.25ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int intervalMax;
|
||||
|
||||
/**
|
||||
* Slave latency which defines how many connections intervals a slave may skip.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int latency;
|
||||
|
||||
/**
|
||||
* Supervision timeout (units of 10ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>update</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaUpdateResponse extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
/**
|
||||
* 0 : the update was successful. Non-zero: An error occurred.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 : the update was successful. Non-zero: An error occurred.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>versionIndEvent</b>.
|
||||
* <p>
|
||||
* This event indicates the remote devices version.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaVersionIndEvent extends BlueGigaDeviceResponse {
|
||||
public static int COMMAND_CLASS = 0x03;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
/**
|
||||
* Bluetooth controller specification version
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int versNr;
|
||||
|
||||
/**
|
||||
* Manufacturer of the controller
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int compId;
|
||||
|
||||
/**
|
||||
* Bluetooth controller version
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bluetooth controller specification version
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current vers_nr as {@link int}
|
||||
*/
|
||||
public int getVersNr() {
|
||||
return versNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manufacturer of the controller
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current comp_id as {@link int}
|
||||
*/
|
||||
public int getCompId() {
|
||||
return compId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bluetooth controller version
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>connectDirect</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaConnectDirectCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x06;
|
||||
public static int COMMAND_METHOD = 0x03;
|
||||
|
||||
private BlueGigaConnectDirectCommand(CommandBuilder builder) {
|
||||
this.address = builder.address;
|
||||
this.addrType = builder.addrType;
|
||||
this.connIntervalMin = builder.connIntervalMin;
|
||||
this.connIntervalMax = builder.connIntervalMax;
|
||||
this.timeout = builder.timeout;
|
||||
this.latency = builder.latency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bluetooth address of the target device.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* see: Bluetooth Address Types.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BluetoothAddressType</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private String address = "";
|
||||
private BluetoothAddressType addrType = BluetoothAddressType.UNKNOWN;
|
||||
private int connIntervalMin;
|
||||
private int connIntervalMax;
|
||||
private int timeout;
|
||||
private int latency;
|
||||
|
||||
/**
|
||||
* Bluetooth address of the target device.
|
||||
*
|
||||
* @param address the address to set as {@link String}
|
||||
*/
|
||||
public CommandBuilder withAddress(String address) {
|
||||
this.address = address;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* see: Bluetooth Address Types.
|
||||
*
|
||||
* @param addrType the addrType to set as {@link BluetoothAddressType}
|
||||
*/
|
||||
public CommandBuilder withAddrType(BluetoothAddressType addrType) {
|
||||
this.addrType = addrType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withConnIntervalMin(int connIntervalMin) {
|
||||
this.connIntervalMin = connIntervalMin;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withConnIntervalMax(int connIntervalMax) {
|
||||
this.connIntervalMax = connIntervalMax;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withLatency(int latency) {
|
||||
this.latency = latency;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaConnectDirectCommand build() {
|
||||
return new BlueGigaConnectDirectCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>connectDirect</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*/
|
||||
private BgApiResponse result;
|
||||
|
||||
/**
|
||||
* Connection handle that is reserved for new connection
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>connectSelective</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>connectSelective</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - Java type is {@link BgApiResponse}
|
||||
*/
|
||||
private BgApiResponse result;
|
||||
|
||||
/**
|
||||
* Connection handle that is reserved for new connection
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverMode;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>discover</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaDiscoverCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x06;
|
||||
public static int COMMAND_METHOD = 0x02;
|
||||
|
||||
private BlueGigaDiscoverCommand(CommandBuilder builder) {
|
||||
this.mode = builder.mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* see:GAP Discover Mode.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>GapDiscoverMode</i> - Java type is {@link GapDiscoverMode}
|
||||
*/
|
||||
private GapDiscoverMode 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private GapDiscoverMode mode = GapDiscoverMode.UNKNOWN;
|
||||
|
||||
/**
|
||||
* see:GAP Discover Mode.
|
||||
*
|
||||
* @param mode the mode to set as {@link GapDiscoverMode}
|
||||
*/
|
||||
public CommandBuilder withMode(GapDiscoverMode mode) {
|
||||
this.mode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaDiscoverCommand build() {
|
||||
return new BlueGigaDiscoverCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>discover</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>endProcedure</b>.
|
||||
* <p>
|
||||
* This command ends the current GAP discovery procedure and stop the scanning of advertising
|
||||
* devices.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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 []";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>endProcedure</b>.
|
||||
* <p>
|
||||
* This command ends the current GAP discovery procedure and stop the scanning of advertising
|
||||
* devices.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ScanResponseType;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>scanResponseEvent</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaScanResponseEvent extends BlueGigaResponse {
|
||||
public static int COMMAND_CLASS = 0x06;
|
||||
public static int COMMAND_METHOD = 0x00;
|
||||
|
||||
/**
|
||||
* RSSI value (dBm). Range: -103 to -38
|
||||
* <p>
|
||||
* BlueGiga API type is <i>int8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>ScanResponseType</i> - Java type is {@link ScanResponseType}
|
||||
*/
|
||||
private ScanResponseType packetType;
|
||||
|
||||
/**
|
||||
* Advertisers address
|
||||
* <p>
|
||||
* BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
|
||||
*/
|
||||
private String sender;
|
||||
|
||||
/**
|
||||
* Advertiser address type. 1: random address. 0: public address
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
|
||||
*/
|
||||
private BluetoothAddressType addressType;
|
||||
|
||||
/**
|
||||
* Bond handle if there is known bond for this device, 0xff otherwise
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int bond;
|
||||
|
||||
/**
|
||||
* Scan response data
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>int8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>ScanResponseType</i> - Java type is {@link ScanResponseType}
|
||||
*
|
||||
* @return the current packet_type as {@link ScanResponseType}
|
||||
*/
|
||||
public ScanResponseType getPacketType() {
|
||||
return packetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advertisers address
|
||||
* <p>
|
||||
* BlueGiga API type is <i>bd_addr</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BluetoothAddressType</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current bond as {@link int}
|
||||
*/
|
||||
public int getBond() {
|
||||
return bond;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan response data
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setAdvData</b>.
|
||||
* <p>
|
||||
* 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].
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int setScanrsp;
|
||||
|
||||
/**
|
||||
* Advertisement data to send
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
|
||||
*/
|
||||
private int[] advData = new int[0];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setAdvData</b>.
|
||||
* <p>
|
||||
* 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].
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setAdvParameters</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - Java type is {@link int}
|
||||
*/
|
||||
private int advIntervalMin;
|
||||
|
||||
/**
|
||||
* Maximum advertisement interval in units of 625us. Range: 0x20 to 0x4000. Default: 0x200
|
||||
* (320ms)
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setAdvParameters</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setMode</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaSetModeCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x06;
|
||||
public static int COMMAND_METHOD = 0x01;
|
||||
|
||||
private BlueGigaSetModeCommand(CommandBuilder builder) {
|
||||
this.discover = builder.discover;
|
||||
this.connect = builder.connect;
|
||||
}
|
||||
|
||||
/**
|
||||
* see:GAP Discoverable Mode
|
||||
* <p>
|
||||
* BlueGiga API type is <i>GapDiscoverableMode</i> - Java type is {@link GapDiscoverableMode}
|
||||
*/
|
||||
private GapDiscoverableMode discover;
|
||||
|
||||
/**
|
||||
* see:GAP Connectable Mode
|
||||
* <p>
|
||||
* BlueGiga API type is <i>GapConnectableMode</i> - Java type is {@link GapConnectableMode}
|
||||
*/
|
||||
private GapConnectableMode 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private GapDiscoverableMode discover = GapDiscoverableMode.UNKNOWN;
|
||||
private GapConnectableMode connect = GapConnectableMode.UNKNOWN;
|
||||
|
||||
/**
|
||||
* see:GAP Discoverable Mode
|
||||
*
|
||||
* @param discover the discover to set as {@link GapDiscoverableMode}
|
||||
*/
|
||||
public CommandBuilder withDiscover(GapDiscoverableMode discover) {
|
||||
this.discover = discover;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* see:GAP Connectable Mode
|
||||
*
|
||||
* @param connect the connect to set as {@link GapConnectableMode}
|
||||
*/
|
||||
public CommandBuilder withConnect(GapConnectableMode connect) {
|
||||
this.connect = connect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaSetModeCommand build() {
|
||||
return new BlueGigaSetModeCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setMode</b>.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setScanParameters</b>.
|
||||
* <p>
|
||||
* This command sets the scan parameters which affect how other Smart devices are discovered.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
* @author Pauli Anttila - Added message builder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaSetScanParametersCommand extends BlueGigaCommand {
|
||||
public static int COMMAND_CLASS = 0x06;
|
||||
public static int COMMAND_METHOD = 0x07;
|
||||
|
||||
private BlueGigaSetScanParametersCommand(CommandBuilder builder) {
|
||||
this.scanInterval = builder.scanInterval;
|
||||
this.scanWindow = builder.scanWindow;
|
||||
this.activeScanning = builder.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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint16</i> - 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.
|
||||
* <p>
|
||||
* BlueGiga API type is <i>boolean</i> - Java type is {@link boolean}
|
||||
*/
|
||||
private boolean 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();
|
||||
}
|
||||
|
||||
public static class CommandBuilder {
|
||||
private int scanInterval;
|
||||
private int scanWindow;
|
||||
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 CommandBuilder withScanInterval(int scanInterval) {
|
||||
this.scanInterval = scanInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withScanWindow(int scanWindow) {
|
||||
this.scanWindow = scanWindow;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CommandBuilder withActiveScanning(boolean activeScanning) {
|
||||
this.activeScanning = activeScanning;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlueGigaSetScanParametersCommand build() {
|
||||
return new BlueGigaSetScanParametersCommand(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.gap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BgApiResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>setScanParameters</b>.
|
||||
* <p>
|
||||
* This command sets the scan parameters which affect how other Smart devices are discovered.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>BgApiResponse</i> - 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* 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.openhab.binding.bluetooth.bluegiga.internal.command.security;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaResponse;
|
||||
|
||||
/**
|
||||
* Class to implement the BlueGiga command <b>bondStatusEvent</b>.
|
||||
* <p>
|
||||
* This event outputs bonding status information.
|
||||
* <p>
|
||||
* This class provides methods for processing BlueGiga API commands.
|
||||
* <p>
|
||||
* Note that this code is autogenerated. Manual changes may be overwritten.
|
||||
*
|
||||
* @author Chris Jackson - Initial contribution of Java code generator
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BlueGigaBondStatusEvent extends BlueGigaResponse {
|
||||
public static int COMMAND_CLASS = 0x05;
|
||||
public static int COMMAND_METHOD = 0x04;
|
||||
|
||||
/**
|
||||
* Bonding handle
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int bond;
|
||||
|
||||
/**
|
||||
* Encryption key size used in long-term key
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*/
|
||||
private int mitm;
|
||||
|
||||
/**
|
||||
* Keys stored for bonding. See: Bonding Keys
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - Java type is {@link int}
|
||||
*
|
||||
* @return the current mitm as {@link int}
|
||||
*/
|
||||
public int getMitm() {
|
||||
return mitm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keys stored for bonding. See: Bonding Keys
|
||||
* <p>
|
||||
* BlueGiga API type is <i>uint8</i> - 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();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user