gpt4 book ai didi

linux - QT 低能耗 Controller 外设模式崩溃并出现错误 "Resource not available"

转载 作者:行者123 更新时间:2023-12-02 22:54:21 27 4
gpt4 key购买 nike

更新:

Qt版本:5.11

平台:树莓派3

操作系统:Rasbpian

我正在将我的 Linux Qt BLE 应用程序连接到 IOS 中央设备。它在大多数情况下工作正常,但有时会因以下错误而崩溃

qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 29 error: -1 "Resource temporarily unavailable"

这是代码和底层场景。

我有一个运行 Qt 5.11 的 raspberrypi,并且我创建了一个 BLE 低功耗外围设备,用于连接到 IOS 应用程序并发送和接收数据。

声明:

QLowEnergyCharacteristicData ReadCharacteristicData,
WriteCharactersiticData,
ConnectivityData,
TrackerData_Data;

QLowEnergyCharacteristic charas;

QLowEnergyDescriptorData ReadCharacteristicDesc,
WriteCharactersiticDesc,
ConnectivityDesc,
TrackerDesc;

QLowEnergyServiceData serviceData;

QScopedPointer<QLowEnergyController> leController;
QScopedPointer<QLowEnergyService> service;


服务初始化:`


Here I am initializing bluetooth service
//! [Advertising Data]

advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
advertisingData.setLocalName("Atlas360Dev");
advertisingData.setServices(QList<QBluetoothUuid>()<<QBluetoothUuid::Atlas);

// For IOS its readonly and for Atlas its write only
ReadCharacteristicData.setUuid(QBluetoothUuid::ReadCharacteristic);
ReadCharacteristicData.setProperties(QLowEnergyCharacteristic::Notify);
ReadCharacteristicDesc.setUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
ReadCharacteristicDesc.setValue(QByteArray(2,0));
ReadCharacteristicData.addDescriptor(ReadCharacteristicDesc);


// For IOS its write only characteristic and for Atlas its read only
WriteCharactersiticData.setUuid(QBluetoothUuid::WriteCharacteristic);
WriteCharactersiticData.setProperties(QLowEnergyCharacteristic::Write |QLowEnergyCharacteristic::Notify);
WriteCharactersiticDesc.setUuid(QBluetoothUuid::AtlasDescriptor);
WriteCharactersiticDesc.setValue(QByteArray::fromHex("Write").toHex());
WriteCharactersiticData.addDescriptor(WriteCharactersiticDesc);

// For IOS its readonly and for Atlas its write only
ConnectivityData.setUuid(QBluetoothUuid::Connectivity);
ConnectivityData.setProperties(QLowEnergyCharacteristic::Notify);
ConnectivityDesc.setUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
ConnectivityDesc.setValue(QByteArray(2, 0));
ConnectivityData.addDescriptor(ConnectivityDesc);


// For IOS its write only characteristic and for Atlas its read only
TrackerData_Data.setUuid(QBluetoothUuid::TrackingData);
TrackerData_Data.setProperties(QLowEnergyCharacteristic::Notify);
TrackerDesc.setUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
TrackerDesc.setValue(QByteArray(2, 0));
TrackerData_Data.addDescriptor(TrackerDesc);



serviceData.setType(QLowEnergyServiceData::ServiceTypePrimary);
serviceData.setUuid(QBluetoothUuid::Atlas);

serviceData.addCharacteristic(ReadCharacteristicData);
serviceData.addCharacteristic(WriteCharactersiticData);
serviceData.addCharacteristic(ConnectivityData);
serviceData.addCharacteristic(TrackerData_Data);


leController.reset(QLowEnergyController::createPeripheral());




// leController->addService(serviceData) will return a pointer to service object
service.reset(leController->addService(serviceData));

leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData,advertisingData);



connect(&heartbeatTimer, &QTimer::timeout,this, &mainprocess::TickProvider);
connect(leController.data(), &QLowEnergyController::disconnected,this,&mainprocess::reconnect);
connect(service.data(),&QLowEnergyService::characteristicChanged,this,&mainprocess::printvalue);

heartbeatTimer.start(30);


///////////////////////////////////////
This sends data to IOS app every 30ms
///////////////////////////////////////

void mainprocess::TickProvider ()
{

if(Tracker.isRunning())

{
// sending Tracker Data
I have ommitted the code


QLowEnergyCharacteristic Charac_1 = service->characteristic(QBluetoothUuid::TrackingData);
service->writeCharacteristic(Charac_1,trackingdata);

}


// Sending Connectivity Status
QByteArray connectivity;

QLowEnergyCharacteristic Charac_2 = service->characteristic(QBluetoothUuid::Connectivity);
service->writeCharacteristic(Charac_2,connectivity);

}

//////////////////////////////////////////////////////////
Here I receive commands from IOS and respond accordingly
/////////////////////////////////////////////////////////

void mainprocess::printvalue(const QLowEnergyCharacteristic &info, const QByteArray &ba){


if (info.uuid()== QBluetoothUuid(QBluetoothUuid::WriteCharacteristic)){


// Username
if(ba.at(0)==0xA1){

}

// Password
if(ba.at(0)==0xA2){

}

// Tour Title
if(ba.at(0)==0xA3){

}

// Section Title
if(ba.at(0)==0xA4){

}

// Distance Interval
if(ba.at(0)==0xA7){

}

// Countdown
if(ba.at(0)==0xA8){

}

// Address
if(ba.at(0)==0xA9){

}

// Address Upload Later
if(ba.at(0)==0xA5){

}

// Mode
if(ba.at(0)==0xAA){

}

}
}

/////////////////////
Reconnect Function
////////////////////

void mainprocess::reconnect()
{
qDebug()<<"Reconnect Called";
//initializeBluetooth();

// connect(leController.data(), &QLowEnergyController::disconnected,this,&mainprocess::reconnect);

service.reset(leController->addService(serviceData));
connect(service.data(),&QLowEnergyService::characteristicChanged,this,&mainprocess::printvalue);
if (service!=nullptr)
leController->startAdvertising(QLowEnergyAdvertisingParameters(),
advertisingData,advertisingData);//, advertisingData);

}

最佳答案

在 BLE 扫描期间,同样的情况也发生在我身上。设备似乎因某种原因关闭(可以通过 hcitool 命令进行调查 - 在 Linux 平台上)

您应该将插槽连接到以下信号:

QBluetoothDeviceDiscoveryAgent::error(QBluetoothDeviceDiscoveryAgent::Error)

您可能会发现您的设备已关闭。

在这种情况下,请检查以下内容:

QBluetoothLocalDevice::hostMode()

如果它返回QBluetoothLocalDevice::HostPoweredOff,只需执行:

your_bluetooth_local_device->powerOn();

无论如何:请添加一个完整的示例,说明您实际在做什么、使用的 Qt 版本、平台。

关于linux - QT 低能耗 Controller 外设模式崩溃并出现错误 "Resource not available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59041899/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com