diff --git a/ground/src/plugins/uavtalk/uavtalk.cpp b/ground/src/plugins/uavtalk/uavtalk.cpp index ac160c920..e99051c25 100644 --- a/ground/src/plugins/uavtalk/uavtalk.cpp +++ b/ground/src/plugins/uavtalk/uavtalk.cpp @@ -568,8 +568,16 @@ bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstance cs = updateChecksum(cs, txBuffer, dataOffset+length); qToLittleEndian(cs, &txBuffer[dataOffset+length]); - // Send buffer - io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH); + // Send buffer, check that the transmit backlog does not grow above limit + if ( io->bytesToWrite() < TX_BUFFER_SIZE ) + { + io->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH); + } + else + { + ++stats.txErrors; + return false; + } // Update stats ++stats.txObjects; diff --git a/ground/src/plugins/uavtalk/uavtalk.h b/ground/src/plugins/uavtalk/uavtalk.h index d2c9b721b..655ec957b 100644 --- a/ground/src/plugins/uavtalk/uavtalk.h +++ b/ground/src/plugins/uavtalk/uavtalk.h @@ -77,6 +77,7 @@ private: static const int MAX_PAYLOAD_LENGTH = 256; static const int MAX_PACKET_LENGTH = (HEADER_LENGTH+MAX_PAYLOAD_LENGTH+CHECKSUM_LENGTH); static const quint16 ALL_INSTANCES = 0xFFFF; + static const int TX_BUFFER_SIZE = 2*1024; typedef enum {STATE_SYNC, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS} RxStateType;