Compiling and running

This commit is contained in:
Mohacsi Istvan
2021-07-13 14:14:34 +02:00
parent 02f1bc55b9
commit 0fa106a9a7
3 changed files with 14 additions and 12 deletions
+9 -5
View File
@@ -3,6 +3,8 @@
#include <iostream>
#include <cstring>
#include <deque>
#include <thread>
#include <vector>
#include <functional>
#include <shared_mutex>
@@ -81,7 +83,7 @@ public:
// Queue for draining
if(m_fill[idx]==m_MOD-1){
std::cout << "Complete frame at " << idx << "\t(queued for draining)" <<std::endl;
// std::cout << "Complete frame at " << idx << "\t(queued for draining)\tqueue size: " << drain_queue.size() << std::endl;
drain_queue.push_back(idx);
}
}
@@ -130,10 +132,12 @@ protected:
NOTE : It does not lock, that must be done externally! **/
void drain_loop(){
while(true){
if(!drain_fifo.empty()){
uint32_t idx = drain_queue.pop_front();
std::cout << "\tDraining " << idx << std::endl;
if(!drain_queue.empty()){
uint32_t idx = drain_queue.front();
drain_queue.pop_front();
flush_line(idx);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
}
}
@@ -155,7 +159,7 @@ protected:
/** Watchdog timer and flush queue **/
Watchdog *m_watchdog;
std::thread m_drainer;
std::deque<uint32_t> drain_queue();
std::deque<uint32_t> drain_queue;
};
+4 -6
View File
@@ -29,7 +29,6 @@
It also has an internal mutex that can be used for thread-safe
access to the underlying connection;
**/
template <size_t ZMQ_PUB_IO_THREADS>
class ZmqPublisher {
protected:
const uint16_t m_port;
@@ -39,8 +38,8 @@ class ZmqPublisher {
std::mutex g_zmq_socket;
public:
ZmqPublisher(std::string ip, uint16_t port) :
m_port(port), m_address("tcp://*:" + std::to_string(port)), m_ctx(ZMQ_PUB_IO_THREADS), m_socket(m_ctx, ZMQ_PUB) {
ZmqPublisher(std::string ip, uint16_t port, uint32_t n_threads) :
m_port(port), m_address("tcp://*:" + std::to_string(port)), m_ctx(n_threads), m_socket(m_ctx, ZMQ_PUB) {
// Bind the socket
m_socket.bind(m_address.c_str());
std::cout << "Initialized ZMQ publisher at " << m_address << std::endl;
@@ -55,10 +54,9 @@ class ZmqPublisher {
Specialized publisher to send 'ImageBinaryFormat' data format as
multipart message. It also takes care of thread safety.
**/
template <size_t ZMQ_PUB_IO_THREADS>
class ZmqImagePublisher: public ZmqPublisher<ZMQ_PUB_IO_THREADS> {
class ZmqImagePublisher: public ZmqPublisher {
public:
ZmqImagePublisher(std::string ip, uint16_t port) : ZmqPublisher(ip, port) {};
ZmqImagePublisher(std::string ip, uint16_t port, uint32_t n_threads) : ZmqPublisher(ip, port, n_threads) {};
const std::string topic = "IMAGEDATA";
void sendImage(ImageBinaryFormat& image){
+1 -1
View File
@@ -20,7 +20,7 @@ int main (int argc, char *argv[]) {
std::cout << "Creating ZMQ socket..." << std::endl;
ZmqImagePublisher<2> pub("*", 5200);
ZmqImagePublisher pub("*", 5200, 2);
// ... and extracting sender function
std::function<void(ImageBinaryFormat&)> zmq_publish =
std::bind(&ZmqImagePublisher::sendImage, &pub, std::placeholders::_1);