/* Copyright (C) 2022-2024 Damien Gaignon
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
* In contrast to {@link #performInitialized(String)}, no initialization sequence is performed * with the device, only the actions of the given builder are executed. * @param transaction * @throws IOException if connection to the device fails * @see #performInitialized(String) */ public void performConnected(Transaction transaction) throws IOException { if (!isConnected()) { if (!connect()) { throw new IOException("2: Unable to connect to device: " + getDevice()); } } getQueue().add(transaction); } public BtBRQueue getQueue() { return mQueue; } /** * Subclasses should call this method to add services they support. * Only supported services will be queried for characteristics. * * @param aSupportedService the supported service uuid */ protected void addSupportedService(UUID aSupportedService) { mSupportedService = aSupportedService; } protected UUID getSupportedService() { return mSupportedService; } protected void setBufferSize(int bufferSize) { mBufferSize = bufferSize; } protected int getBufferSize() { return mBufferSize; } /** * Utility method that may be used to log incoming messages when we don't know how to deal with them yet. */ public void logMessageContent(byte[] value) { logger.info("RECEIVED DATA WITH LENGTH: {}", (value != null) ? value.length : "(null)"); Logging.logBytes(logger, value); } public void onConnectionEstablished() { try { initializeDevice(createTransactionBuilder("Initializing device")).queue(getQueue()); } catch (final Exception ex) { final GBDevice device = getDevice(); if (device != null) { logger.error("Exception raised while initializing device {} (address {}), disconnecting", device.getName(), device.getAddress(), ex); device.setState(GBDevice.State.WAITING_FOR_RECONNECT); device.sendDeviceUpdateIntent(getContext()); } else { logger.error("Exception raised while initializing unknown device", ex); } } } }