54 QLowEnergyController::Error newError)
56 Q_Q(QLowEnergyController);
60 case QLowEnergyController::UnknownRemoteDeviceError:
61 errorString = QLowEnergyController::tr(
"Remote device cannot be found");
63 case QLowEnergyController::InvalidBluetoothAdapterError:
64 errorString = QLowEnergyController::tr(
"Cannot find local adapter");
66 case QLowEnergyController::NetworkError:
67 errorString = QLowEnergyController::tr(
"Error occurred during connection I/O");
69 case QLowEnergyController::ConnectionError:
70 errorString = QLowEnergyController::tr(
"Error occurred trying to connect to remote device.");
72 case QLowEnergyController::AdvertisingError:
73 errorString = QLowEnergyController::tr(
"Error occurred trying to start advertising");
75 case QLowEnergyController::RemoteHostClosedError:
76 errorString = QLowEnergyController::tr(
"Remote device closed the connection");
78 case QLowEnergyController::AuthorizationError:
79 errorString = QLowEnergyController::tr(
"Failed to authorize on the remote device");
81 case QLowEnergyController::MissingPermissionsError:
82 errorString = QLowEnergyController::tr(
"Missing permissions error");
84 case QLowEnergyController::RssiReadError:
85 errorString = QLowEnergyController::tr(
"Error reading RSSI value");
87 case QLowEnergyController::NoError:
90 case QLowEnergyController::UnknownError:
91 errorString = QLowEnergyController::tr(
"Unknown Error");
95 emit q->errorOccurred(newError);
135 QLowEnergyHandle handle)
137 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(handle);
138 if (service.isNull())
139 return QLowEnergyCharacteristic();
141 if (service->characteristicList.isEmpty())
142 return QLowEnergyCharacteristic();
145 if (service->characteristicList.contains(handle))
146 return QLowEnergyCharacteristic(service, handle);
149 QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
150 std::sort(charHandles.begin(), charHandles.end());
151 for (qsizetype i = charHandles.size() - 1; i >= 0; --i) {
152 if (charHandles.at(i) > handle)
155 return QLowEnergyCharacteristic(service, charHandles.at(i));
158 return QLowEnergyCharacteristic();
186 QLowEnergyHandle charHandle,
const QByteArray &value,
bool appendValue)
188 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
189 if (!service.isNull()) {
190 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
191 if (charIt != service->characteristicList.end()) {
195 charDetails.value += value;
197 charDetails.value = value;
199 return charDetails.value.size();
210 QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle,
211 const QByteArray &value,
bool appendValue)
213 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
214 if (!service.isNull()) {
215 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
216 if (charIt != service->characteristicList.end()) {
219 DescriptorDataMap::iterator descIt = charDetails.descriptorList.find(descriptorHandle);
220 if (descIt != charDetails.descriptorList.end()) {
224 descDetails.value += value;
226 descDetails.value = value;
228 return descDetails.value.size();
250 const QLowEnergyServiceData &service)
256 const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create();
257 servicePrivate->setController(
this);
258 servicePrivate->state = QLowEnergyService::LocalService;
259 servicePrivate->uuid = service.uuid();
260 servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary
261 ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService;
262 const QList<QLowEnergyService *> includedServices = service.includedServices();
263 for (QLowEnergyService *
const includedService : includedServices) {
264 servicePrivate->includedServices << includedService->serviceUuid();
265 includedService->d_ptr->type |= QLowEnergyService::IncludedService;
269 const QLowEnergyHandle oldLastHandle =
this->lastLocalHandle;
270 servicePrivate->startHandle = ++
this->lastLocalHandle;
271 this->lastLocalHandle += servicePrivate->includedServices.size();
272 const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics();
273 for (
const QLowEnergyCharacteristicData &cd : characteristics) {
274 const QLowEnergyHandle declHandle = ++
this->lastLocalHandle;
275 QLowEnergyServicePrivate::CharData charData;
276 charData.valueHandle = ++
this->lastLocalHandle;
277 charData.uuid = cd.uuid();
278 charData.properties = cd.properties();
279 charData.value = cd.value();
280 const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors();
281 for (
const QLowEnergyDescriptorData &dd : descriptors) {
282 QLowEnergyServicePrivate::DescData descData;
283 descData.uuid = dd.uuid();
284 descData.value = dd.value();
285 charData.descriptorList.insert(++
this->lastLocalHandle, descData);
287 servicePrivate->characteristicList.insert(declHandle, charData);
289 servicePrivate->endHandle =
this->lastLocalHandle;
290 const bool handleOverflow =
this->lastLocalHandle <= oldLastHandle;
291 if (handleOverflow) {
292 qCWarning(QT_BT) <<
"Not enough attribute handles left to create this service";
293 this->lastLocalHandle = oldLastHandle;
297 if (localServices.contains(servicePrivate->uuid)) {
298 qCWarning(QT_BT) <<
"Overriding existing local service with uuid"
299 << servicePrivate->uuid;
301 this->localServices.insert(servicePrivate->uuid, servicePrivate);
303 this->addToGenericAttributeList(service, servicePrivate->startHandle);
304 return new QLowEnergyService(servicePrivate);