- removed IFormatter
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1070 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+13
-9
@@ -11,12 +11,13 @@
|
|||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Formatter
|
// Formatter
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
Formatter::Formatter(IFormatter *pFrameHandler)
|
Formatter::Formatter()
|
||||||
: Processor::Block(1, 1)
|
: Processor::Block(1, 1)
|
||||||
, m_scrambler(FRAME_SCRAMBLER_SEED, FRAME_SCRAMBLER_POLY)
|
, m_scrambler(FRAME_SCRAMBLER_SEED, FRAME_SCRAMBLER_POLY)
|
||||||
, m_pFrameHandler(pFrameHandler)
|
|
||||||
, m_dataCount(0)
|
, m_dataCount(0)
|
||||||
, m_idleCount(0)
|
, m_idleCount(0)
|
||||||
|
, m_buf_in(nullptr)
|
||||||
|
, m_buf_out(nullptr)
|
||||||
{
|
{
|
||||||
resetStats();
|
resetStats();
|
||||||
memset(&m_frame, 0, sizeof(frame_t));
|
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
|
// Get buffers
|
||||||
auto buf_in = buffer_in<uint8_t>();
|
m_buf_in = buffer_in<uint8_t>();
|
||||||
// auto buf_out = buffer_out<uint8_t>();
|
m_buf_out = buffer_out<uint8_t>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Formatter::process()
|
||||||
|
{
|
||||||
// Process input
|
// Process input
|
||||||
while(buf_in->len())
|
while(m_buf_in->len())
|
||||||
{
|
{
|
||||||
size_t frame_remain = FRAME_NUM_BYTES_PER_FRAME - m_dataCount;
|
size_t frame_remain = FRAME_NUM_BYTES_PER_FRAME - m_dataCount;
|
||||||
size_t to_write = std::min(buf_in->len(), frame_remain);
|
size_t to_write = std::min(m_buf_in->len(), frame_remain);
|
||||||
buf_in->read(&m_frame.data[m_dataCount], to_write);
|
m_buf_in->read(&m_frame.data[m_dataCount], to_write);
|
||||||
m_dataCount += to_write;
|
m_dataCount += to_write;
|
||||||
|
|
||||||
if (m_dataCount == FRAME_NUM_BYTES_PER_FRAME)
|
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((uint8_t*)&m_frame.hdr.length, sizeof(m_frame.hdr.length));
|
||||||
m_scrambler.process(m_frame.data, FRAME_NUM_BYTES_PER_FRAME);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|||||||
+8
-11
@@ -8,36 +8,33 @@
|
|||||||
#include "FrameDefs.hpp"
|
#include "FrameDefs.hpp"
|
||||||
#include "Scrambler.hpp"
|
#include "Scrambler.hpp"
|
||||||
|
|
||||||
class IFormatter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IFormatter() {}
|
|
||||||
virtual ~IFormatter() {}
|
|
||||||
virtual void onFrame(void *pFrame, uint32_t size) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Formatter : public Processor::Block
|
class Formatter : public Processor::Block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Formatter(IFormatter *pFrameHandler);
|
Formatter();
|
||||||
virtual ~Formatter() = default;
|
virtual ~Formatter() = default;
|
||||||
void process(void *pData, uint32_t len);
|
void process(void *pData, uint32_t len);
|
||||||
frame_statistics_t getStats();
|
frame_statistics_t getStats();
|
||||||
void resetStats();
|
void resetStats();
|
||||||
void process();
|
|
||||||
|
// Processor::Block
|
||||||
|
void prepare() override;
|
||||||
|
void process() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scrambler m_scrambler;
|
Scrambler m_scrambler;
|
||||||
IFormatter *m_pFrameHandler;
|
|
||||||
frame_t m_frame;
|
frame_t m_frame;
|
||||||
uint32_t m_dataCount;
|
uint32_t m_dataCount;
|
||||||
uint32_t m_idleCount;
|
uint32_t m_idleCount;
|
||||||
frame_statistics_t m_frameStats;
|
frame_statistics_t m_frameStats;
|
||||||
|
Processor::Buffer<uint8_t> *m_buf_in;
|
||||||
|
Processor::Buffer<uint8_t> *m_buf_out;
|
||||||
|
|
||||||
void process_idle(uint32_t len);
|
void process_idle(uint32_t len);
|
||||||
void process_data(uint8_t *pData, uint32_t len);
|
void process_data(uint8_t *pData, uint32_t len);
|
||||||
|
|
||||||
void commit(frame_type frameType, uint32_t m_dataCount);
|
void commit(frame_type frameType, uint32_t m_dataCount);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user