1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

UAVTalk, change private member QIODevice* io to smart pointer QPointer<QIODevice>

This commit is contained in:
Mike LaBranche 2012-06-13 14:57:43 -07:00
parent 295fa4a8f3
commit 8283d4280e
2 changed files with 10 additions and 8 deletions

View File

@ -112,10 +112,12 @@ void UAVTalk::processInputStream()
{
quint8 tmp;
while (io->bytesAvailable() > 0)
{
io->read((char*)&tmp, 1);
processInputByte(tmp);
if (io && io->isReadable()) {
while (io->bytesAvailable() > 0)
{
io->read((char*)&tmp, 1);
processInputByte(tmp);
}
}
}
@ -719,9 +721,8 @@ bool UAVTalk::transmitNack(quint32 objId)
qToLittleEndian<quint16>(dataOffset, &txBuffer[2]);
// Send buffer, check that the transmit backlog does not grow above limit
if ( io->bytesToWrite() < TX_BUFFER_SIZE )
if (io && io->isWritable() && io->bytesToWrite() < TX_BUFFER_SIZE )
{
io->write((const char*)txBuffer, dataOffset+CHECKSUM_LENGTH);
}
@ -811,7 +812,7 @@ bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstance
txBuffer[dataOffset+length] = updateCRC(0, txBuffer, dataOffset + length);
// Send buffer, check that the transmit backlog does not grow above limit
if ( io->bytesToWrite() < TX_BUFFER_SIZE )
if (io && io->isWritable() && io->bytesToWrite() < TX_BUFFER_SIZE )
{
io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
}

View File

@ -27,6 +27,7 @@
#ifndef UAVTALK_H
#define UAVTALK_H
#include <QtCore>
#include <QIODevice>
#include <QMutex>
#include <QMutexLocker>
@ -93,7 +94,7 @@ private:
typedef enum {STATE_SYNC, STATE_TYPE, STATE_SIZE, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;
// Variables
QIODevice* io;
QPointer<QIODevice> io;
UAVObjectManager* objMngr;
QMutex* mutex;
UAVObject* respObj;