Introduced pattern class

This commit is contained in:
Erik Frojdh
2020-11-27 10:03:15 +01:00
parent 8ca1d9c50c
commit d9b2a90651
22 changed files with 384 additions and 118 deletions

View File

@ -10,7 +10,7 @@ set(SOURCES
src/ZmqSocket.cpp
src/UdpRxSocket.cpp
src/sls_detector_exceptions.cpp
src/sls_detector_defs.cpp
# src/sls_detector_defs.cpp
)
# Header files to install as a part of the library

View File

@ -44,9 +44,9 @@ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi);
std::string ToString(const slsDetectorDefs::rxParameters &r);
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::rxParameters &r);
std::string ToString(const slsDetectorDefs::patternParameters &r);
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::patternParameters &r);
// std::string ToString(const slsDetectorDefs::patternParameters &r);
// std::ostream &operator<<(std::ostream &os,
// const slsDetectorDefs::patternParameters &r);
std::string ToString(const slsDetectorDefs::scanParameters &r);
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::scanParameters &r);

View File

@ -475,34 +475,34 @@ typedef struct {
} __attribute__((packed));
#endif
/** pattern structure */
#ifdef __cplusplus
struct patternParameters {
#else
typedef struct __attribute__((packed)) {
#endif
uint64_t word[MAX_PATTERN_LENGTH];
uint64_t ioctrl;
uint32_t limits[2];
// loop0 start, loop0 stop .. loop2 start, loop2 stop
uint32_t loop[6];
uint32_t nloop[3];
uint32_t wait[3];
uint64_t waittime[3];
#ifdef __cplusplus
public:
patternParameters() {
// Since the def has to be c compatible we can't use {} for the
// members
memset(this, 0, sizeof(patternParameters));
}
void load(const std::string &fname);
void save(const std::string &fname);
void validate() const;
} __attribute__((packed));
#else
} patternParameters;
#endif
// /** pattern structure */
// #ifdef __cplusplus
// struct patternParameters {
// #else
// typedef struct __attribute__((packed)) {
// #endif
// uint64_t word[MAX_PATTERN_LENGTH];
// uint64_t ioctrl;
// uint32_t limits[2];
// // loop0 start, loop0 stop .. loop2 start, loop2 stop
// uint32_t loop[6];
// uint32_t nloop[3];
// uint32_t wait[3];
// uint64_t waittime[3];
// #ifdef __cplusplus
// public:
// patternParameters() {
// // Since the def has to be c compatible we can't use {} for the
// // members
// memset(this, 0, sizeof(patternParameters));
// }
// void load(const std::string &fname);
// void save(const std::string &fname);
// void validate() const;
// } __attribute__((packed));
// #else
// } patternParameters;
// #endif
#ifdef __cplusplus
protected:

View File

@ -88,43 +88,43 @@ std::ostream &operator<<(std::ostream &os,
return os << ToString(r);
}
std::string ToString(const slsDetectorDefs::patternParameters &r) {
std::ostringstream oss;
oss << '[' << std::setfill('0') << std::endl;
int addr_width = 4;
int word_width = 16;
for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) {
if (r.word[i] != 0) {
oss << "patword " << ToStringHex(i, addr_width) << " "
<< ToStringHex(r.word[i], word_width) << std::endl;
}
}
oss << "patioctrl " << ToStringHex(r.ioctrl, word_width) << std::endl
<< "patlimits " << ToStringHex(r.limits[0], addr_width) << " "
<< ToStringHex(r.limits[1], addr_width) << std::endl
<< "patloop0 " << ToStringHex(r.loop[0], addr_width) << " "
<< ToStringHex(r.loop[1], addr_width) << std::endl
<< "patnloop0 " << r.nloop[0] << std::endl
<< "patloop1 " << ToStringHex(r.loop[2], addr_width) << " "
<< ToStringHex(r.loop[3], addr_width) << std::endl
<< "patnloop1 " << r.nloop[1] << std::endl
<< "patloop2 " << ToStringHex(r.loop[4], addr_width) << " "
<< ToStringHex(r.loop[5], addr_width) << std::endl
<< "patnloop2 " << r.nloop[2] << std::endl
<< "patwait0 " << ToStringHex(r.wait[0], addr_width) << std::endl
<< "patwaittime0 " << r.waittime[0] << std::endl
<< "patwait1 " << ToStringHex(r.wait[1], addr_width) << std::endl
<< "patwaittime1 " << r.waittime[1] << std::endl
<< "patwait2 " << ToStringHex(r.wait[2], addr_width) << std::endl
<< "patwaittime2 " << r.waittime[2] << std::endl
<< ']';
return oss.str();
}
// std::string ToString(const slsDetectorDefs::patternParameters &r) {
// std::ostringstream oss;
// oss << '[' << std::setfill('0') << std::endl;
// int addr_width = 4;
// int word_width = 16;
// for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) {
// if (r.word[i] != 0) {
// oss << "patword " << ToStringHex(i, addr_width) << " "
// << ToStringHex(r.word[i], word_width) << std::endl;
// }
// }
// oss << "patioctrl " << ToStringHex(r.ioctrl, word_width) << std::endl
// << "patlimits " << ToStringHex(r.limits[0], addr_width) << " "
// << ToStringHex(r.limits[1], addr_width) << std::endl
// << "patloop0 " << ToStringHex(r.loop[0], addr_width) << " "
// << ToStringHex(r.loop[1], addr_width) << std::endl
// << "patnloop0 " << r.nloop[0] << std::endl
// << "patloop1 " << ToStringHex(r.loop[2], addr_width) << " "
// << ToStringHex(r.loop[3], addr_width) << std::endl
// << "patnloop1 " << r.nloop[1] << std::endl
// << "patloop2 " << ToStringHex(r.loop[4], addr_width) << " "
// << ToStringHex(r.loop[5], addr_width) << std::endl
// << "patnloop2 " << r.nloop[2] << std::endl
// << "patwait0 " << ToStringHex(r.wait[0], addr_width) << std::endl
// << "patwaittime0 " << r.waittime[0] << std::endl
// << "patwait1 " << ToStringHex(r.wait[1], addr_width) << std::endl
// << "patwaittime1 " << r.waittime[1] << std::endl
// << "patwait2 " << ToStringHex(r.wait[2], addr_width) << std::endl
// << "patwaittime2 " << r.waittime[2] << std::endl
// << ']';
// return oss.str();
// }
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::patternParameters &r) {
return os << ToString(r);
}
// std::ostream &operator<<(std::ostream &os,
// const slsDetectorDefs::patternParameters &r) {
// return os << ToString(r);
// }
std::string ToString(const slsDetectorDefs::scanParameters &r) {
std::ostringstream oss;

View File

@ -2,6 +2,7 @@
#include "sls/TimeHelper.h"
#include "sls/ToString.h"
#include "sls/network_utils.h"
#include "sls/Pattern.h"
#include "sls/sls_detector_defs.h"
#include "sls/container_utils.h"
#include <array>
@ -317,9 +318,9 @@ TEST_CASE("Printing c style arrays of double"){
}
TEST_CASE("Print a member of patternParameters"){
auto pat = sls::make_unique<slsDetectorDefs::patternParameters>();
pat->patlimits[0] = 4;
pat->patlimits[1] = 100;
REQUIRE(ToString(pat->patlimits) == "[4, 100]");
auto pat = sls::make_unique<sls::patternParameters>();
pat->limits[0] = 4;
pat->limits[1] = 100;
REQUIRE(ToString(pat->limits) == "[4, 100]");
}