diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 99de817d6..419fe5b5d 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -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 rxDbitList; /** reciever dbit offset */ int rxDbitOffset; diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 1e4f62fb0..d505b3eba 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -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 list(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize); - setReceiverDbitList(list); + setReceiverDbitList(shm()->rxDbitList); } setReceiverSilentMode(static_cast(shm()->rxSilentMode)); @@ -2729,51 +2726,20 @@ void slsDetector::setReceiverDbitList(std::vector 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 slsDetector::getReceiverDbitList() { - int fnum = F_GET_RECEIVER_DBIT_LIST; - int ret = FAIL; - std::vector retval; - int retsize = 0; + sls::FixedCapacityContainer 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)); - } - 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); + sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval); + shm()->rxDbitList = retval; } - - 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(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 temp; + n += receiver.receiveData(&temp, sizeof(temp)); + shm()->rxDbitList = temp; } // dbit offset diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index fc8c0a444..36c2ea220 100755 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -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)); + ret = OK; + memset(mess, 0, sizeof(mess)); + sls::FixedCapacityContainer 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 : args) { + FILE_LOG(logDEBUG1) << it << " "; + } + FILE_LOG(logDEBUG1) << "\n"; + if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + 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(args); + } - // 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 arg(narglist, narglist + narg); - - FILE_LOG(logDEBUG1) << "Setting DBIT list"; - for (auto &it : arg) { - 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) { - ret = FAIL; - sprintf(mess, "Could not set dbit list as size is > 64\n"); - FILE_LOG(logERROR) << mess; - } else - receiver->setDbitList(arg); - } - } - - return interface->Server_SendResult(true, ret, nullptr, 0, mess); + + } + return interface->Server_SendResult(true, ret, nullptr, 0, mess); } - - int slsReceiverTCPIPInterface::get_dbit_list() { ret = OK; memset(mess, 0, sizeof(mess)); - std::vector list; + sls::FixedCapacityContainer 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); } diff --git a/slsSupportLib/include/FixedCapacityContainer.h b/slsSupportLib/include/FixedCapacityContainer.h index 4b39d52db..d53136baa 100644 --- a/slsSupportLib/include/FixedCapacityContainer.h +++ b/slsSupportLib/include/FixedCapacityContainer.h @@ -20,6 +20,8 @@ template class FixedCapacityContainer { bool operator==(const std::vector &other) const noexcept; bool operator!=(const std::vector &other) const noexcept; + operator std::vector(){return std::vector(begin(), end());} + template bool operator==(const FixedCapacityContainer &other) const noexcept; diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index c903d24a9..bf14a3545 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -24,6 +24,7 @@ #include "ansi.h" #define BIT32_MASK 0xFFFFFFFF +#define MAX_RX_DBIT 64 /** default ports */ #define DEFAULT_PORTNO 1952 diff --git a/slsSupportLib/tests/test-FixedCapacityContainer.cpp b/slsSupportLib/tests/test-FixedCapacityContainer.cpp index 9277df258..d4853cab7 100644 --- a/slsSupportLib/tests/test-FixedCapacityContainer.cpp +++ b/slsSupportLib/tests/test-FixedCapacityContainer.cpp @@ -215,3 +215,16 @@ SCENARIO("Assigning containers to each other", "[support]") { } } +SCENARIO("Converting to vector", "[support]"){ + GIVEN("a FixedCapacityContainer"){ + FixedCapacityContainer a{1,2,3}; + WHEN("Converted into a vector"){ + std::vector b(a); + THEN("Data and size matches"){ + REQUIRE(a == b); + REQUIRE(a.size() == b.size()); + } + } + } +} +