Merge branch 'developer' into mysocket

This commit is contained in:
Erik Frojdh 2019-05-15 10:02:43 +02:00
commit f64facee0c
6 changed files with 60 additions and 107 deletions

View File

@ -16,8 +16,8 @@
class multiSlsDetector; class multiSlsDetector;
class ServerInterface; class ServerInterface;
#define SLS_SHMVERSION 0x190503 #define SLS_SHMVERSION 0x190515
#define MAX_RX_DBIT 64
/** /**
@ -241,11 +241,7 @@ struct sharedSlsDetector {
/** overwrite enable */ /** overwrite enable */
bool rxFileOverWrite; bool rxFileOverWrite;
/** receiver dbit size */ sls::FixedCapacityContainer<int, MAX_RX_DBIT> rxDbitList;
int rxDbitListSize;
/** receiver dbit list */
int rxDbitList[MAX_RX_DBIT];
/** reciever dbit offset */ /** reciever dbit offset */
int rxDbitOffset; int rxDbitOffset;

View File

@ -387,8 +387,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
shm()->rxFileWrite = true; shm()->rxFileWrite = true;
shm()->rxMasterFileWrite = true; shm()->rxMasterFileWrite = true;
shm()->rxFileOverWrite = true; shm()->rxFileOverWrite = true;
shm()->rxDbitListSize = 0;
memset(shm()->rxDbitList, 0, MAX_RX_DBIT * sizeof(int));
shm()->rxDbitOffset = 0; shm()->rxDbitOffset = 0;
// get the detector parameters based on type // 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 streaming source ip:" << shm()->rxZmqip
<< "\nrx additional json header:" << shm()->rxAdditionalJsonHeader << "\nrx additional json header:" << shm()->rxAdditionalJsonHeader
<< "\nrx_datastream:" << enableDataStreamingFromReceiver(-1) << "\nrx_datastream:" << enableDataStreamingFromReceiver(-1)
<< "\nrx_dbitlistsize:" << shm()->rxDbitListSize << "\nrx_dbitlistsize:" << shm()->rxDbitList.size()
<< "\nrx_DbitOffset:" << shm()->rxDbitOffset << "\nrx_DbitOffset:" << shm()->rxDbitOffset
<< std::endl; << std::endl;
@ -1972,8 +1970,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
} }
if (shm()->myDetectorType == CHIPTESTBOARD) { if (shm()->myDetectorType == CHIPTESTBOARD) {
std::vector<int> list(shm()->rxDbitList, shm()->rxDbitList + shm()->rxDbitListSize); setReceiverDbitList(shm()->rxDbitList);
setReceiverDbitList(list);
} }
setReceiverSilentMode(static_cast<int>(shm()->rxSilentMode)); 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"); throw sls::RuntimeError("Dbit list value must be between 0 and 63\n");
} }
} }
shm()->rxDbitList = list;
// copy size and vector to shm
shm()->rxDbitListSize = list.size();
std::copy(list.begin(), list.end(), shm()->rxDbitList);
if (shm()->rxOnlineFlag == ONLINE_FLAG) { if (shm()->rxOnlineFlag == ONLINE_FLAG) {
int args[list.size() + 1]; sendToReceiver(F_SET_RECEIVER_DBIT_LIST, shm()->rxDbitList, nullptr);
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);
} }
} }
std::vector<int> slsDetector::getReceiverDbitList() { std::vector<int> slsDetector::getReceiverDbitList() {
int fnum = F_GET_RECEIVER_DBIT_LIST; sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
int ret = FAIL;
std::vector <int> retval;
int retsize = 0;
FILE_LOG(logDEBUG1) << "Getting Receiver Dbit List"; FILE_LOG(logDEBUG1) << "Getting Receiver Dbit List";
if (shm()->rxOnlineFlag == ONLINE_FLAG) { if (shm()->rxOnlineFlag == ONLINE_FLAG) {
auto receiver = sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
sls::ClientSocket("Receiver", shm()->rxHostname, shm()->rxTCPPort); shm()->rxDbitList = retval;
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)); return shm()->rxDbitList;
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;
} }
int slsDetector::setReceiverDbitOffset(int value) { int slsDetector::setReceiverDbitOffset(int value) {
@ -3420,15 +3386,11 @@ int slsDetector::updateCachedReceiverVariables() const {
n += receiver.receiveData(&i32, sizeof(i32)); n += receiver.receiveData(&i32, sizeof(i32));
shm()->rxSilentMode = static_cast<bool>(i32); shm()->rxSilentMode = static_cast<bool>(i32);
// dbit list size // dbit list
{ {
int listsize = 0; sls::FixedCapacityContainer<int, MAX_RX_DBIT> temp;
n += receiver.receiveData(&listsize, sizeof(listsize)); n += receiver.receiveData(&temp, sizeof(temp));
int list[listsize]; shm()->rxDbitList = temp;
n += receiver.receiveData(list, sizeof(list));
// copy after no errors
shm()->rxDbitListSize = listsize;
std::copy(list, list + listsize, shm()->rxDbitList);
} }
// dbit offset // dbit offset

View File

@ -3,12 +3,14 @@
* @short interface between receiver and client * @short interface between receiver and client
***********************************************/ ***********************************************/
#include "slsReceiverTCPIPInterface.h"
#include "FixedCapacityContainer.h"
#include "MySocketTCP.h" #include "MySocketTCP.h"
#include "ServerSocket.h" #include "ServerSocket.h"
#include "ServerInterface.h" #include "ServerInterface.h"
#include "slsReceiver.h" #include "slsReceiver.h"
#include "slsReceiverImplementation.h" #include "slsReceiverImplementation.h"
#include "slsReceiverTCPIPInterface.h"
#include "slsReceiverUsers.h" #include "slsReceiverUsers.h"
#include "versionAPI.h" #include "versionAPI.h"
@ -2131,52 +2133,36 @@ int slsReceiverTCPIPInterface::set_adc_mask() {
return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess);
} }
int slsReceiverTCPIPInterface::set_dbit_list() { int slsReceiverTCPIPInterface::set_dbit_list() {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
sls::FixedCapacityContainer<int, MAX_RX_DBIT> args;
// receive arguments if (interface->Server_ReceiveArg(ret, mess, &args, sizeof(args), true, receiver) == FAIL) {
int narg = -1; return FAIL;
if (mySock->ReceiveDataOnly(&narg,sizeof(narg)) < 0 ) } else if (ret == OK) {
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);
FILE_LOG(logDEBUG1) << "Setting DBIT list"; FILE_LOG(logDEBUG1) << "Setting DBIT list";
for (auto &it : arg) { for (auto &it : args) {
FILE_LOG(logDEBUG1) << it << " "; FILE_LOG(logDEBUG1) << it << " ";
} }
FILE_LOG(logDEBUG1) << "\n"; 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 (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) {
if (arg.size() > 64) { if (args.size() > 64) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Could not set dbit list as size is > 64\n"); sprintf(mess, "Could not set dbit list as size is > 64\n");
FILE_LOG(logERROR) << mess; FILE_LOG(logERROR) << mess;
} else } else
receiver->setDbitList(arg); receiver->setDbitList(args);
}
} }
}
return interface->Server_SendResult(true, ret, nullptr, 0, mess); return interface->Server_SendResult(true, ret, nullptr, 0, mess);
} }
int slsReceiverTCPIPInterface::get_dbit_list() { int slsReceiverTCPIPInterface::get_dbit_list() {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
std::vector<int> list; sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
// no arg, check receiver is null // no arg, check receiver is null
interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver); interface->Server_ReceiveArg(ret, mess, nullptr, 0, true, receiver);
@ -2184,17 +2170,10 @@ int slsReceiverTCPIPInterface::get_dbit_list() {
// base object not null // base object not null
if (ret == OK) { if (ret == OK) {
// get // get
list = receiver->getDbitList(); retval = receiver->getDbitList();
FILE_LOG(logDEBUG1) << "Dbit list size retval:" << list.size(); FILE_LOG(logDEBUG1) << "Dbit list size retval:" << retval.size();
} }
return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess);
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;
} }

View File

@ -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;
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> template <size_t OtherCapacity>
bool operator==(const FixedCapacityContainer<T, OtherCapacity> &other) const bool operator==(const FixedCapacityContainer<T, OtherCapacity> &other) const
noexcept; noexcept;

View File

@ -24,6 +24,7 @@
#include "ansi.h" #include "ansi.h"
#define BIT32_MASK 0xFFFFFFFF #define BIT32_MASK 0xFFFFFFFF
#define MAX_RX_DBIT 64
/** default ports */ /** default ports */
#define DEFAULT_PORTNO 1952 #define DEFAULT_PORTNO 1952

View File

@ -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());
}
}
}
}