Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions components/comms/CommsChannelMsg/CommsChannelMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,24 @@ class CommsChannelMsg
return _cmdVector;
}

// Whether the buffer may be taken (moved out, leaving it empty) by the channel sending the message, rather
// than copied. Set by a protocol codec on a message it made to send and doesn't use afterwards - a message
// passed on as it is may be sent again (e.g. on each channel), so its buffer mustn't be taken
void setBufTakeable(bool takeable)
{
_bufTakeable = takeable;
}
bool isBufTakeable() const
{
return _bufTakeable;
}

private:
uint32_t _channelID;
CommsMsgProtocol _msgProtocol;
uint32_t _msgNum;
CommsMsgTypeCode _msgTypeCode;
bool _bufTakeable = false;
#ifdef IMPLEMENT_NO_PSRAM_FOR_COMMS_CHANNEL_MSG
std::vector<uint8_t> _cmdVector;
#else
Expand Down
3 changes: 3 additions & 0 deletions components/comms/ProtocolRICSerial/ProtocolRICSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ void ProtocolRICSerial::encodeTxMsgAndSend(CommsChannelMsg& msg)
_pHDLC->appendFramePayload(encoded, fcs, ricSerialRec, sizeof(ricSerialRec));
_pHDLC->appendFramePayload(encoded, fcs, msg.getBuf(), msg.getBufLen());
_pHDLC->appendFrameEnd(encoded, fcs);

// Nothing uses the encoded message after it is sent, so the channel may take its buffer
encodedMsg.setBufTakeable(true);
#endif

// Debug
Expand Down
15 changes: 13 additions & 2 deletions components/comms/ProtocolRawMsg/ProtocolRawMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class ProtocolRawMsg
_cmdVector.assign(pBuf, pBuf+bufLen);
}

// Take the contents of a buffer without copying (it is left empty)
void takeBuffer(SpiramAwareUint8Vector& buf)
{
#ifdef IMPLEMENT_NO_PSRAM_FOR_PROTOCOL_RAW_MSG
_cmdVector.assign(buf.begin(), buf.end());
buf.clear();
#else
_cmdVector.swap(buf);
#endif
}

void setBufferSize(uint32_t bufSize)
{
_cmdVector.resize(bufSize);
Expand All @@ -55,11 +66,11 @@ class ProtocolRawMsg
}

// Access to command vector
const uint8_t* getBuf()
const uint8_t* getBuf() const
{
return _cmdVector.data();
}
uint32_t getBufLen()
uint32_t getBufLen() const
{
return _cmdVector.size();
}
Expand Down
Loading