QLowEnergyService:: writeCharacteristic takes a long time, how can it be shortened?
-
The following is my code that takes about 100ms or more between qDebug1 and qDebug2. Even if I reduce the amount of data sent, the time spent is not significantly reduced. How should I handle this?
int CommBluebooth::SendDataEx(const QByteArray i_data)
{
int maxBytes = 200;
int frames = (i_data.count() - 1) / maxBytes + 1;
for (int i = 0; i < frames; i++)
{
if (i_data.isNull() || i_data.isEmpty() || !IsConnect())
{
return 0;
}int sendlen = (i + 1 == frames) ? (i_data.count() - (i * maxBytes)): maxBytes; QByteArray sendData = i_data.mid(i * maxBytes, sendlen); if (m_service != nullptr) { QString str; str += QString("<%1> - ").arg(QTime::currentTime().toString("HH:mm:ss.zzz")); qDebug()<<"bluetooth strat sending:" << str; m_service->writeCharacteristic(m_writeCharacteristic, sendData, m_blueboothParam->writeMode); QString str2; str2 += QString("<%1> - ").arg(QTime::currentTime().toString("HH:mm:ss.zzz")); qDebug()<<"Bluetooth transmission completed:" << str2; } } return i_data.size();}