From 40be63056c446f1b9f4391b371604f581ab8648b Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 24 Jun 2022 08:53:14 +0000 Subject: [PATCH] - removed IFormatter git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1070 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- radio/Formatter.cpp | 24 ++++++++++++++---------- radio/Formatter.hpp | 19 ++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/radio/Formatter.cpp b/radio/Formatter.cpp index 08b338b..5d475f3 100644 --- a/radio/Formatter.cpp +++ b/radio/Formatter.cpp @@ -11,12 +11,13 @@ // -------------------------------------------------------------- // Formatter // -------------------------------------------------------------- -Formatter::Formatter(IFormatter *pFrameHandler) +Formatter::Formatter() : Processor::Block(1, 1) , m_scrambler(FRAME_SCRAMBLER_SEED, FRAME_SCRAMBLER_POLY) -, m_pFrameHandler(pFrameHandler) , m_dataCount(0) , m_idleCount(0) +, m_buf_in(nullptr) +, m_buf_out(nullptr) { resetStats(); memset(&m_frame, 0, sizeof(frame_t)); @@ -95,18 +96,21 @@ void Formatter::process(void *pData, uint32_t len) } } -void Formatter::process() +void Formatter::prepare() { // Get buffers - auto buf_in = buffer_in(); -// auto buf_out = buffer_out(); - + m_buf_in = buffer_in(); + m_buf_out = buffer_out(); +} + +void Formatter::process() +{ // Process input - while(buf_in->len()) + while(m_buf_in->len()) { size_t frame_remain = FRAME_NUM_BYTES_PER_FRAME - m_dataCount; - size_t to_write = std::min(buf_in->len(), frame_remain); - buf_in->read(&m_frame.data[m_dataCount], to_write); + size_t to_write = std::min(m_buf_in->len(), frame_remain); + m_buf_in->read(&m_frame.data[m_dataCount], to_write); m_dataCount += to_write; if (m_dataCount == FRAME_NUM_BYTES_PER_FRAME) @@ -141,7 +145,7 @@ void Formatter::commit(frame_type frameType, uint32_t dataCount) m_scrambler.process((uint8_t*)&m_frame.hdr.length, sizeof(m_frame.hdr.length)); m_scrambler.process(m_frame.data, FRAME_NUM_BYTES_PER_FRAME); - m_pFrameHandler->onFrame((void*)&m_frame, sizeof(frame_t)); + m_buf_out->write((uint8_t*)&m_frame, sizeof(frame_t)); } // -------------------------------------------------------------- diff --git a/radio/Formatter.hpp b/radio/Formatter.hpp index 8e84614..2ddd19e 100644 --- a/radio/Formatter.hpp +++ b/radio/Formatter.hpp @@ -8,36 +8,33 @@ #include "FrameDefs.hpp" #include "Scrambler.hpp" -class IFormatter -{ -public: - IFormatter() {} - virtual ~IFormatter() {} - virtual void onFrame(void *pFrame, uint32_t size) = 0; -}; class Formatter : public Processor::Block { public: - Formatter(IFormatter *pFrameHandler); + Formatter(); virtual ~Formatter() = default; void process(void *pData, uint32_t len); frame_statistics_t getStats(); void resetStats(); - void process(); + + // Processor::Block + void prepare() override; + void process() override; private: Scrambler m_scrambler; - IFormatter *m_pFrameHandler; frame_t m_frame; uint32_t m_dataCount; uint32_t m_idleCount; frame_statistics_t m_frameStats; + Processor::Buffer *m_buf_in; + Processor::Buffer *m_buf_out; + void process_idle(uint32_t len); void process_data(uint8_t *pData, uint32_t len); void commit(frame_type frameType, uint32_t m_dataCount); - }; // --------------------------------------------------------------