mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-18 15:57:13 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
184
slsDetectorSoftware/src/CmdProxy.cpp
Normal file
184
slsDetectorSoftware/src/CmdProxy.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
#include "CmdProxy.h"
|
||||
|
||||
|
||||
#include "TimeHelper.h"
|
||||
#include "ToString.h"
|
||||
#include "logger.h"
|
||||
#include "slsDetectorCommand.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#define TIME_COMMAND(GETFCN, SETFCN, HLPSTR) \
|
||||
std::ostringstream os; \
|
||||
os << cmd << ' '; \
|
||||
if (action == slsDetectorDefs::HELP_ACTION) \
|
||||
os << HLPSTR << '\n'; \
|
||||
else if (action == slsDetectorDefs::GET_ACTION) { \
|
||||
auto t = det->GETFCN({det_id}); \
|
||||
if (args.size() == 0) { \
|
||||
os << OutString(t) << '\n'; \
|
||||
} else if (args.size() == 1) { \
|
||||
os << OutString(t, args[0]) << '\n'; \
|
||||
} else { \
|
||||
WrongNumberOfParameters(2); \
|
||||
} \
|
||||
} else if (action == slsDetectorDefs::PUT_ACTION) { \
|
||||
if (args.size() == 1) { \
|
||||
std::string time_str(args[0]); \
|
||||
std::string unit = RemoveUnit(time_str); \
|
||||
auto t = StringTo<time::ns>(time_str, unit); \
|
||||
det->SETFCN(t, {det_id}); \
|
||||
} else if (args.size() == 2) { \
|
||||
auto t = StringTo<time::ns>(args[0], args[1]); \
|
||||
det->SETFCN(t, {det_id}); \
|
||||
} else { \
|
||||
WrongNumberOfParameters(2); \
|
||||
} \
|
||||
os << args << '\n'; \
|
||||
} else { \
|
||||
throw sls::RuntimeError("Unknown action"); \
|
||||
} \
|
||||
return os.str();
|
||||
|
||||
|
||||
|
||||
namespace sls {
|
||||
|
||||
std::ostream &operator<<(std::ostream &os,
|
||||
const std::vector<std::string> &vec) {
|
||||
if (!vec.empty()) {
|
||||
auto it = vec.begin();
|
||||
os << *it++;
|
||||
while (it != vec.end())
|
||||
os << ' ' << *it++;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string CmdProxy::Call(const std::string &command,
|
||||
const std::vector<std::string> &arguments,
|
||||
int detector_id, int action, std::ostream &os) {
|
||||
cmd = command;
|
||||
args = arguments;
|
||||
det_id = detector_id;
|
||||
|
||||
ReplaceIfDepreciated(cmd);
|
||||
|
||||
auto it = functions.find(cmd);
|
||||
if (it != functions.end()) {
|
||||
os << ((*this).*(it->second))(action);
|
||||
return {};
|
||||
} else {
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
bool CmdProxy::ReplaceIfDepreciated(std::string &command) {
|
||||
auto d_it = depreciated_functions.find(command);
|
||||
if (d_it != depreciated_functions.end()) {
|
||||
FILE_LOG(logWARNING)
|
||||
<< command
|
||||
<< " is depreciated and will be removed. Please migrate to: "
|
||||
<< d_it->second;
|
||||
command = d_it->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> CmdProxy::GetAllCommands() {
|
||||
auto commands = slsDetectorCommand(nullptr).getAllCommands();
|
||||
for (const auto &it : functions)
|
||||
commands.emplace_back(it.first);
|
||||
std::sort(begin(commands), end(commands));
|
||||
return commands;
|
||||
}
|
||||
|
||||
std::vector<std::string> CmdProxy::GetProxyCommands() {
|
||||
std::vector<std::string> commands;
|
||||
for (const auto &it : functions)
|
||||
commands.emplace_back(it.first);
|
||||
std::sort(begin(commands), end(commands));
|
||||
return commands;
|
||||
}
|
||||
|
||||
void CmdProxy::WrongNumberOfParameters(size_t expected) {
|
||||
throw RuntimeError(
|
||||
"Command " + cmd + " expected <=" + std::to_string(expected) +
|
||||
" parameter/s but got " + std::to_string(args.size()) + "\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************************************
|
||||
* *
|
||||
* COMMANDS *
|
||||
* *
|
||||
************************************************/
|
||||
|
||||
std::string CmdProxy::Period(int action) {
|
||||
TIME_COMMAND(getPeriod, setPeriod,
|
||||
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the period");
|
||||
}
|
||||
std::string CmdProxy::Exptime(int action) {
|
||||
TIME_COMMAND(
|
||||
getExptime, setExptime,
|
||||
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the exposure time");
|
||||
}
|
||||
std::string CmdProxy::SubExptime(int action) {
|
||||
TIME_COMMAND(getSubExptime, setSubExptime,
|
||||
"[duration] [(optional unit) ns|us|ms|s]\n\tSet the "
|
||||
"exposure time of EIGER subframes");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::string CmdProxy::ListCommands(int action) {
|
||||
if (action == slsDetectorDefs::HELP_ACTION)
|
||||
return "list\n\tlists all available commands, list deprecated - "
|
||||
"list deprecated commands\n";
|
||||
|
||||
if (args.size() == 0) {
|
||||
auto commands = slsDetectorCommand(nullptr).getAllCommands();
|
||||
for (const auto &it : functions)
|
||||
commands.emplace_back(it.first);
|
||||
std::sort(begin(commands), end(commands));
|
||||
|
||||
std::cout << "These " << commands.size() << " commands are available\n";
|
||||
for (auto &c : commands)
|
||||
std::cout << c << '\n';
|
||||
return "";
|
||||
} else if (args.size() == 1) {
|
||||
if (args[0] == "deprecated") {
|
||||
std::cout << "The following " << depreciated_functions.size()
|
||||
<< " commands are deprecated\n";
|
||||
size_t field_width = 20;
|
||||
for (const auto &it : depreciated_functions) {
|
||||
std::cout << std::right << std::setw(field_width) << it.first
|
||||
<< " -> " << it.second << '\n';
|
||||
}
|
||||
return "";
|
||||
} else if (args[0] == "migrated") {
|
||||
std::cout << "The following " << functions.size()
|
||||
<< " commands have been migrated to the new API\n";
|
||||
for (const auto &it : functions) {
|
||||
std::cout << it.first << '\n';
|
||||
}
|
||||
return "";
|
||||
} else {
|
||||
throw RuntimeError(
|
||||
"Could not decode argument. Possible options: deprecated");
|
||||
}
|
||||
} else {
|
||||
WrongNumberOfParameters(1);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sls
|
@ -578,7 +578,7 @@ void Detector::setFileNamePrefix(const std::string &fname, Positions pos) {
|
||||
pimpl->Parallel(&slsDetector::setFileName, pos, fname);
|
||||
}
|
||||
|
||||
Result<int> Detector::getAcquisitonIndex(Positions pos) const {
|
||||
Result<int> Detector::getAcquisitionIndex(Positions pos) const {
|
||||
return pimpl->Parallel(&slsDetector::getFileIndex, pos);
|
||||
}
|
||||
|
||||
@ -631,7 +631,7 @@ void Detector::setRxZmqDataStream(bool enable, Positions pos) {
|
||||
}
|
||||
|
||||
Result<int> Detector::getRxZmqFrequency(Positions pos) const {
|
||||
return pimpl->Parallel(&slsDetector::setReceiverStreamingTimer, pos, -1);
|
||||
return pimpl->Parallel(&slsDetector::setReceiverStreamingFrequency, pos, -1);
|
||||
}
|
||||
|
||||
void Detector::setRxZmqFrequency(int freq, Positions pos) {
|
||||
|
118
slsDetectorSoftware/src/multiSlsDetectorClient.cpp
Normal file
118
slsDetectorSoftware/src/multiSlsDetectorClient.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include "multiSlsDetectorClient.h"
|
||||
#include "CmdProxy.h"
|
||||
#include "Detector.h"
|
||||
#include "multiSlsDetector.h"
|
||||
#include "slsDetectorCommand.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
multiSlsDetectorClient::multiSlsDetectorClient(int argc, char *argv[],
|
||||
int action,
|
||||
multiSlsDetector *myDetector,
|
||||
std::ostream &output)
|
||||
: action_(action), detPtr(myDetector), os(output) {
|
||||
parser.Parse(argc, argv);
|
||||
runCommand();
|
||||
}
|
||||
|
||||
multiSlsDetectorClient::multiSlsDetectorClient(const std::string &args,
|
||||
int action,
|
||||
multiSlsDetector *myDetector,
|
||||
std::ostream &output)
|
||||
: action_(action), detPtr(myDetector), os(output) {
|
||||
parser.Parse(args);
|
||||
runCommand();
|
||||
}
|
||||
|
||||
void multiSlsDetectorClient::runCommand() {
|
||||
if (parser.isHelp())
|
||||
action_ = slsDetectorDefs::HELP_ACTION;
|
||||
bool verify = true;
|
||||
bool update = true;
|
||||
if (action_ == slsDetectorDefs::PUT_ACTION && parser.n_arguments() == 0) {
|
||||
os << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
os << std::endl;
|
||||
return;
|
||||
};
|
||||
if (action_ == slsDetectorDefs::GET_ACTION && parser.command().empty()) {
|
||||
os << "Wrong usage - should be: " << parser.executable()
|
||||
<< "[id-][pos:]channel arg" << std::endl;
|
||||
os << std::endl;
|
||||
return;
|
||||
};
|
||||
|
||||
if (action_ == slsDetectorDefs::READOUT_ACTION &&
|
||||
parser.detector_id() != -1) {
|
||||
os << "detector_id: " << parser.detector_id()
|
||||
<< " ,readout of individual detectors is not allowed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// special commands
|
||||
if (parser.command() == "free") {
|
||||
multiSlsDetector::freeSharedMemory(parser.multi_id(),
|
||||
parser.detector_id());
|
||||
return;
|
||||
} // get user details without verify sharedMultiSlsDetector version
|
||||
else if ((parser.command() == "user") &&
|
||||
(action_ == slsDetectorDefs::GET_ACTION)) {
|
||||
verify = false;
|
||||
update = false;
|
||||
}
|
||||
|
||||
// create multiSlsDetector class if required
|
||||
std::unique_ptr<multiSlsDetector> localDet;
|
||||
if (detPtr == nullptr) {
|
||||
try {
|
||||
localDet = sls::make_unique<multiSlsDetector>(parser.multi_id(),
|
||||
verify, update);
|
||||
detPtr = localDet.get();
|
||||
} catch (const sls::RuntimeError &e) {
|
||||
/*os << e.GetMessage() << std::endl;*/
|
||||
return;
|
||||
} catch (...) {
|
||||
os << " caught exception\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (parser.detector_id() >= static_cast<int>(detPtr->size())) {
|
||||
os << "position is out of bounds.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Call CmdProxy which execute the command if it exists, on success
|
||||
// returns an empty string If the command is not in CmdProxy but
|
||||
// deprecated the new command is returned
|
||||
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
||||
int multi_id = 0;
|
||||
if (detPtr != nullptr)
|
||||
multi_id = detPtr->getMultiId();
|
||||
sls::Detector d(multi_id);
|
||||
sls::CmdProxy proxy(&d);
|
||||
auto cmd = proxy.Call(parser.command(), parser.arguments(),
|
||||
parser.detector_id(), action_, os);
|
||||
if (cmd.empty()) {
|
||||
return;
|
||||
} else {
|
||||
parser.setCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
// call multi detector command line
|
||||
slsDetectorCommand myCmd(detPtr);
|
||||
std::string answer =
|
||||
myCmd.executeLine(parser.n_arguments() + 1, parser.argv().data(),
|
||||
action_, parser.detector_id());
|
||||
|
||||
if (parser.multi_id() != 0)
|
||||
os << parser.multi_id() << '-';
|
||||
if (parser.detector_id() != -1)
|
||||
os << parser.detector_id() << ':';
|
||||
|
||||
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
||||
os << parser.command() << " ";
|
||||
}
|
||||
os << answer << std::endl;
|
||||
}
|
@ -534,27 +534,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTiming;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>exptime [i]</b> sets/gets exposure time in s. \c Returns \c (double with 9 decimal digits)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "exptime";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>subexptime [i]</b> sets/gets sub exposure time in s. Used in EIGER only in 32 bit mode. \c Returns \c (double with 9 decimal digits)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "subexptime";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>period [i]</b> sets/gets frame period in s. \c Returns \c (double with 9 decimal digits)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "period";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>subdeadtime [i]</b> sets/gets sub frame dead time in s. Subperiod is set in the detector = subexptime + subdeadtime. This value is normally a constant in the config file. Used in EIGER only in 32 bit mode. \c Returns \c (double with 9 decimal digits)
|
||||
*/
|
||||
@ -569,12 +548,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>frames [i]</b> sets/gets number of frames. If \c timing is not \c auto, then it is the number of frames per cycle/trigger. \c Returns \c (long long int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "frames";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer;
|
||||
++i;
|
||||
|
||||
/*! \page timing
|
||||
- <b>startingfnum [i]</b> sets/gets starting frame number for the next acquisition. Only for Jungfrau and Eiger. \c Returns \c (long long int)
|
||||
@ -1502,27 +1475,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileName;
|
||||
++i;
|
||||
|
||||
/*! \page output
|
||||
- <b>findex [i]</b> Sets/gets the current file index. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "findex";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileIndex;
|
||||
++i;
|
||||
|
||||
/*! \page output
|
||||
- <b>fwrite [i]</b> Enables/disables file writing. 1 enables, 0 disables. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "fwrite";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdEnablefwrite;
|
||||
++i;
|
||||
|
||||
/*! \page output
|
||||
- <b>foverwrite [i]</b> enables(1) /disables(0) file overwriting. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "foverwrite";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdOverwrite;
|
||||
++i;
|
||||
|
||||
/*! \page output
|
||||
- <b>fformat [i]</b> sets/gets the file format for data in receiver. Options: [binary, hdf5]. \c Returns \c (string)
|
||||
*/
|
||||
@ -1530,13 +1482,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdFileName;
|
||||
++i;
|
||||
|
||||
/*! \page output
|
||||
- <b>fmaster [i]</b> sets/gets the master file write enable in receiver. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "fmaster";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdEnablefwrite;
|
||||
++i;
|
||||
|
||||
/* communication configuration */
|
||||
|
||||
/*! \page network Network
|
||||
@ -1736,13 +1681,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPort;
|
||||
++i;
|
||||
|
||||
/*! \page network
|
||||
- <b>lock [i]</b> Locks/Unlocks the detector to communicate with this client. 1 locks, 0 unlocks. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "lock";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLock;
|
||||
++i;
|
||||
|
||||
/*! \page network
|
||||
- <b>lastclient </b> Gets the last client communicating with the detector. Cannot put!. \c Returns \c (string)
|
||||
*/
|
||||
@ -1784,13 +1722,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_lock [i]</b> locks/unlocks the receiver to communicate with only this client. 1 locks, 0 unlocks. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "rx_lock";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLock;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_lastclient</b> gets the last client communicating with the receiver. Only get! \c Returns \c (int)
|
||||
*/
|
||||
@ -1798,27 +1729,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdLastClient;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_readfreq [i]</b> sets/gets the stream frequency of data from receiver to client. i > 0 is the nth frame being streamed. 0 sets frequency to a default timer (200ms). Default: sends every frame \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "rx_readfreq";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_fifodepth [i]</b> sets/gets receiver fifo (between Listener and Writer Threads) depth to i number of frames. Can improve listener packet loss (loss due to packet processing time in Listener threads), not if limited by writing. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "rx_fifodepth";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_silent [i]</b> sets/gets receiver in silent mode, ie. it will not print anything during real time acquisition. 1 sets, 0 unsets. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "rx_silent";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_framesperfile [i]</b> sets/gets the frames per file in receiver to i. 0 means infinite or all frames in a single file. \c Returns \c (int)
|
||||
*/
|
||||
@ -1833,13 +1743,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_padding</b> sets/gets the frame padding in the receiver. 0 does not pad partial frames(fastest), 1 (default) pads partial frames. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "rx_padding";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdReceiver;
|
||||
++i;
|
||||
|
||||
/*! \page receiver
|
||||
- <b>rx_jsonaddheader [t]</b> sets/gets additional json header to be streamed out with the zmq from receiver. Default is empty. \c t must be in the format "\"label1\":\"value1\",\"label2\":\"value2\"" etc. Use only if it needs to be processed by an intermediate process. \c Returns \c (string)
|
||||
*/
|
||||
@ -2565,94 +2468,6 @@ std::string slsDetectorCommand::helpFileName(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdEnablefwrite(int narg, const char * const args[], int action, int detPos) {
|
||||
|
||||
int i;
|
||||
char ans[100];
|
||||
if (action == HELP_ACTION) {
|
||||
return helpEnablefwrite(action);
|
||||
}
|
||||
if (cmd == "fwrite") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &i))
|
||||
myDet->setFileWrite(i, detPos);
|
||||
else
|
||||
return std::string("could not decode enable file write");
|
||||
}
|
||||
sprintf(ans, "%d", myDet->getFileWrite(detPos));
|
||||
return std::string(ans);
|
||||
}
|
||||
|
||||
else if (cmd == "fmaster") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &i))
|
||||
myDet->setMasterFileWrite(i, detPos);
|
||||
else
|
||||
return std::string("could not decode master file enable");
|
||||
}
|
||||
sprintf(ans, "%d", myDet->getMasterFileWrite(detPos));
|
||||
return std::string(ans);
|
||||
}
|
||||
|
||||
else return std::string("unknown command " + cmd);
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::helpEnablefwrite(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == GET_ACTION || action == HELP_ACTION) {
|
||||
os << std::string("fwrite \t When Enabled writes the data into the file\n");
|
||||
os << std::string("fmaster \t When Enabled writes the master file\n");
|
||||
}
|
||||
if (action == PUT_ACTION || action == HELP_ACTION) {
|
||||
os << std::string("fwrite i \t should be 1 or 0\n");
|
||||
os << std::string("fmaster i \t sets the master file write enable. should be 1 or 0\n");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdOverwrite(int narg, const char * const args[], int action, int detPos) {
|
||||
int i;
|
||||
char ans[100];
|
||||
if (action == HELP_ACTION) {
|
||||
return helpOverwrite(action);
|
||||
}
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &i))
|
||||
myDet->setFileOverWrite(i, detPos);
|
||||
else
|
||||
return std::string("could not decode foverwrite");
|
||||
}
|
||||
sprintf(ans, "%d", myDet->getFileOverWrite(detPos));
|
||||
return std::string(ans);
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::helpOverwrite(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == GET_ACTION || action == HELP_ACTION)
|
||||
os << std::string("foverwrite \t When Enabled overwrites files\n");
|
||||
if (action == PUT_ACTION || action == HELP_ACTION)
|
||||
os << std::string("foverwrite i \t should be 1 or 0 or -1\n");
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdFileIndex(int narg, const char * const args[], int action, int detPos) {
|
||||
if (action == HELP_ACTION) {
|
||||
return helpFileName(action);
|
||||
} else if (action == PUT_ACTION) {
|
||||
int i = std::stoi(args[1]);
|
||||
myDet->setFileIndex(i, detPos);
|
||||
}
|
||||
return std::to_string(myDet->getFileIndex(detPos));
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::helpFileIndex(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == GET_ACTION || action == HELP_ACTION)
|
||||
os << std::string("findex \t gets the file index for the next the data file\n");
|
||||
if (action == PUT_ACTION || action == HELP_ACTION)
|
||||
os << std::string("findex i \t sets the fileindex for the next data file\n");
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdRateCorr(int narg, const char * const args[], int action, int detPos) {
|
||||
|
||||
@ -3040,55 +2855,6 @@ std::string slsDetectorCommand::helpPort(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdLock(int narg, const char * const args[], int action, int detPos) {
|
||||
|
||||
if (action == HELP_ACTION)
|
||||
return helpLock(action);
|
||||
|
||||
int val; //, ret;
|
||||
char ans[1000];
|
||||
|
||||
if (cmd == "lock") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &val))
|
||||
myDet->lockServer(val, detPos);
|
||||
else
|
||||
return std::string("could not lock status") + std::string(args[1]);
|
||||
}
|
||||
|
||||
sprintf(ans, "%d", myDet->lockServer(-1, detPos));
|
||||
}
|
||||
|
||||
else if (cmd == "rx_lock") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &val))
|
||||
myDet->lockReceiver(val, detPos);
|
||||
else
|
||||
return std::string("could not decode lock status") + std::string(args[1]);
|
||||
}
|
||||
sprintf(ans, "%d", myDet->lockReceiver(-1, detPos));
|
||||
}
|
||||
|
||||
else
|
||||
return std::string("could not decode command");
|
||||
|
||||
return std::string(ans);
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::helpLock(int action) {
|
||||
|
||||
std::ostringstream os;
|
||||
if (action == PUT_ACTION || action == HELP_ACTION) {
|
||||
os << "lock i \n locks (1) or unlocks (0) the detector to communicate to this client" << std::endl;
|
||||
os << "rx_lock i \n locks (1) or unlocks (0) the receiver to communicate to this client" << std::endl;
|
||||
}
|
||||
if (action == GET_ACTION || action == HELP_ACTION) {
|
||||
os << "lock \n returns the detector lock status" << std::endl;
|
||||
os << "rx_lock \n returns the receiver lock status" << std::endl;
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdLastClient(int narg, const char * const args[], int action, int detPos) {
|
||||
|
||||
if (action == HELP_ACTION)
|
||||
@ -4266,8 +4032,6 @@ std::string slsDetectorCommand::cmdTimer(int narg, const char * const args[], in
|
||||
index = SUBFRAME_DEADTIME;
|
||||
else if (cmd == "delay")
|
||||
index = DELAY_AFTER_TRIGGER;
|
||||
else if (cmd == "frames")
|
||||
index = FRAME_NUMBER;
|
||||
else if (cmd == "cycles")
|
||||
index = CYCLES_NUMBER;
|
||||
// also does digital sample
|
||||
@ -4894,18 +4658,7 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[],
|
||||
sprintf(answer, "%lu", myDet->getReceiverCurrentFrameIndex(detPos));
|
||||
return std::string(answer);
|
||||
}
|
||||
} else if (cmd == "rx_readfreq") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (!sscanf(args[1], "%d", &ival))
|
||||
return std::string("Could not scan read frequency mode ") + std::string(args[1]);
|
||||
if (ival >= 0)
|
||||
myDet->setReceiverStreamingFrequency(ival, detPos);
|
||||
}
|
||||
sprintf(answer, "%d", myDet->setReceiverStreamingFrequency(-1, detPos));
|
||||
return std::string(answer);
|
||||
|
||||
}
|
||||
|
||||
else if (cmd == "tengiga") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (!sscanf(args[1], "%d", &ival))
|
||||
@ -4918,30 +4671,6 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[],
|
||||
|
||||
}
|
||||
|
||||
else if (cmd == "rx_fifodepth") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (!sscanf(args[1], "%d", &ival))
|
||||
return std::string("Could not scan rx_fifodepth input ") + std::string(args[1]);
|
||||
if (ival >= 0)
|
||||
sprintf(answer, "%d", myDet->setReceiverFifoDepth(ival, detPos));
|
||||
} else
|
||||
sprintf(answer, "%d", myDet->setReceiverFifoDepth(-1, detPos));
|
||||
return std::string(answer);
|
||||
|
||||
}
|
||||
|
||||
else if (cmd == "rx_silent") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (!sscanf(args[1], "%d", &ival))
|
||||
return std::string("Could not scan rx_silent input ") + std::string(args[1]);
|
||||
if (ival >= 0)
|
||||
sprintf(answer, "%d", myDet->setReceiverSilentMode(ival, detPos));
|
||||
} else
|
||||
sprintf(answer, "%d", myDet->setReceiverSilentMode(-1, detPos));
|
||||
return std::string(answer);
|
||||
|
||||
}
|
||||
|
||||
else if (cmd == "rx_framesperfile") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &ival)) {
|
||||
@ -4964,18 +4693,6 @@ std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[],
|
||||
return myDet->getReceiverFrameDiscardPolicy(myDet->setReceiverFramesDiscardPolicy(GET_FRAME_DISCARD_POLICY, detPos));
|
||||
}
|
||||
|
||||
else if (cmd == "rx_padding") {
|
||||
if (action == PUT_ACTION) {
|
||||
if (sscanf(args[1], "%d", &ival)) {
|
||||
myDet->setPartialFramesPadding(ival, detPos);
|
||||
} else
|
||||
return std::string("could not scan receiver padding enable\n");
|
||||
}
|
||||
memset(answer, 0, 100);
|
||||
sprintf(answer, "%d", myDet->getPartialFramesPadding(detPos));
|
||||
return std::string(answer);
|
||||
}
|
||||
|
||||
else if (cmd == "rx_jsonaddheader") {
|
||||
if (action == PUT_ACTION) {
|
||||
myDet->setAdditionalJsonHeader(args[1], detPos);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "multiSlsDetectorClient.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "versionAPI.h"
|
||||
#include <cstdlib>
|
||||
|
||||
#include <cstring> //strcmp
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
|
Reference in New Issue
Block a user