- refactored
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@891 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+48
-39
@@ -2,6 +2,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <crc/crc.h>
|
#include <crc/crc.h>
|
||||||
#include <radio/symbol.h>
|
#include <radio/symbol.h>
|
||||||
#include "Formatter.hpp"
|
#include "Formatter.hpp"
|
||||||
@@ -27,46 +29,24 @@ Formatter::~Formatter()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Formatter::idle()
|
void Formatter::process_data(uint8_t *pData, uint32_t len)
|
||||||
{
|
|
||||||
if (m_dataCount)
|
|
||||||
{
|
|
||||||
// Commit partial DATA frame
|
|
||||||
commit(FRAME_TYPE_DATA, m_dataCount);
|
|
||||||
m_dataCount = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// IDLE frame not full
|
|
||||||
if (m_idleCount < FRAME_NUM_BYTES_PER_FRAME)
|
|
||||||
{
|
|
||||||
m_frame.data[m_idleCount++] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_idleCount == FRAME_NUM_BYTES_PER_FRAME)
|
|
||||||
{
|
|
||||||
// Commit full IDLE frame of size FRAME_NUM_BYTES_PER_FRAME
|
|
||||||
commit(FRAME_TYPE_IDLE, m_idleCount);
|
|
||||||
m_idleCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Formatter::process(uint8_t data)
|
|
||||||
{
|
{
|
||||||
if (m_idleCount)
|
if (m_idleCount)
|
||||||
{
|
{
|
||||||
// Commit partial IDLE frame
|
// Idle in progress: Commit partial IDLE frame
|
||||||
commit(FRAME_TYPE_IDLE, m_idleCount);
|
commit(FRAME_TYPE_IDLE, m_idleCount);
|
||||||
m_idleCount = 0;
|
m_idleCount = 0;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
size_t remain = len;
|
||||||
|
while(remain)
|
||||||
{
|
{
|
||||||
// DATA frame not full
|
size_t frame_remain = FRAME_NUM_BYTES_PER_FRAME - m_dataCount;
|
||||||
if (m_dataCount < FRAME_NUM_BYTES_PER_FRAME)
|
size_t to_write = std::min(remain, frame_remain);
|
||||||
{
|
memcpy(&m_frame.data[m_dataCount], pData, to_write);
|
||||||
m_frame.data[m_dataCount++] = data;
|
m_dataCount += to_write;
|
||||||
}
|
remain -= to_write;
|
||||||
|
pData += to_write;
|
||||||
|
|
||||||
if (m_dataCount == FRAME_NUM_BYTES_PER_FRAME)
|
if (m_dataCount == FRAME_NUM_BYTES_PER_FRAME)
|
||||||
{
|
{
|
||||||
@@ -77,15 +57,44 @@ void Formatter::process(uint8_t data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Formatter::process_idle(uint32_t len)
|
||||||
|
{
|
||||||
|
if (m_dataCount)
|
||||||
|
{
|
||||||
|
// Commit partial DATA frame
|
||||||
|
commit(FRAME_TYPE_DATA, m_dataCount);
|
||||||
|
m_dataCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t remain = len;
|
||||||
|
while(remain)
|
||||||
|
{
|
||||||
|
size_t frame_remain = FRAME_NUM_BYTES_PER_FRAME - m_dataCount;
|
||||||
|
size_t to_write = std::min(remain, frame_remain);
|
||||||
|
memset(&m_frame.data[m_dataCount], 0, to_write);
|
||||||
|
m_dataCount += to_write;
|
||||||
|
remain -= to_write;
|
||||||
|
|
||||||
|
if (m_idleCount == FRAME_NUM_BYTES_PER_FRAME)
|
||||||
|
{
|
||||||
|
// Commit full IDLE frame of size FRAME_NUM_BYTES_PER_FRAME
|
||||||
|
commit(FRAME_TYPE_IDLE, m_idleCount);
|
||||||
|
m_idleCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void Formatter::process(void *pData, uint32_t len)
|
void Formatter::process(void *pData, uint32_t len)
|
||||||
{
|
{
|
||||||
uint8_t *pByte;
|
if (pData)
|
||||||
|
|
||||||
pByte = (uint8_t*)pData;
|
|
||||||
|
|
||||||
while(len--)
|
|
||||||
{
|
{
|
||||||
process(*(pByte++));
|
// Data available: Process data
|
||||||
|
process_data((uint8_t*)pData, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Data not available: Process Idle
|
||||||
|
process_idle(len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -20,8 +20,6 @@ class Formatter
|
|||||||
public:
|
public:
|
||||||
Formatter(IFormatter *pFrameHandler);
|
Formatter(IFormatter *pFrameHandler);
|
||||||
~Formatter();
|
~Formatter();
|
||||||
void idle();
|
|
||||||
void process(uint8_t data);
|
|
||||||
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();
|
||||||
@@ -33,7 +31,8 @@ private:
|
|||||||
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;
|
||||||
|
void process_idle(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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+17
-12
@@ -2,6 +2,7 @@
|
|||||||
#ifndef _RADIO_FRAME_HPP_
|
#ifndef _RADIO_FRAME_HPP_
|
||||||
#define _RADIO_FRAME_HPP_
|
#define _RADIO_FRAME_HPP_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <radio/radio_types.h>
|
#include <radio/radio_types.h>
|
||||||
#include <radio/cpx.h>
|
#include <radio/cpx.h>
|
||||||
#include "FrameDefs.hpp"
|
#include "FrameDefs.hpp"
|
||||||
@@ -66,21 +67,25 @@ public:
|
|||||||
|
|
||||||
void process()
|
void process()
|
||||||
{
|
{
|
||||||
uint32_t i;
|
{
|
||||||
|
uint8_t data[12];
|
||||||
|
for (uint32_t i=0; i < sizeof(data); i++)
|
||||||
|
{
|
||||||
|
data[i] = i;
|
||||||
|
}
|
||||||
|
m_formatter.process(data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i < 12; i++)
|
m_formatter.process(nullptr, 100);
|
||||||
{
|
{
|
||||||
m_formatter.process((uint8_t)i);
|
uint8_t data[100];
|
||||||
|
for (uint32_t i=0; i < sizeof(data); i++)
|
||||||
|
{
|
||||||
|
data[i] = i;
|
||||||
|
}
|
||||||
|
m_formatter.process(data, sizeof(data));
|
||||||
}
|
}
|
||||||
for (i=0; i < 100; i++)
|
m_formatter.process(nullptr, 1);
|
||||||
{
|
|
||||||
m_formatter.idle();
|
|
||||||
}
|
|
||||||
for (i=0; i < 100; i++)
|
|
||||||
{
|
|
||||||
m_formatter.process((uint8_t)i);
|
|
||||||
}
|
|
||||||
m_formatter.idle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user