clang format

This commit is contained in:
2021-10-19 14:49:43 +02:00
parent 3726ae3fd1
commit b39c64032d
66 changed files with 642 additions and 624 deletions

View File

@ -53,7 +53,7 @@ class DataSocket {
int Send(const std::string &s);
// Variadic template to send all arguments
template <class... Args> int SendAll(Args &&... args) {
template <class... Args> int SendAll(Args &&...args) {
auto l = std::initializer_list<int>{Send(args)...};
auto sum = std::accumulate(begin(l), end(l), 0);
return sum;
@ -86,7 +86,7 @@ class DataSocket {
private:
int sockfd_ = -1;
int fnum_ {0};
int fnum_{0};
};
}; // namespace sls

View File

@ -19,7 +19,7 @@ namespace sls {
// already available as std::make_unique in C++14
template <typename T, typename... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args &&... args) {
make_unique(Args &&...args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

View File

@ -13,36 +13,34 @@
* Removed most of the code that is not relevant for our scope.
* Snippets copied from md5_local.h or md32_common.h has been marked
*/
#ifndef HEADER_MD5_H
# define HEADER_MD5_H
#define HEADER_MD5_H
# include <stddef.h>
#include <stddef.h>
# ifdef __cplusplus
#ifdef __cplusplus
/*
* Modifications 2021 Paul Scherrer Institut
* namespace sls added
*/
namespace sls {
extern "C" {
# endif
#endif
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! MD5_LONG has to be at least 32 bits wide. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
# define MD5_LONG unsigned int
# define MD5_CBLOCK 64
# define MD5_LBLOCK (MD5_CBLOCK/4)
# define MD5_DIGEST_LENGTH 16
#define MD5_LONG unsigned int
#define MD5_CBLOCK 64
#define MD5_LBLOCK (MD5_CBLOCK / 4)
#define MD5_DIGEST_LENGTH 16
/**
* Modification 2021 Paul Scherrer Institut
* Comment from md32_common.h
/**
* Modification 2021 Paul Scherrer Institut
* Comment from md32_common.h
*/
/*-
* This is a generic 32 bit "collector" for message digest algorithms.
@ -99,65 +97,68 @@ extern "C" {
* #define HASH_FINAL MD5_Final_SLS
* #define HASH_BLOCK_DATA_ORDER md5_block_data_order
*/
# define MD32_REG_T int
#define MD32_REG_T int
/**
* Modification 2021 Paul Scherrer Institut
* Made default little endian if big endian not defined
/**
* Modification 2021 Paul Scherrer Institut
* Made default little endian if big endian not defined
*/
#ifndef DATA_ORDER_IS_BIG_ENDIAN
#define DATA_ORDER_IS_LITTLE_ENDIAN
#endif
/**
* Modification 2021 Paul Scherrer Institut
/**
* Modification 2021 Paul Scherrer Institut
* Macros exported from md32_common.h
*/
#define HASH_LONG MD5_LONG
#define HASH_CTX MD5_CTX
#define HASH_CBLOCK MD5_CBLOCK
#define HASH_UPDATE MD5_Update_SLS
#define HASH_TRANSFORM MD5_Transform
#define HASH_FINAL MD5_Final_SLS
#define HASH_BLOCK_DATA_ORDER md5_block_data_order
#define HASH_MAKE_STRING(c,s) do { \
unsigned long ll; \
ll=(c)->A; (void)HOST_l2c(ll,(s)); \
ll=(c)->B; (void)HOST_l2c(ll,(s)); \
ll=(c)->C; (void)HOST_l2c(ll,(s)); \
ll=(c)->D; (void)HOST_l2c(ll,(s)); \
} while (0)
#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
#define HASH_LONG MD5_LONG
#define HASH_CTX MD5_CTX
#define HASH_CBLOCK MD5_CBLOCK
#define HASH_UPDATE MD5_Update_SLS
#define HASH_TRANSFORM MD5_Transform
#define HASH_FINAL MD5_Final_SLS
#define HASH_BLOCK_DATA_ORDER md5_block_data_order
#define HASH_MAKE_STRING(c, s) \
do { \
unsigned long ll; \
ll = (c)->A; \
(void)HOST_l2c(ll, (s)); \
ll = (c)->B; \
(void)HOST_l2c(ll, (s)); \
ll = (c)->C; \
(void)HOST_l2c(ll, (s)); \
ll = (c)->D; \
(void)HOST_l2c(ll, (s)); \
} while (0)
#define ROTATE(a, n) (((a) << (n)) | (((a)&0xffffffff) >> (32 - (n))))
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
# define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++))) ) )
# define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff), \
l)
#define HOST_c2l(c, l) \
(l = (((unsigned long)(*((c)++))) << 24), \
l |= (((unsigned long)(*((c)++))) << 16), \
l |= (((unsigned long)(*((c)++))) << 8), \
l |= (((unsigned long)(*((c)++)))))
#define HOST_l2c(l, c) \
(*((c)++) = (unsigned char)(((l) >> 24) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 16) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
*((c)++) = (unsigned char)(((l)) & 0xff), l)
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
# define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<<24) )
# define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>>24)&0xff), \
l)
#define HOST_c2l(c, l) \
(l = (((unsigned long)(*((c)++)))), \
l |= (((unsigned long)(*((c)++))) << 8), \
l |= (((unsigned long)(*((c)++))) << 16), \
l |= (((unsigned long)(*((c)++))) << 24))
#define HOST_l2c(l, c) \
(*((c)++) = (unsigned char)(((l)) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 16) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 24) & 0xff), l)
#endif
typedef struct MD5state_st {
MD5_LONG A, B, C, D;
MD5_LONG Nl, Nh;
@ -169,15 +170,14 @@ int MD5_Init_SLS(MD5_CTX *c);
int MD5_Update_SLS(MD5_CTX *c, const void *data, size_t len);
int MD5_Final_SLS(unsigned char *md, MD5_CTX *c);
/**
* Modification 2021 Paul Scherrer Institut
* from md32_common.h
/**
* Modification 2021 Paul Scherrer Institut
* from md32_common.h
*/
void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
# ifdef __cplusplus
#ifdef __cplusplus
}
} // namespace sls
# endif
# endif
#endif
#endif

View File

@ -73,7 +73,7 @@ struct UdpDestination {
constexpr bool operator==(const UdpDestination &other) const {
return ((entry == other.entry) && (port == other.port) &&
(port2 == other.port2) && (ip== other.ip) &&
(port2 == other.port2) && (ip == other.ip) &&
(ip2 == other.ip2) && (mac == other.mac) &&
(mac2 == other.mac2));
}

View File

@ -34,10 +34,10 @@
#define MAX_RX_DBIT 64
/** default ports */
#define DEFAULT_PORTNO 1952
#define DEFAULT_UDP_PORTNO 50001
#define DEFAULT_ZMQ_CL_PORTNO 30001
#define DEFAULT_ZMQ_RX_PORTNO 30001
#define DEFAULT_PORTNO 1952
#define DEFAULT_UDP_PORTNO 50001
#define DEFAULT_ZMQ_CL_PORTNO 30001
#define DEFAULT_ZMQ_RX_PORTNO 30001
#define DEFAULT_UDP_SRC_PORTNO 32410
#define DEFAULT_UDP_DST_PORTNO 50001
@ -379,7 +379,13 @@ typedef struct {
enum readoutMode { ANALOG_ONLY, DIGITAL_ONLY, ANALOG_AND_DIGITAL };
/** chip speed */
enum speedLevel { FULL_SPEED, HALF_SPEED, QUARTER_SPEED, G2_108MHZ, G2_144MHZ };
enum speedLevel {
FULL_SPEED,
HALF_SPEED,
QUARTER_SPEED,
G2_108MHZ,
G2_144MHZ
};
/**
* burst mode for gotthard2
@ -412,7 +418,7 @@ typedef struct {
#ifdef __cplusplus
enum class streamingInterface {
#else
enum streamingInterface {
enum streamingInterface {
#endif
NONE = 0,
LOW_LATENCY_LINK = 1 << 0,
@ -470,8 +476,7 @@ typedef struct {
uint64_t select;
/** [Gotthard2][Jungfrau] disable */
currentSrcParameters()
: enable(0), fix(-1), normal(-1), select(0) {}
currentSrcParameters() : enable(0), fix(-1), normal(-1), select(0) {}
/** [Gotthard2] enable or disable */
explicit currentSrcParameters(bool srcEnable)
@ -487,7 +492,8 @@ typedef struct {
/** [Jungfrau](chipv1.1) enable current src, fix[fix|no fix],
* select is a mask of 63 bits (muliple columns can be selected
* simultaneously, normal [normal|low] */
currentSrcParameters(bool fixCurrent, uint64_t selectCurrent, bool normalCurrent)
currentSrcParameters(bool fixCurrent, uint64_t selectCurrent,
bool normalCurrent)
: enable(1), fix(static_cast<int>(fixCurrent)),
normal(static_cast<int>(normalCurrent)), select(selectCurrent) {}
@ -562,14 +568,14 @@ inline slsDetectorDefs::streamingInterface
operator|(const slsDetectorDefs::streamingInterface &a,
const slsDetectorDefs::streamingInterface &b) {
return slsDetectorDefs::streamingInterface(static_cast<int32_t>(a) |
static_cast<int32_t>(b));
static_cast<int32_t>(b));
};
inline slsDetectorDefs::streamingInterface
operator&(const slsDetectorDefs::streamingInterface &a,
const slsDetectorDefs::streamingInterface &b) {
return slsDetectorDefs::streamingInterface(static_cast<int32_t>(a) &
static_cast<int32_t>(b));
static_cast<int32_t>(b));
};
#endif
@ -647,7 +653,7 @@ struct detParameters {
#ifdef __cplusplus
struct sls_detector_module {
#else
typedef struct {
typedef struct {
#endif
int serialnumber; /**< is the module serial number */
int nchan; /**< is the number of channels on the module*/
@ -718,4 +724,3 @@ using Positions = const std::vector<int> &;
using defs = slsDetectorDefs;
} // namespace sls
#endif

View File

@ -56,6 +56,7 @@ std::string RemoveUnit(std::string &str);
bool is_int(const std::string &s);
bool replace_first(std::string *s, const std::string& substr, const std::string& repl);
bool replace_first(std::string *s, const std::string &substr,
const std::string &repl);
} // namespace sls

View File

@ -1,15 +1,15 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
/** API versions */
#define GITBRANCH "6.0.0-rc1"
#define GITBRANCH "6.0.0-rc1"
#define APILIB 0x211008
#define APIRECEIVER 0x211007
#define APIGUI 0x210819
#define APICTB 0x211019
#define APIGOTTHARD 0x211019
#define APILIB 0x211008
#define APIRECEIVER 0x211007
#define APIGUI 0x210819
#define APICTB 0x211019
#define APIGOTTHARD 0x211019
#define APIGOTTHARD2 0x211019
#define APIMYTHEN3 0x211019
#define APIMOENCH 0x211019
#define APIEIGER 0x211019
#define APIJUNGFRAU 0x211019
#define APIMYTHEN3 0x211019
#define APIMOENCH 0x211019
#define APIEIGER 0x211019
#define APIJUNGFRAU 0x211019

View File

@ -2,8 +2,8 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "sls/DataSocket.h"
#include "sls/logger.h"
#include "sls/sls_detector_funcs.h"
#include "sls/sls_detector_exceptions.h"
#include "sls/sls_detector_funcs.h"
#include <algorithm>
#include <arpa/inet.h>
#include <cassert>
@ -44,9 +44,7 @@ DataSocket &DataSocket::operator=(DataSocket &&move) noexcept {
return *this;
}
void DataSocket::setFnum(const int fnum) {
fnum_ = fnum;
}
void DataSocket::setFnum(const int fnum) { fnum_ = fnum; }
int DataSocket::Receive(void *buffer, size_t size) {
// TODO!(Erik) Add sleep? how many reties?
@ -65,7 +63,8 @@ int DataSocket::Receive(void *buffer, size_t size) {
} else {
std::ostringstream ss;
ss << "TCP socket read " << bytes_read << " bytes instead of "
<< bytes_expected << " bytes (" << getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
<< bytes_expected << " bytes ("
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
throw sls::SocketError(ss.str());
}
}
@ -90,7 +89,8 @@ int DataSocket::Send(const void *buffer, size_t size) {
if (bytes_sent != data_size) {
std::ostringstream ss;
ss << "TCP socket sent " << bytes_sent << " bytes instead of "
<< data_size << " bytes (" << getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
<< data_size << " bytes ("
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
throw sls::SocketError(ss.str());
}
return bytes_sent;

View File

@ -252,7 +252,7 @@ std::string ToString(const defs::speedLevel s) {
case defs::G2_108MHZ:
return std::string("108");
case defs::G2_144MHZ:
return std::string("144");
return std::string("144");
default:
return std::string("Unknown");
}

6
slsSupportLib/src/string_utils.cpp Executable file → Normal file
View File

@ -38,14 +38,14 @@ bool is_int(const std::string &s) {
}) == s.end();
}
bool replace_first(std::string *s, const std::string& substr, const std::string& repl){
bool replace_first(std::string *s, const std::string &substr,
const std::string &repl) {
auto pos = s->find(substr);
if (pos != std::string::npos){
if (pos != std::string::npos) {
s->replace(pos, substr.size(), repl);
return true;
}
return false;
}
}; // namespace sls

View File

@ -4,7 +4,6 @@
#include "sls/ClientSocket.h"
#include "sls/ServerSocket.h"
#include <chrono>
#include <thread>
#include <future>
#include <iostream>
#include <thread>

View File

@ -331,12 +331,12 @@ TEST_CASE("streamingInterface") {
REQUIRE(ToString(sls::defs::streamingInterface::ETHERNET_10GB) == "10gbe");
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK) == "lll");
REQUIRE(ToString(sls::defs::streamingInterface::LOW_LATENCY_LINK |
sls::defs::streamingInterface::ETHERNET_10GB) == "lll, 10gbe");
sls::defs::streamingInterface::ETHERNET_10GB) ==
"lll, 10gbe");
}
//Speed level
TEST_CASE("speedLevel to string"){
// Speed level
TEST_CASE("speedLevel to string") {
REQUIRE(ToString(sls::defs::speedLevel::FULL_SPEED) == "full_speed");
REQUIRE(ToString(sls::defs::speedLevel::HALF_SPEED) == "half_speed");
REQUIRE(ToString(sls::defs::speedLevel::QUARTER_SPEED) == "quarter_speed");
@ -344,10 +344,15 @@ TEST_CASE("speedLevel to string"){
REQUIRE(ToString(sls::defs::speedLevel::G2_144MHZ) == "144");
}
TEST_CASE("string to speedLevel"){
REQUIRE(StringTo<sls::defs::speedLevel>("full_speed") == sls::defs::speedLevel::FULL_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("half_speed") == sls::defs::speedLevel::HALF_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("quarter_speed") == sls::defs::speedLevel::QUARTER_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("108") == sls::defs::speedLevel::G2_108MHZ);
REQUIRE(StringTo<sls::defs::speedLevel>("144") == sls::defs::speedLevel::G2_144MHZ);
TEST_CASE("string to speedLevel") {
REQUIRE(StringTo<sls::defs::speedLevel>("full_speed") ==
sls::defs::speedLevel::FULL_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("half_speed") ==
sls::defs::speedLevel::HALF_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("quarter_speed") ==
sls::defs::speedLevel::QUARTER_SPEED);
REQUIRE(StringTo<sls::defs::speedLevel>("108") ==
sls::defs::speedLevel::G2_108MHZ);
REQUIRE(StringTo<sls::defs::speedLevel>("144") ==
sls::defs::speedLevel::G2_144MHZ);
}

View File

@ -114,19 +114,16 @@ TEST_CASE("Copy construct a MacAddr") {
CHECK(addr == addr2);
}
TEST_CASE("udp dst struct basic properties"){
TEST_CASE("udp dst struct basic properties") {
static_assert(sizeof(UdpDestination) == 36);
UdpDestination dst{};
REQUIRE(dst.entry == 0);
REQUIRE(dst.port == 0);
REQUIRE(dst.port2 == 0);
REQUIRE(dst.ip == 0);
REQUIRE(dst.ip2 == 0);
REQUIRE(dst.mac == 0);
REQUIRE(dst.mac2 == 0);
REQUIRE(dst.entry == 0);
REQUIRE(dst.port == 0);
REQUIRE(dst.port2 == 0);
REQUIRE(dst.ip == 0);
REQUIRE(dst.ip2 == 0);
REQUIRE(dst.mac == 0);
REQUIRE(dst.mac2 == 0);
}
// TODO!(Erik) Look up a real hostname and verify the IP

View File

@ -78,29 +78,28 @@ TEST_CASE("Check is string is integer") {
REQUIRE_FALSE(sls::is_int(""));
}
TEST_CASE("Replace substring in string"){
TEST_CASE("Replace substring in string") {
std::string s = "this string should be replaced";
auto r = sls::replace_first(&s, "string ", "");
REQUIRE(r == true);
REQUIRE(s == "this should be replaced");
}
TEST_CASE("Replace --help in command"){
TEST_CASE("Replace --help in command") {
std::string s = "sls_detector_get --help exptime";
auto r = sls::replace_first(&s, " --help", "");
REQUIRE(r == true);
REQUIRE(s == "sls_detector_get exptime");
}
TEST_CASE("Replace -h in command"){
TEST_CASE("Replace -h in command") {
std::string s = "sls_detector_get -h exptime";
auto r = sls::replace_first(&s, " -h", "");
REQUIRE(r == true);
REQUIRE(s == "sls_detector_get exptime");
}
TEST_CASE("replace --help"){
TEST_CASE("replace --help") {
std::string s = "list --help";
auto r = sls::replace_first(&s, " --help", "");
REQUIRE(r == true);