use of org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand in project smarthome by eclipse.
the class BlueGigaBridgeHandler method initialize.
@Override
public void initialize() {
Object discovery = getConfig().get(BlueGigaAdapterConstants.PROPERTY_DISCOVERY);
if (discovery != null && discovery.toString().equalsIgnoreCase(Boolean.FALSE.toString())) {
discoveryActive = false;
logger.debug("Deactivated discovery participation.");
}
final String portId = (String) getConfig().get(BlueGigaAdapterConstants.CONFIGURATION_PORT);
if (portId == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Serial port must be configured!");
return;
}
if (openSerialPort(portId, 115200)) {
BlueGigaSerialHandler bgh = new BlueGigaSerialHandler(inputStream, outputStream);
// Create and send the reset command to the dongle
bgh.addEventListener(this);
bgh.addHandlerListener(this);
this.setBgHandler(bgh);
updateStatus(ThingStatus.UNKNOWN);
scheduler.submit(() -> {
// Stop any procedures that are running
bgStopProcedure();
// Close all transactions
BlueGigaCommand command = new BlueGigaGetConnectionsCommand();
BlueGigaGetConnectionsResponse connectionsResponse = (BlueGigaGetConnectionsResponse) bgh.sendTransaction(command);
if (connectionsResponse != null) {
maxConnections = connectionsResponse.getMaxconn();
}
// Close all connections so we start from a known position
for (int connection = 0; connection < maxConnections; connection++) {
bgDisconnect(connection);
}
// Get our Bluetooth address
command = new BlueGigaAddressGetCommand();
BlueGigaAddressGetResponse addressResponse = (BlueGigaAddressGetResponse) bgh.sendTransaction(command);
if (addressResponse != null) {
address = new BluetoothAddress(addressResponse.getAddress());
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE);
}
command = new BlueGigaGetInfoCommand();
BlueGigaGetInfoResponse infoResponse = (BlueGigaGetInfoResponse) bgh.sendTransaction(command);
// Set mode to non-discoverable etc.
// Not doing this will cause connection failures later
bgSetMode();
// Start passive scan
bgStartScanning(false, passiveScanInterval, passiveScanWindow);
Map<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);
});
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, "Failed opening serial port.");
}
}
use of org.eclipse.smarthome.binding.bluetooth.bluegiga.internal.BlueGigaCommand in project smarthome by eclipse.
the class BlueGigaBridgeHandler method bgStopProcedure.
/*
* The following methods are private methods for handling the BlueGiga protocol
*/
private boolean bgStopProcedure() {
BlueGigaCommand command = new BlueGigaEndProcedureCommand();
BlueGigaEndProcedureResponse response = (BlueGigaEndProcedureResponse) getBgHandler().sendTransaction(command);
return response.getResult() == BgApiResponse.SUCCESS;
}
Aggregations