Skip to content

Commit 02e9341

Browse files
committed
feat: DataHandler: add receive_packets flag
1 parent 618208a commit 02e9341

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

inc/udmaio/DataHandlerAbstract.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,20 @@ class DataHandlerAbstract : public Logger, private boost::noncopyable {
3737
void _start_read();
3838
void _handle_input(const boost::system::error_code& ec);
3939

40+
protected:
41+
bool _receive_packets; ///< Enable segmentation of stream into SOF/EOF delimited frames
42+
4043
public:
4144
/// @brief Construct a Data Handler
4245
/// @param dma Interface to the AXI DMA core
4346
/// @param desc Interface to the SGDMA descriptors
4447
/// @param mem Interface to the memory holding the SGDMA data buffers
48+
/// @param receive_packets Receive packets/frames delimited by SOF/EOF. If not set, receive stream as-is without regard for packets
4549
explicit DataHandlerAbstract(std::string name,
4650
UioAxiDmaIf& dma,
4751
UioMemSgdma& desc,
48-
DmaBufferAbstract& mem);
52+
DmaBufferAbstract& mem,
53+
bool receive_packets = true);
4954
virtual ~DataHandlerAbstract();
5055

5156
/// @brief Stop the data reception

pyudmaio/src/DataHandlerPython.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ namespace udmaio {
1515

1616
DataHandlerPython::DataHandlerPython(std::shared_ptr<UioAxiDmaIf> dma_ptr,
1717
std::shared_ptr<UioMemSgdma> desc_ptr,
18-
std::shared_ptr<DmaBufferAbstract> mem_ptr)
19-
: DataHandlerSync("DataHandlerPython", *dma_ptr, *desc_ptr, *mem_ptr)
18+
std::shared_ptr<DmaBufferAbstract> mem_ptr,
19+
bool receive_packets)
20+
: DataHandlerSync("DataHandlerPython", *dma_ptr, *desc_ptr, *mem_ptr, receive_packets)
2021
, _dma_ptr(dma_ptr)
2122
, _desc_ptr(desc_ptr)
2223
, _mem_ptr(mem_ptr) {}
@@ -56,7 +57,8 @@ py::array_t<uint8_t> DataHandlerPython::numpy_read_nb() {
5657
throw std::runtime_error("DMA has experienced an error");
5758
}
5859

59-
auto full_bufs = _desc_ptr->get_full_buffers();
60+
auto full_bufs =
61+
_receive_packets ? _desc_ptr->get_next_packet() : _desc_ptr->get_full_buffers();
6062
auto vec = new std::vector<uint8_t>(_desc_ptr->read_buffers(full_bufs));
6163

6264
// Callback for Python garbage collector

pyudmaio/src/DataHandlerPython.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma once
1313

1414
#include <memory>
15+
1516
#include <pybind11/numpy.h>
1617

1718
#include "udmaio/DataHandlerSync.hpp"
@@ -25,13 +26,15 @@ class DataHandlerPython : public DataHandlerSync {
2526
std::shared_ptr<UioMemSgdma> _desc_ptr;
2627
std::shared_ptr<DmaBufferAbstract> _mem_ptr;
2728

28-
public:
29-
DataHandlerPython(std::shared_ptr<UioAxiDmaIf>, std::shared_ptr<UioMemSgdma>, std::shared_ptr<DmaBufferAbstract>);
29+
public:
30+
DataHandlerPython(std::shared_ptr<UioAxiDmaIf>,
31+
std::shared_ptr<UioMemSgdma>,
32+
std::shared_ptr<DmaBufferAbstract>,
33+
bool receive_packets = true);
3034

3135
void start(int nr_pkts, size_t pkt_size, bool init_only = false);
32-
py::array_t<uint8_t> numpy_read(uint32_t ms_timeout=0);
36+
py::array_t<uint8_t> numpy_read(uint32_t ms_timeout = 0);
3337
py::array_t<uint8_t> numpy_read_nb();
34-
3538
};
3639

37-
} // namespace udmaio
40+
} // namespace udmaio

pyudmaio/src/PythonBinding.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ PYBIND11_MODULE(binding, m) {
122122
data_handler
123123
.def(py::init<std::shared_ptr<udmaio::UioAxiDmaIf>,
124124
std::shared_ptr<udmaio::UioMemSgdma>,
125-
std::shared_ptr<udmaio::DmaBufferAbstract>>())
125+
std::shared_ptr<udmaio::DmaBufferAbstract>,
126+
bool>(),
127+
py::arg("dma"),
128+
py::arg("desc"),
129+
py::arg("mem"),
130+
py::arg("receive_packets") = bool(true))
126131
.def("start",
127132
&udmaio::DataHandlerPython::start,
128133
py::arg("nr_pkts"),

src/DataHandlerAbstract.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ namespace udmaio {
2121
DataHandlerAbstract::DataHandlerAbstract(std::string name,
2222
UioAxiDmaIf& dma,
2323
UioMemSgdma& desc,
24-
DmaBufferAbstract& mem)
25-
: Logger(name), _dma{dma}, _desc{desc}, _mem{mem}, _svc{}, _sd{_svc, _dma.get_fd_int()} {
24+
DmaBufferAbstract& mem,
25+
bool receive_packets)
26+
: Logger(name)
27+
, _dma{dma}
28+
, _desc{desc}
29+
, _mem{mem}
30+
, _svc{}
31+
, _sd{_svc, _dma.get_fd_int()}
32+
, _receive_packets{receive_packets} {
2633
BOOST_LOG_SEV(_lg, bls::trace) << "ctor";
2734
};
2835

@@ -58,7 +65,7 @@ void DataHandlerAbstract::_handle_input(const boost::system::error_code& ec) {
5865
uint32_t irq_count = _dma.clear_interrupt();
5966
BOOST_LOG_SEV(_lg, bls::trace) << "irq count = " << irq_count;
6067

61-
auto full_bufs = _desc.get_full_buffers();
68+
auto full_bufs = _receive_packets ? _desc.get_next_packet() : _desc.get_full_buffers();
6269
if (full_bufs.empty()) {
6370
BOOST_LOG_SEV(_lg, bls::trace) << "spurious event, got no data";
6471
} else {

0 commit comments

Comments
 (0)