mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-01 04:04:57 +01:00
fix ci and add formatting (#48)
* add dependency * dont run blocking zmq example and add formatting * format files
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
|
||||
DType::DType(const std::type_info &t) {
|
||||
if (t == typeid(int8_t))
|
||||
m_type = TypeIndex::INT8;
|
||||
@@ -29,11 +28,10 @@ DType::DType(const std::type_info &t) {
|
||||
else if (t == typeid(double))
|
||||
m_type = TypeIndex::DOUBLE;
|
||||
else
|
||||
throw std::runtime_error(
|
||||
"Could not construct data type. Type not supported.");
|
||||
throw std::runtime_error("Could not construct data type. Type not supported.");
|
||||
}
|
||||
|
||||
uint8_t DType::bitdepth()const {
|
||||
uint8_t DType::bitdepth() const {
|
||||
switch (m_type) {
|
||||
case TypeIndex::INT8:
|
||||
case TypeIndex::UINT8:
|
||||
@@ -54,12 +52,11 @@ uint8_t DType::bitdepth()const {
|
||||
case TypeIndex::ERROR:
|
||||
return 0;
|
||||
default:
|
||||
throw std::runtime_error(LOCATION+"Could not get bitdepth. Type not supported.");
|
||||
throw std::runtime_error(LOCATION + "Could not get bitdepth. Type not supported.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DType::DType(DType::TypeIndex ti):m_type(ti){}
|
||||
DType::DType(DType::TypeIndex ti) : m_type(ti) {}
|
||||
|
||||
DType::DType(std::string_view sv) {
|
||||
|
||||
@@ -99,8 +96,7 @@ DType::DType(std::string_view sv) {
|
||||
else if (sv == "f8")
|
||||
m_type = TypeIndex::DOUBLE;
|
||||
else
|
||||
throw std::runtime_error(
|
||||
"Could not construct data type. Type no supported.");
|
||||
throw std::runtime_error("Could not construct data type. Type no supported.");
|
||||
}
|
||||
|
||||
std::string DType::str() const {
|
||||
@@ -138,18 +134,10 @@ std::string DType::str() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool DType::operator==(const DType &other) const noexcept {
|
||||
return m_type == other.m_type;
|
||||
}
|
||||
bool DType::operator!=(const DType &other) const noexcept {
|
||||
return !(*this == other);
|
||||
}
|
||||
bool DType::operator==(const DType &other) const noexcept { return m_type == other.m_type; }
|
||||
bool DType::operator!=(const DType &other) const noexcept { return !(*this == other); }
|
||||
|
||||
bool DType::operator==(const std::type_info &t) const {
|
||||
return DType(t) == *this;
|
||||
}
|
||||
bool DType::operator!=(const std::type_info &t) const {
|
||||
return DType(t) != *this;
|
||||
}
|
||||
bool DType::operator==(const std::type_info &t) const { return DType(t) == *this; }
|
||||
bool DType::operator!=(const std::type_info &t) const { return DType(t) != *this; }
|
||||
|
||||
} // namespace pl
|
||||
} // namespace aare
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
#include "aare/Frame.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
namespace aare {
|
||||
|
||||
Frame::Frame(std::byte* bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
||||
m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows*cols*bitdepth/8];
|
||||
std::memcpy(m_data, bytes, rows*cols*bitdepth/8);
|
||||
}
|
||||
|
||||
Frame::Frame(ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
||||
m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows*cols*bitdepth/8];
|
||||
std::memset(m_data, 0, rows*cols*bitdepth/8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::byte* Frame::get(int row, int col) {
|
||||
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
|
||||
std::cerr << "Invalid row or column index" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return m_data+(row*m_cols + col)*(m_bitdepth/8);
|
||||
Frame::Frame(std::byte *bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth)
|
||||
: m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows * cols * bitdepth / 8];
|
||||
std::memcpy(m_data, bytes, rows * cols * bitdepth / 8);
|
||||
}
|
||||
|
||||
Frame::Frame(ssize_t rows, ssize_t cols, ssize_t bitdepth) : m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||
m_data = new std::byte[rows * cols * bitdepth / 8];
|
||||
std::memset(m_data, 0, rows * cols * bitdepth / 8);
|
||||
}
|
||||
|
||||
std::byte *Frame::get(int row, int col) {
|
||||
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
|
||||
std::cerr << "Invalid row or column index" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return m_data + (row * m_cols + col) * (m_bitdepth / 8);
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
#include "aare/ZmqSocket.hpp"
|
||||
#include <zmq.h>
|
||||
#include <fmt/core.h>
|
||||
#include <zmq.h>
|
||||
|
||||
namespace aare{
|
||||
namespace aare {
|
||||
|
||||
|
||||
ZmqSocket::ZmqSocket(const std::string& endpoint):m_endpoint(endpoint){
|
||||
ZmqSocket::ZmqSocket(const std::string &endpoint) : m_endpoint(endpoint) {
|
||||
memset(m_header_buffer, 0, m_max_header_size);
|
||||
}
|
||||
|
||||
void ZmqSocket::connect(){
|
||||
void ZmqSocket::connect() {
|
||||
m_context = zmq_ctx_new();
|
||||
m_socket = zmq_socket(m_context, ZMQ_SUB);
|
||||
fmt::print("Setting ZMQ_RCVHWM to {}\n", m_zmq_hwm);
|
||||
int rc = zmq_setsockopt(m_socket, ZMQ_RCVHWM, &m_zmq_hwm, sizeof(m_zmq_hwm)); //should be set before connect
|
||||
int rc = zmq_setsockopt(m_socket, ZMQ_RCVHWM, &m_zmq_hwm, sizeof(m_zmq_hwm)); // should be set before connect
|
||||
if (rc)
|
||||
throw std::runtime_error(fmt::format("Could not set ZMQ_RCVHWM: {}", strerror(errno)));
|
||||
|
||||
int bufsize = 1024*1024*m_zmq_hwm;
|
||||
fmt::print("Setting ZMQ_RCVBUF to: {} MB\n", bufsize/(1024*1024));
|
||||
|
||||
int bufsize = 1024 * 1024 * m_zmq_hwm;
|
||||
fmt::print("Setting ZMQ_RCVBUF to: {} MB\n", bufsize / (1024 * 1024));
|
||||
rc = zmq_setsockopt(m_socket, ZMQ_RCVBUF, &bufsize, sizeof(bufsize));
|
||||
if (rc)
|
||||
throw std::runtime_error(fmt::format("Could not set ZMQ_RCVBUF: {}", strerror(errno)));
|
||||
@@ -34,53 +33,49 @@ void ZmqSocket::disconnect() {
|
||||
m_context = nullptr;
|
||||
}
|
||||
|
||||
ZmqSocket::~ZmqSocket(){
|
||||
ZmqSocket::~ZmqSocket() {
|
||||
if (m_socket)
|
||||
disconnect();
|
||||
delete[] m_header_buffer;
|
||||
}
|
||||
|
||||
void ZmqSocket::set_zmq_hwm(int hwm){
|
||||
m_zmq_hwm = hwm;
|
||||
}
|
||||
void ZmqSocket::set_zmq_hwm(int hwm) { m_zmq_hwm = hwm; }
|
||||
|
||||
void ZmqSocket::set_timeout_ms(int n){
|
||||
m_timeout_ms = n;
|
||||
}
|
||||
void ZmqSocket::set_timeout_ms(int n) { m_timeout_ms = n; }
|
||||
|
||||
int ZmqSocket::receive(zmqHeader &header, std::byte *data){
|
||||
int ZmqSocket::receive(zmqHeader &header, std::byte *data) {
|
||||
|
||||
//receive header
|
||||
// receive header
|
||||
int header_bytes_received = zmq_recv(m_socket, m_header_buffer, m_max_header_size, 0);
|
||||
m_header_buffer[header_bytes_received] = '\0'; //make sure we zero terminate
|
||||
if (header_bytes_received < 0){
|
||||
m_header_buffer[header_bytes_received] = '\0'; // make sure we zero terminate
|
||||
if (header_bytes_received < 0) {
|
||||
fmt::print("Error receiving header: {}\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
fmt::print("Bytes: {}, Header: {}\n", header_bytes_received, m_header_buffer);
|
||||
|
||||
//decode header
|
||||
if (!decode_header(header)){
|
||||
|
||||
// decode header
|
||||
if (!decode_header(header)) {
|
||||
fmt::print("Error decoding header\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//do we have a multipart message (data following header)?
|
||||
// do we have a multipart message (data following header)?
|
||||
int more;
|
||||
size_t more_size = sizeof(more);
|
||||
zmq_getsockopt(m_socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
if (!more) {
|
||||
return 0; //no data following header
|
||||
}else{
|
||||
int data_bytes_received = zmq_recv(m_socket, data, 1024*1024*2, 0); //TODO! configurable size!!!!
|
||||
return 0; // no data following header
|
||||
} else {
|
||||
int data_bytes_received = zmq_recv(m_socket, data, 1024 * 1024 * 2, 0); // TODO! configurable size!!!!
|
||||
if (data_bytes_received == -1)
|
||||
throw std::runtime_error("Got half of a multipart msg!!!");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ZmqSocket::decode_header(zmqHeader &h){
|
||||
//TODO: implement
|
||||
bool ZmqSocket::decode_header(zmqHeader &h) {
|
||||
// TODO: implement
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user