added functionality to set additional json header key value pairs for prototype ctb, server fixed for eiger compile from ctb integration

This commit is contained in:
maliakal_d 2019-02-13 09:37:31 +01:00
parent 031a11c4f7
commit f9be8b89ac
9 changed files with 161 additions and 21 deletions

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 9d9251293d1a0b5300b8d7191949cf01de1c7b81
Revision: 21
Repsitory UUID: 031a11c4f7b25e8c14532976731aebdc0bb56fe7
Revision: 23
Branch: refactor
Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4255
Last Changed Date: 2019-01-15 10:22:16.000000002 +0100 ./xparameters.h
Last Changed Rev: 4307
Last Changed Date: 2019-02-11 14:53:03.000000002 +0100 ./xparameters.h

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "9d9251293d1a0b5300b8d7191949cf01de1c7b81"
#define GITREPUUID "031a11c4f7b25e8c14532976731aebdc0bb56fe7"
#define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4255
#define GITDATE 0x20190115
#define GITREV 0x4307
#define GITDATE 0x20190211
#define GITBRANCH "refactor"

View File

@ -1359,7 +1359,9 @@ int start_acquisition(int file_des) {
FILE_LOG(logDEBUG1, ("Starting Acquisition\n"));
// only set
if (Server_VerifyLock() == OK) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
nframes = 0;
#endif
ret = startStateMachine();
if (ret == FAIL) {
sprintf(mess, "Could not start acquisition\n");
@ -1444,7 +1446,9 @@ int start_and_read_all(int file_des) {
FILE_LOG(logDEBUG1, ("Stopping Acquisition\n"));
// only set
if (Server_VerifyLock() == OK) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
nframes = 0;
#endif
ret = startStateMachine();
if (ret == FAIL) {
sprintf(mess, "Could not start acquisition\n");
@ -2505,14 +2509,15 @@ int set_ctb_pattern(int file_des) {
uint64_t args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT64) < 0)
return printSocketReadError();
int addr = (int)args[0];
uint64_t word = args[1];
int64_t retval64 = -1;
#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD)
functionNotImplemented();
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
#else
int addr = (int)args[0];
uint64_t word = args[1];
if ((word == -1) || (Server_VerifyLock() == OK)) {
// address for set word should be valid (if not -1 or -2, it goes to setword)
@ -2558,16 +2563,17 @@ int set_ctb_pattern(int file_des) {
uint64_t args[4] = {-1, -1, -1, -1};
if (receiveData(file_des, args, sizeof(args), INT64) < 0)
return printSocketReadError();
int loopLevel = (int)args[0];
int startAddr = (int)args[1];
int stopAddr = (int)args[2];
int numLoops = (int)args[3];
int retvals[3] = {-1, -1, -1};
#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD)
functionNotImplemented();
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
#else
int loopLevel = (int)args[0];
int startAddr = (int)args[1];
int stopAddr = (int)args[2];
int numLoops = (int)args[3];
if (loopLevel < -1 || loopLevel > 2) { // -1 complete pattern
ret = FAIL;
sprintf(mess, "Pattern (Pattern Loop) Level (%d) is not implemented for this detector\n", loopLevel);
@ -2610,14 +2616,15 @@ int set_ctb_pattern(int file_des) {
uint64_t args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT64) < 0)
return printSocketReadError();
int loopLevel = (int)args[0];
int addr = (int)args[1];
int retval32 = -1;
#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD)
functionNotImplemented();
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
#else
int loopLevel = (int)args[0];
int addr = (int)args[1];
if ((addr == -1) || (Server_VerifyLock() == OK)) {
if (loopLevel < 0 || loopLevel > 2) {
ret = FAIL;
@ -2651,14 +2658,15 @@ int set_ctb_pattern(int file_des) {
uint64_t args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT64) < 0)
return printSocketReadError();
int loopLevel = (int)args[1];
uint64_t timeval = (int)args[2];
int64_t retval64 = -1;
#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD)
functionNotImplemented();
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
#else
int loopLevel = (int)args[1];
uint64_t timeval = (int)args[2];
if ((timeval == -1) || (Server_VerifyLock() == OK)) {
if (loopLevel < 0 || loopLevel > 2) {
ret = FAIL;

View File

@ -1934,6 +1934,29 @@ std::string multiSlsDetector::getAdditionalJsonHeader(int detPos) {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setAdditionalJsonParameter(key, value);
}
// multi
auto r = parallelCall(&slsDetector::setAdditionalJsonParameter, key, value);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getAdditionalJsonParameter(const std::string& key, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getAdditionalJsonParameter(key);
}
// multi
auto r = serialCall(&slsDetector::getAdditionalJsonParameter, key);
return sls::concatenateIfDifferent(r);
}
int multiSlsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize, int detPos) {
// single
if (detPos >= 0) {

View File

@ -1057,17 +1057,36 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* Sets the additional json header
* @param jsonheader additional json header
* @param detPos -1 for all detectors in list or specific detector position
* @returns additional json header, returns "none" if default setting and no custom ip set
* @returns additional json header, default is empty
*/
std::string setAdditionalJsonHeader(const std::string& jsonheader, int detPos = -1);
/**
* Returns the additional json header
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header, returns "none" if default setting and no custom ip set
* @returns the additional json header, default is empty
*/
std::string getAdditionalJsonHeader(int detPos = -1);
/**
* Sets the value for the additional json header parameter if found, else append it
* @param key additional json header parameter
* @param value additional json header parameter value (cannot be empty)
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos = -1);
/**
* Returns the additional json header parameter value
* @param key additional json header parameter
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1);
/**
* Sets the receiver UDP socket buffer size
* @param udpsockbufsize additional json header

View File

@ -310,7 +310,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL
list.nGappixelsY = 1;
break;
default:
FILE_LOG(logERROR) << "Unknown detector type!";
FILE_LOG(logERROR) << "Unknown detector type! " << type;
throw std::exception();
}
}
@ -2625,7 +2625,7 @@ std::string slsDetector::setAdditionalJsonHeader(const std::string &jsonheader)
sls::strcpy_safe(args, jsonheader.c_str());
FILE_LOG(logDEBUG1) << "Sending additional json header " << args;
if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) {
auto receiver = sls::ClientSocket(thisDetector->receiver_hostname, thisDetector->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
if (ret == FAIL) {
@ -2646,6 +2646,65 @@ std::string slsDetector::getAdditionalJsonHeader() {
return std::string(thisDetector->receiver_additionalJsonHeader);
}
std::string slsDetector::setAdditionalJsonParameter(const std::string& key, const std::string& value) {
// validation (ignore if key or value has , : ")
if (key.find_first_of(",\":") != std::string::npos || value.find_first_of(",\":") != std::string::npos) {
FILE_LOG(logERROR) << "Could not set additional json header parameter as the key or value has illegal characters (,\":)";
return getAdditionalJsonParameter(key);
}
std::string header(thisDetector->receiver_additionalJsonHeader);
size_t keyPos = header.find(std::string("\"") + key + std::string("\":") );
// if key found, replace value
if (keyPos != std::string::npos) {
size_t valuePosStart = header.find (std::string(":\""), keyPos) + 2;
size_t valuePosEnd = header.find (std::string("\""), valuePosStart) - 1;
header.replace(valuePosStart, valuePosEnd - valuePosStart + 1, value);
}
// key not found, append key value pair
else {
if (header.length()) {
header.append(",");
}
// put it in formula \"key\":\"value\"
header.append(std::string("\"") + key + std::string("\"") + std::string(":")
+ std::string("\"") + value + std::string("\""));
}
// update additional json header
setAdditionalJsonHeader(header);
return getAdditionalJsonParameter(key);
}
std::string slsDetector::getAdditionalJsonParameter(const std::string& key) {
// additional json header is empty
if (!strlen(thisDetector->receiver_additionalJsonHeader))
return std::string("");
// add quotations before and after the key value
std::string keyLiteral = key;
keyLiteral.insert(0, "\"");
keyLiteral.append("\"");
// loop through the parameters
for (const auto &parameter : sls::split(thisDetector->receiver_additionalJsonHeader, ',')) {
// get a vector of key value pair for each parameter
const auto &pairs = sls::split(parameter, ':');
// match for key
if (pairs[0] == keyLiteral) {
// return value without quotations
return pairs[1].substr(1, pairs[1].length() - 2);
}
}
// return empty string as no match found with key
return std::string("");
}
int slsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize) {
int fnum = F_RECEIVER_UDP_SOCK_BUF_SIZE;
int ret = FAIL;

View File

@ -977,6 +977,23 @@ public:
*/
std::string getAdditionalJsonHeader();
/**
* Sets the value for the additional json header parameter if found, else append it
* @param key additional json header parameter
* @param value additional json header parameter value (cannot be empty)
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string setAdditionalJsonParameter(const std::string& key, const std::string& value);
/**
* Returns the additional json header parameter value
* @param key additional json header parameter
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string getAdditionalJsonParameter(const std::string& key);
/**
* Sets the receiver UDP socket buffer size
* @param udpsockbufsize additional json header

View File

@ -1640,6 +1640,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>rx_jsonpara [k] [v]</b> sets/gets value v for additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found Use only if it needs to be processed by an intermediate process. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "rx_jsonpara"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>configuremac [i]</b> configures the MAC of the detector with these parameters: detectorip, detectormac, rx_udpip, rx_udpmac, rx_udpport, rx_udpport2 (if applicable). This command is already included in \c rx_hsotname. Only put!. \c Returns \c (int)
*/
@ -2844,6 +2851,11 @@ std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int
myDet->setAdditionalJsonHeader(args[1], detPos);
}
return myDet->getAdditionalJsonHeader(detPos);
} else if (cmd == "rx_jsonpara") {
if (action == PUT_ACTION) {
myDet->setAdditionalJsonParameter(args[1], args[2], detPos);
}
return myDet->getAdditionalJsonParameter(args[1]);
}
return ("unknown network parameter") + cmd;
@ -2884,6 +2896,7 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
"out with the zmq from receiver. Default is empty. t must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc."
"Use only if it needs to be processed by an intermediate process."
<< std::endl;
os << "rx_jsonpara [k v]\n sets value to v for additional json header parameter k to be streamed out with the zmq from receiver. Use only if it needs to be processed by an intermediate process." << std::endl;
os << "rx_udpsocksize [t]\n sets the UDP socket buffer size. Different defaults for Jungfrau. "
"Does not remember in client shared memory, "
"so must be initialized each time after setting receiver "
@ -2908,6 +2921,7 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
os << "rx_jsonaddheader \n gets additional json header to be streamed "
"out with the zmq from receiver."
<< std::endl;
os << "rx_jsonpara [k] \n gets value of additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found. Use only if it needs to be processed by an intermediate process." << std::endl;
os << "rx_udpsocksize \n gets the UDP socket buffer size." << std::endl;
os << "rx_realudpsocksize \n gets the actual UDP socket buffer size. Usually double the set udp socket buffer size due to kernel bookkeeping." << std::endl;
}