void BluetoothHandler::receiveHrNotifications() {

	qDebug() << "YYYY setting up to receive GATT notifications";

	if (!bt_initialised) {
		qDebug() << "Bluetooth libraries are not initialised!";
		return;
	}

	HrDataContainer* hrdc = HrDataContainer::getInstance();
	QString device_addr = hrdc->getCurrentDeviceAddr();
	QString device_name = hrdc->getCurrentDeviceName();
	hrdc->clearData();

	bt_gatt_conn_parm_t conParm;
	conParm.minConn = 0x30;
	conParm.maxConn = 0x50;
	conParm.latency = 0;
	conParm.superTimeout = 50;

	errno= 0;

	if (bt_gatt_connect_service(device_addr.toAscii().constData(), HR_SERVICE_UUID, NULL, &conParm, this) < 0) {
		qDebug() << "YYYY GATT connect service request failed: " + QString::number(errno) + " (" + QString(strerror(errno)) + ")";
	} else {
		qDebug() << "YYYY requested connection to HR service OK";
	}

}
void BluetoothHandler::receiveHrNotifications() {

	qDebug() << "YYYY setting up to receive GATT notifications";

	if (!bt_initialised) {
		qDebug() << "Bluetooth libraries are not initialised!";
		return;
	}

	HrDataContainer* hrdc = HrDataContainer::getInstance();
	QString device_addr = hrdc->getCurrentDeviceAddr();
	QString device_name = hrdc->getCurrentDeviceName();
	hrdc->clearData();

	bt_gatt_conn_parm_t conParm;
	conParm.minConn = 0x30;
	conParm.maxConn = 0x50;
	conParm.latency = 0;
	conParm.superTimeout = 50;

	errno= 0;

	if (bt_gatt_connect_service(device_addr.toAscii().constData(), HR_SERVICE_UUID, NULL, &conParm, this) < 0) {
		qDebug() << "YYYY GATT connect service request failed: " + QString::number(errno) + " (" + QString(strerror(errno)) + ")";
		// there's a known issue where sometimes we get ERRNO=EBUSY (16) when this is not the case and we've connected to the service OK. So for now we ignore this errno value.
		if (errno != 16) {
			Utilities::alert("GATT connect service request failed: " + QString::number(errno));
		}
	} else {
		qDebug() << "YYYY requested connection to HR service OK";
	}

}
void BluetoothHandler::stopHrNotifications() {

	errno= 0;

	HrDataContainer* hrdc = HrDataContainer::getInstance();
	QString device_addr = hrdc->getCurrentDeviceAddr();

	if (bt_gatt_disconnect_service(device_addr.toAscii().constData(), HR_SERVICE_UUID) < 0) {
		qDebug() << "YYYY GATT disconnect service request failed: " + QString::number(errno) + " (" + QString(strerror(errno)) + ")";
	} else {
		qDebug() << "YYYY disconnected from HR service OK";
	}

}