From afb134b91558869d80f617bec4da35ade0a3ce11 Mon Sep 17 00:00:00 2001 From: "james.goppert" Date: Thu, 11 Nov 2010 02:42:43 +0000 Subject: [PATCH] Added buffersize member to BinComm. git-svn-id: https://arducopter.googlecode.com/svn/trunk@824 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/APM_BinComm/APM_BinComm.cpp | 9 +++++---- libraries/APM_BinComm/APM_BinComm.h | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/APM_BinComm/APM_BinComm.cpp b/libraries/APM_BinComm/APM_BinComm.cpp index 3bb68b8c77..1280ca04ff 100644 --- a/libraries/APM_BinComm/APM_BinComm.cpp +++ b/libraries/APM_BinComm/APM_BinComm.cpp @@ -45,10 +45,11 @@ #define DEC_MESSAGE_TIMEOUT 1000 BinComm::BinComm(const BinComm::MessageHandler *handlerTable, - Stream *interface) : + uint16_t rxBufferSize, Stream *interface) : _handlerTable(handlerTable), _decodePhase(DEC_WAIT_P1), - _lastReceived(millis()) + _lastReceived(millis()), + _rxBufferSize(rxBufferSize) { init(interface); }; @@ -98,10 +99,10 @@ BinComm::update(void) // XXX we might want to further constrain this count count = _interface->available(); - if (count >= 128) + if (count >= _rxBufferSize) { char text[50]; - strncpy(text,"buffer overflow",50); + strncpy(text," buffer overflow",50); send_msg_status_text(SEVERITY_LOW,text); } diff --git a/libraries/APM_BinComm/APM_BinComm.h b/libraries/APM_BinComm/APM_BinComm.h index 50d3dd616d..997e7c78a3 100644 --- a/libraries/APM_BinComm/APM_BinComm.h +++ b/libraries/APM_BinComm/APM_BinComm.h @@ -69,9 +69,14 @@ public: /// /// @param interface The stream that will be used /// for telemetry communications. + /// + /// @param rxBuffSize Size of receive buffer allocated by interface. + /// This is used to warn for buffer overflow. + /// + /// BinComm(const MessageHandler *handlerTable, - Stream *interface = NULL); + uint16_t rxBufferSize, Stream *interface = NULL); /// /// Optional initialiser. @@ -100,6 +105,8 @@ private: uint8_t payload[256]; } _decodeBuf; + uint16_t _rxBufferSize; + /// Outgoing header/packet buffer /// XXX we could make this smaller struct {