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);
134 QLowEnergyHandle handle)
136 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(handle);
137 if (service.isNull())
138 return QLowEnergyCharacteristic();
140 if (service->characteristicList.isEmpty())
141 return QLowEnergyCharacteristic();
144 if (service->characteristicList.contains(handle))
145 return QLowEnergyCharacteristic(service, handle);
148 QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
149 std::sort(charHandles.begin(), charHandles.end());
150 for (qsizetype i = charHandles.size() - 1; i >= 0; --i) {
151 if (charHandles.at(i) > handle)
154 return QLowEnergyCharacteristic(service, charHandles.at(i));
157 return QLowEnergyCharacteristic();
185 QLowEnergyHandle charHandle,
const QByteArray &value,
bool appendValue)
187 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
188 if (!service.isNull()) {
189 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
190 if (charIt != service->characteristicList.end()) {
194 charDetails.value += value;
196 charDetails.value = value;
198 return charDetails.value.size();
209 QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle,
210 const QByteArray &value,
bool appendValue)
212 QSharedPointer<QLowEnergyServicePrivate> service = serviceForHandle(charHandle);
213 if (!service.isNull()) {
214 CharacteristicDataMap::iterator charIt = service->characteristicList.find(charHandle);
215 if (charIt != service->characteristicList.end()) {
218 DescriptorDataMap::iterator descIt = charDetails.descriptorList.find(descriptorHandle);
219 if (descIt != charDetails.descriptorList.end()) {
223 descDetails.value += value;
225 descDetails.value = value;
227 return descDetails.value.size();
249 const QLowEnergyServiceData &service)
255 const auto servicePrivate = QSharedPointer<QLowEnergyServicePrivate>::create();
256 servicePrivate->setController(
this);
257 servicePrivate->state = QLowEnergyService::LocalService;
258 servicePrivate->uuid = service.uuid();
259 servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary
260 ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService;
261 const QList<QLowEnergyService *> includedServices = service.includedServices();
262 for (QLowEnergyService *
const includedService : includedServices) {
263 servicePrivate->includedServices << includedService->serviceUuid();
264 includedService->d_ptr->type |= QLowEnergyService::IncludedService;
268 const QLowEnergyHandle oldLastHandle =
this->lastLocalHandle;
269 servicePrivate->startHandle = ++
this->lastLocalHandle;
270 this->lastLocalHandle += servicePrivate->includedServices.size();
271 const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics();
272 for (
const QLowEnergyCharacteristicData &cd : characteristics) {
273 const QLowEnergyHandle declHandle = ++
this->lastLocalHandle;
274 QLowEnergyServicePrivate::CharData charData;
275 charData.valueHandle = ++
this->lastLocalHandle;
276 charData.uuid = cd.uuid();
277 charData.properties = cd.properties();
278 charData.value = cd.value();
279 const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors();
280 for (
const QLowEnergyDescriptorData &dd : descriptors) {
281 QLowEnergyServicePrivate::DescData descData;
282 descData.uuid = dd.uuid();
283 descData.value = dd.value();
284 charData.descriptorList.insert(++
this->lastLocalHandle, descData);
286 servicePrivate->characteristicList.insert(declHandle, charData);
288 servicePrivate->endHandle =
this->lastLocalHandle;
289 const bool handleOverflow =
this->lastLocalHandle <= oldLastHandle;
290 if (handleOverflow) {
291 qCWarning(QT_BT) <<
"Not enough attribute handles left to create this service";
292 this->lastLocalHandle = oldLastHandle;
296 if (localServices.contains(servicePrivate->uuid)) {
297 qCWarning(QT_BT) <<
"Overriding existing local service with uuid"
298 << servicePrivate->uuid;
300 this->localServices.insert(servicePrivate->uuid, servicePrivate);
302 this->addToGenericAttributeList(service, servicePrivate->startHandle);
303 return new QLowEnergyService(servicePrivate);