M3defaultpattern (#227)

* default pattern for m3 and moench including Python bindings

Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
This commit is contained in:
Dhanya Thattil
2020-12-09 13:28:39 +01:00
committed by GitHub
parent 85bc37f04d
commit a62e068a9a
22 changed files with 159 additions and 62 deletions

View File

@ -1,8 +1,8 @@
#pragma once
#include "sls/Pattern.h"
#include "sls/Result.h"
#include "sls/network_utils.h"
#include "sls/sls_detector_defs.h"
#include "sls/Pattern.h"
#include <chrono>
#include <map>
#include <memory>
@ -16,7 +16,6 @@ class DetectorImpl;
class MacAddr;
class IpAddr;
// Free function to avoid dependence on class
// and avoid the option to free another objects
// shm by mistake
@ -1461,12 +1460,15 @@ class Detector {
/** [CTB][Moench][Mythen3] Loads pattern parameters structure directly to
* server */
void setPattern(const Pattern& pat, Positions pos = {});
void setPattern(const Pattern &pat, Positions pos = {});
/** [CTB][Moench][Mythen3] [Ctb][Moench][Mythen3] Saves pattern to file
* (ascii). \n [Ctb][Moench] Also executes pattern.*/
void savePattern(const std::string &fname);
/** [Mythen3][Moench] Loads and runs default pattern */
void loadDefaultPattern(Positions pos = {});
/** [CTB][Moench] */
Result<uint64_t> getPatternIOControl(Positions pos = {}) const;

View File

@ -1014,6 +1014,7 @@ class CmdProxy {
/* Pattern */
{"pattern", &CmdProxy::Pattern},
{"savepattern", &CmdProxy::savepattern},
{"defaultpattern", &CmdProxy::defaultpattern},
{"patioctrl", &CmdProxy::patioctrl},
{"patword", &CmdProxy::PatternWord},
{"patlimits", &CmdProxy::PatternLoopAddresses},
@ -2063,6 +2064,11 @@ class CmdProxy {
"[fname]\n\t[Ctb][Moench][Mythen3] Saves pattern to file (ascii). "
"\n\t[Ctb][Moench] Also executes pattern.");
EXECUTE_SET_COMMAND(
defaultpattern, loadDefaultPattern,
"\n\t[Mythen3][Moench] Loads and runs default pattern in pattern "
"generator. It is to go back to initial settings.");
INTEGER_COMMAND_HEX_WIDTH16(patioctrl, getPatternIOControl,
setPatternIOControl, StringTo<uint64_t>,
"[64 bit mask]\n\t[Ctb][Moench] 64 bit mask "

View File

@ -1754,13 +1754,6 @@ void Detector::setLEDEnable(bool enable, Positions pos) {
// Pattern
void Detector::savePattern(const std::string &fname) {
auto t = pimpl->Parallel(&Module::getPattern, {});
auto pat = t.tsquash("Inconsistent pattern parameters between modules");
pat.validate();
pat.save(fname);
}
void Detector::setPattern(const std::string &fname, Positions pos) {
Pattern pat;
pat.load(fname);
@ -1773,6 +1766,17 @@ void Detector::setPattern(const Pattern &pat, Positions pos) {
pimpl->Parallel(&Module::setPattern, pos, pat);
}
void Detector::savePattern(const std::string &fname) {
auto t = pimpl->Parallel(&Module::getPattern, {});
auto pat = t.tsquash("Inconsistent pattern parameters between modules");
pat.validate();
pat.save(fname);
}
void Detector::loadDefaultPattern(Positions pos) {
pimpl->Parallel(&Module::loadDefaultPattern, pos);
}
Result<uint64_t> Detector::getPatternIOControl(Positions pos) const {
return pimpl->Parallel(&Module::getPatternIOControl, pos);
}

View File

@ -1923,6 +1923,8 @@ Pattern Module::getPattern() {
return pat;
}
void Module::loadDefaultPattern() { sendToDetector(F_LOAD_DEFAULT_PATTERN); }
uint64_t Module::getPatternIOControl() const {
return sendToDetector<uint64_t>(F_SET_PATTERN_IO_CONTROL,
int64_t(GET_FLAG));

View File

@ -1,11 +1,11 @@
#pragma once
#include "SharedMemory.h"
#include "sls/ClientSocket.h"
#include "sls/Pattern.h"
#include "sls/StaticVector.h"
#include "sls/logger.h"
#include "sls/network_utils.h"
#include "sls/sls_detector_defs.h"
#include "sls/Pattern.h"
#include <array>
#include <cmath>
@ -463,8 +463,9 @@ class Module : public virtual slsDetectorDefs {
* Pattern *
* *
* ************************************************/
void setPattern(const Pattern& pat);
void setPattern(const Pattern &pat);
Pattern getPattern();
void loadDefaultPattern();
uint64_t getPatternIOControl() const;
void setPatternIOControl(uint64_t word);
uint64_t getPatternWord(int addr) const;

View File

@ -46,6 +46,19 @@ TEST_CASE("savepattern", "[.cmd]") {
}
}
TEST_CASE("defaultpattern", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MOENCH || det_type == defs::MYTHEN3) {
REQUIRE_THROWS(proxy.Call("defaultpattern", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("defaultpattern", {}, -1, PUT));
} else {
REQUIRE_THROWS(proxy.Call("defaultpattern", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("defaultpattern", {}, -1, PUT));
}
}
TEST_CASE("patioctrl", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);