mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 22:40:02 +02:00
Merge branch 'developer' into mysocket
This commit is contained in:
commit
f64facee0c
@ -16,8 +16,8 @@
|
||||
class multiSlsDetector;
|
||||
class ServerInterface;
|
||||
|
||||
#define SLS_SHMVERSION 0x190503
|
||||
#define MAX_RX_DBIT 64
|
||||
#define SLS_SHMVERSION 0x190515
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -241,11 +241,7 @@ struct sharedSlsDetector {
|
||||
/** overwrite enable */
|
||||
bool rxFileOverWrite;
|
||||
|
||||
/** receiver dbit size */
|
||||
int rxDbitListSize;
|
||||
|
||||
/** receiver dbit list */
|
||||
int rxDbitList[MAX_RX_DBIT];
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> rxDbitList;
|
||||
|
||||
/** reciever dbit offset */
|
||||
int rxDbitOffset;
|
||||
|
@ -387,8 +387,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
|
||||
shm()->rxFileWrite = true;
|
||||
shm()->rxMasterFileWrite = true;
|
||||
shm()->rxFileOverWrite = true;
|
||||
shm()->rxDbitListSize = 0;
|
||||
memset(shm()->rxDbitList, 0, MAX_RX_DBIT * sizeof(int));
|
||||
shm()->rxDbitOffset = 0;
|
||||
|
||||
// get the detector parameters based on type
|
||||
@ -1905,7 +1903,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
||||
<< "\nrx streaming source ip:" << shm()->rxZmqip
|
||||
<< "\nrx additional json header:" << shm()->rxAdditionalJsonHeader
|
||||
<< "\nrx_datastream:" << enableDataStreamingFromReceiver(-1)
|
||||
<< "\nrx_dbitlistsize:" << shm()->rxDbitListSize
|
||||
<< "\nrx_dbitlistsize:" << shm()->rxDbitList.size()
|
||||
<< "\nrx_DbitOffset:" << shm()->rxDbitOffset
|
||||
<< std::endl;
|
||||
|
||||
@ -1972,8 +1970,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
||||
}
|
||||
|
||||
if (shm()->myDetectorType == CHIPTESTBOARD) {
|
||||
std::vector<int> list(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize);
|
||||
setReceiverDbitList(list);
|
||||
setReceiverDbitList(shm()->rxDbitList);
|
||||
}
|
||||
|
||||
setReceiverSilentMode(static_cast<int>(shm()->rxSilentMode));
|
||||
@ -2729,51 +2726,20 @@ void slsDetector::setReceiverDbitList(std::vector<int> list) {
|
||||
throw sls::RuntimeError("Dbit list value must be between 0 and 63\n");
|
||||
}
|
||||
}
|
||||
|
||||
// copy size and vector to shm
|
||||
shm()->rxDbitListSize = list.size();
|
||||
std::copy(list.begin(), list.end(), shm()->rxDbitList);
|
||||
|
||||
shm()->rxDbitList = list;
|
||||
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
|
||||
int args[list.size() + 1];
|
||||
args[0] = list.size();
|
||||
std::copy(std::begin(list), std::end(list), args + 1);
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_LIST, args, sizeof(args), nullptr, 0);
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_LIST, shm()->rxDbitList, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> slsDetector::getReceiverDbitList() {
|
||||
int fnum = F_GET_RECEIVER_DBIT_LIST;
|
||||
int ret = FAIL;
|
||||
std::vector <int> retval;
|
||||
int retsize = 0;
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
|
||||
FILE_LOG(logDEBUG1) << "Getting Receiver Dbit List";
|
||||
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
|
||||
auto receiver =
|
||||
sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort);
|
||||
receiver.sendData(&fnum, sizeof(fnum));
|
||||
receiver.receiveData(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
receiver.receiveData(mess, MAX_STR_LENGTH);
|
||||
throw ReceiverError("Receiver " + std::to_string(detId) +
|
||||
" returned error: " + std::string(mess));
|
||||
sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
|
||||
shm()->rxDbitList = retval;
|
||||
}
|
||||
receiver.receiveData(&retsize, sizeof(retsize));
|
||||
int list[retsize];
|
||||
receiver.receiveData(list, sizeof(list));
|
||||
|
||||
// copy after no errors
|
||||
shm()->rxDbitListSize = retsize;
|
||||
std::copy(list, list + retsize, shm()->rxDbitList);
|
||||
}
|
||||
|
||||
if (shm()->rxDbitListSize) {
|
||||
retval.resize(shm()->rxDbitListSize);
|
||||
std::copy(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize, std::begin(retval));
|
||||
}
|
||||
|
||||
return retval;
|
||||
return shm()->rxDbitList;
|
||||
}
|
||||
|
||||
int slsDetector::setReceiverDbitOffset(int value) {
|
||||
@ -3420,15 +3386,11 @@ int slsDetector::updateCachedReceiverVariables() const {
|
||||
n += receiver.receiveData(&i32, sizeof(i32));
|
||||
shm()->rxSilentMode = static_cast<bool>(i32);
|
||||
|
||||
// dbit list size
|
||||
// dbit list
|
||||
{
|
||||
int listsize = 0;
|
||||
n += receiver.receiveData(&listsize, sizeof(listsize));
|
||||
int list[listsize];
|
||||
n += receiver.receiveData(list, sizeof(list));
|
||||
// copy after no errors
|
||||
shm()->rxDbitListSize = listsize;
|
||||
std::copy(list, list + listsize, shm()->rxDbitList);
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> temp;
|
||||
n += receiver.receiveData(&temp, sizeof(temp));
|
||||
shm()->rxDbitList = temp;
|
||||
}
|
||||
|
||||
// dbit offset
|
||||
|
@ -3,12 +3,14 @@
|
||||
* @short interface between receiver and client
|
||||
***********************************************/
|
||||
|
||||
#include "slsReceiverTCPIPInterface.h"
|
||||
|
||||
#include "FixedCapacityContainer.h"
|
||||
#include "MySocketTCP.h"
|
||||
#include "ServerSocket.h"
|
||||
#include "ServerInterface.h"
|
||||
#include "slsReceiver.h"
|
||||
#include "slsReceiverImplementation.h"
|
||||
#include "slsReceiverTCPIPInterface.h"
|
||||
#include "slsReceiverUsers.h"
|
||||
#include "versionAPI.h"
|
||||
|
||||
@ -2131,52 +2133,36 @@ int slsReceiverTCPIPInterface::set_adc_mask() {
|
||||
return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_dbit_list() {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
// receive arguments
|
||||
int narg = -1;
|
||||
if (mySock->ReceiveDataOnly(&narg,sizeof(narg)) < 0 )
|
||||
return interface->Server_SocketCrash();
|
||||
int narglist[narg];
|
||||
if (mySock->ReceiveDataOnly(narglist, narg * sizeof(int)) < 0 )
|
||||
return interface->Server_SocketCrash();
|
||||
std::vector <int> arg(narglist, narglist + narg);
|
||||
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> args;
|
||||
if (interface->Server_ReceiveArg(ret, mess, &args, sizeof(args), true, receiver) == FAIL) {
|
||||
return FAIL;
|
||||
} else if (ret == OK) {
|
||||
FILE_LOG(logDEBUG1) << "Setting DBIT list";
|
||||
for (auto &it : arg) {
|
||||
for (auto &it : args) {
|
||||
FILE_LOG(logDEBUG1) << it << " ";
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "\n";
|
||||
|
||||
// base object not null
|
||||
if (receiver == nullptr)
|
||||
interface->Server_NullObjectError(ret, mess);
|
||||
else {
|
||||
// only set
|
||||
// verify if receiver is unlocked and idle
|
||||
if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) {
|
||||
if (arg.size() > 64) {
|
||||
if (args.size() > 64) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set dbit list as size is > 64\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
} else
|
||||
receiver->setDbitList(arg);
|
||||
}
|
||||
receiver->setDbitList(args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return interface->Server_SendResult(true, ret, nullptr, 0, mess);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::get_dbit_list() {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
std::vector<int> list;
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
|
||||
|
||||
// no arg, check receiver is null
|
||||
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
|
||||
@ -2184,17 +2170,10 @@ int slsReceiverTCPIPInterface::get_dbit_list() {
|
||||
// base object not null
|
||||
if (ret == OK) {
|
||||
// get
|
||||
list = receiver->getDbitList();
|
||||
FILE_LOG(logDEBUG1) << "Dbit list size retval:" << list.size();
|
||||
retval = receiver->getDbitList();
|
||||
FILE_LOG(logDEBUG1) << "Dbit list size retval:" << retval.size();
|
||||
}
|
||||
|
||||
interface->Server_SendResult(false, ret, nullptr, 0, mess);
|
||||
int retvalsize = list.size();
|
||||
int retval[retvalsize];
|
||||
std::copy(std::begin(list), std::end(list), retval);
|
||||
mySock->SendDataOnly(&retvalsize, sizeof(retvalsize));
|
||||
mySock->SendDataOnly(retval, sizeof(retval));
|
||||
return ret;
|
||||
return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
||||
bool operator==(const std::vector<T> &other) const noexcept;
|
||||
bool operator!=(const std::vector<T> &other) const noexcept;
|
||||
|
||||
operator std::vector<T>(){return std::vector<T>(begin(), end());}
|
||||
|
||||
template <size_t OtherCapacity>
|
||||
bool operator==(const FixedCapacityContainer<T, OtherCapacity> &other) const
|
||||
noexcept;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "ansi.h"
|
||||
|
||||
#define BIT32_MASK 0xFFFFFFFF
|
||||
#define MAX_RX_DBIT 64
|
||||
|
||||
/** default ports */
|
||||
#define DEFAULT_PORTNO 1952
|
||||
|
@ -215,3 +215,16 @@ SCENARIO("Assigning containers to each other", "[support]") {
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Converting to vector", "[support]"){
|
||||
GIVEN("a FixedCapacityContainer"){
|
||||
FixedCapacityContainer<int, 5> a{1,2,3};
|
||||
WHEN("Converted into a vector"){
|
||||
std::vector<int> b(a);
|
||||
THEN("Data and size matches"){
|
||||
REQUIRE(a == b);
|
||||
REQUIRE(a.size() == b.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user