49 QLowEnergyController::Error newError)
51 Q_Q(QLowEnergyController);
55 case QLowEnergyController::UnknownRemoteDeviceError:
56 errorString = QLowEnergyController::tr(
"Remote device cannot be found");
58 case QLowEnergyController::InvalidBluetoothAdapterError:
59 errorString = QLowEnergyController::tr(
"Cannot find local adapter");
61 case QLowEnergyController::NetworkError:
62 errorString = QLowEnergyController::tr(
"Error occurred during connection I/O");
64 case QLowEnergyController::ConnectionError:
65 errorString = QLowEnergyController::tr(
"Error occurred trying to connect to remote device.");
67 case QLowEnergyController::AdvertisingError:
68 errorString = QLowEnergyController::tr(
"Error occurred trying to start advertising");
70 case QLowEnergyController::RemoteHostClosedError:
71 errorString = QLowEnergyController::tr(
"Remote device closed the connection");
73 case QLowEnergyController::AuthorizationError:
74 errorString = QLowEnergyController::tr(
"Failed to authorize on the remote device");
76 case QLowEnergyController::MissingPermissionsError:
77 errorString = QLowEnergyController::tr(
"Missing permissions error");
79 case QLowEnergyController::RssiReadError:
80 errorString = QLowEnergyController::tr(
"Error reading RSSI value");
82 case QLowEnergyController::NoError:
85 case QLowEnergyController::UnknownError:
86 errorString = QLowEnergyController::tr(
"Unknown Error");
90 emit q->errorOccurred(newError);
129 QLowEnergyHandle handle)
131 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(handle);
132 if (service.isNull())
133 return QLowEnergyCharacteristic();
135 if (service->characteristicList.isEmpty())
136 return QLowEnergyCharacteristic();
139 if (service->characteristicList.contains(handle))
140 return QLowEnergyCharacteristic(service, handle);
143 QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
144 std::sort(charHandles.begin(), charHandles.end());
145 for (qsizetype i = charHandles.size() - 1; i >= 0; --i) {
146 if (charHandles.at(i) > handle)
149 return QLowEnergyCharacteristic(service, charHandles.at(i));
152 return QLowEnergyCharacteristic();
180 QLowEnergyHandle charHandle,
const QByteArray &value,
bool appendValue)
182 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
183 if (!service.isNull()) {
184 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
185 if (charIt != service->characteristicList.end()) {
189 charDetails.value += value;
191 charDetails.value = value;
193 return charDetails.value.size();
204 QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle,
205 const QByteArray &value,
bool appendValue)
207 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
208 if (!service.isNull()) {
209 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
210 if (charIt != service->characteristicList.end()) {
213 DescriptorDataMap::iterator descIt = charDetails.descriptorList.find(descriptorHandle);
214 if (descIt != charDetails.descriptorList.end()) {
218 descDetails.value += value;
220 descDetails.value = value;
222 return descDetails.value.size();
244 const QLowEnergyServiceData &service)
250 const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create();
251 servicePrivate->setController(
this);
252 servicePrivate->state = QLowEnergyService::LocalService;
253 servicePrivate->uuid = service.uuid();
254 servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary
255 ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService;
256 const QList<QLowEnergyService *> includedServices = service.includedServices();
257 for (QLowEnergyService *
const includedService : includedServices) {
258 servicePrivate->includedServices << includedService->serviceUuid();
259 includedService->d_ptr->type |= QLowEnergyService::IncludedService;
263 const QLowEnergyHandle oldLastHandle =
this->lastLocalHandle;
264 servicePrivate->startHandle = ++
this->lastLocalHandle;
265 this->lastLocalHandle += servicePrivate->includedServices.size();
266 const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics();
267 for (
const QLowEnergyCharacteristicData &cd : characteristics) {
268 const QLowEnergyHandle declHandle = ++
this->lastLocalHandle;
269 QLowEnergyServicePrivate::CharData charData;
270 charData.valueHandle = ++
this->lastLocalHandle;
271 charData.uuid = cd.uuid();
272 charData.properties = cd.properties();
273 charData.value = cd.value();
274 const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors();
275 for (
const QLowEnergyDescriptorData &dd : descriptors) {
276 QLowEnergyServicePrivate::DescData descData;
277 descData.uuid = dd.uuid();
278 descData.value = dd.value();
279 charData.descriptorList.insert(++
this->lastLocalHandle, descData);
281 servicePrivate->characteristicList.insert(declHandle, charData);
283 servicePrivate->endHandle =
this->lastLocalHandle;
284 const bool handleOverflow =
this->lastLocalHandle <= oldLastHandle;
285 if (handleOverflow) {
286 qCWarning(QT_BT) <<
"Not enough attribute handles left to create this service";
287 this->lastLocalHandle = oldLastHandle;
291 if (localServices.contains(servicePrivate->uuid)) {
292 qCWarning(QT_BT) <<
"Overriding existing local service with uuid"
293 << servicePrivate->uuid;
295 this->localServices.insert(servicePrivate->uuid, servicePrivate);
297 this->addToGenericAttributeList(service, servicePrivate->startHandle);
298 return new QLowEnergyService(servicePrivate);