From fc7a25c92a5f3eaec125464963405abd259eb0dd Mon Sep 17 00:00:00 2001 From: Rob Riggs Date: Thu, 8 Jul 2021 19:50:54 -0500 Subject: [PATCH] Add support for frame resizing. Handle old stream frame type in encoder. --- TNC/HdlcFrame.hpp | 3 +-- TNC/M17Encoder.cpp | 6 ++++++ TNC/SegmentedBuffer.hpp | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/TNC/HdlcFrame.hpp b/TNC/HdlcFrame.hpp index d37dea5..92ee303 100644 --- a/TNC/HdlcFrame.hpp +++ b/TNC/HdlcFrame.hpp @@ -101,6 +101,7 @@ public: } uint16_t size() const {return data_.size();} + bool resize(uint16_t size) {return data_.resize(size);} uint16_t crc() const {return crc_;} uint16_t fcs() const {return fcs_;} @@ -170,12 +171,10 @@ public: free_list_.pop_front(); } taskEXIT_CRITICAL_FROM_ISR(x); - DEBUG("Acquired frame %p (size after = %d)", result, free_list_.size()); return result; } void release(frame_type* frame) { - DEBUG("Released frame %p (size before = %d)", frame, free_list_.size()); frame->clear(); auto x = taskENTER_CRITICAL_FROM_ISR(); free_list_.push_back(*frame); diff --git a/TNC/M17Encoder.cpp b/TNC/M17Encoder.cpp index a8b45f8..ca9852d 100644 --- a/TNC/M17Encoder.cpp +++ b/TNC/M17Encoder.cpp @@ -224,6 +224,12 @@ void M17Encoder::process_stream(tnc::hdlc::IoFrame* frame, FrameType type) { send_stream(frame, type); // Consumes frame. } + else if (frame->size() == 26) + { + // Old-style frame with trailing CRC. + frame->resize(24); + send_stream(frame, type); + } else { WARN("Unexpected AUDIO frame size = %u", frame->size()); diff --git a/TNC/SegmentedBuffer.hpp b/TNC/SegmentedBuffer.hpp index b900873..3e0620c 100644 --- a/TNC/SegmentedBuffer.hpp +++ b/TNC/SegmentedBuffer.hpp @@ -81,6 +81,23 @@ struct SegmentedBuffer { uint16_t size() const {return size_;} + bool resize(uint16_t size) + { + if (size <= size_) + { + size_ = size; + } + else + { + for (;size_ != size;) + { + if (!push_back(value_type())) + return false; + } + } + return true; + } + bool push_back(value_type value) { uint16_t offset = size_ & 0xFF; if (offset == 0) { // Must allocate.