Stoppedflag (#44)

* removed stopped flag from multi and sls shm, since its removed from fixed pattern in sls, slsshmversion api also added to get hostname and type

* clang format
This commit is contained in:
Dhanya Thattil 2019-07-29 11:35:21 +02:00 committed by Erik Fröjdh
parent b524e0c95f
commit 64a8dd2def
4 changed files with 553 additions and 574 deletions

View File

@ -50,10 +50,6 @@ struct sharedMultiSlsDetector {
/** Number of detectors operated at once */
int numberOfDetector[2];
/** stopped flag - is set if an acquisition error occurs or the detector
* is stopped manually. Is reset to 0 at the start of the acquisition */
int stoppedFlag;
/** size of the data that are transfered from all detectors */
int dataBytes;

View File

@ -12,6 +12,7 @@
class ServerInterface;
#define SLS_SHMAPIVERSION 0x190726
#define SLS_SHMVERSION 0x190726
/**
@ -24,13 +25,6 @@ struct sharedSlsDetector {
/** shared memory version */
int shmversion;
/** is the port used for control functions */
int controlPort;
/** stopped flag - is set if an acquisition error occurs or the detector
* is stopped manually. Is reset to 0 at the start of the acquisition */
int stoppedFlag;
/** is the hostname (or IP address) of the detector. needs to be set
* before starting the communication */
char hostname[MAX_STR_LENGTH];
@ -47,6 +41,9 @@ struct sharedSlsDetector {
/** Number of detectors in multi list in x dir and y dir */
int multiSize[2];
/** is the port used for control functions */
int controlPort;
/** is the port used to stop the acquisition */
int stopPort;
@ -259,6 +256,11 @@ class slsDetector : public virtual slsDetectorDefs{
*/
virtual ~slsDetector();
/**
* Returns false if it cannot get fixed pattern from an old version of shm (hostname, type), else true
*/
bool isFixedPatternSharedMemoryCompatible();
/**
* Check version compatibility with receiver software
*/

View File

@ -274,10 +274,13 @@ std::string multiSlsDetector::getUserDetails() {
}
std::ostringstream sstream;
sstream << "\nHostname: " << getHostname();
sstream << "\nHostname: ";
for (auto &d : detectors) {
sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getHostname() : "Unknown") << "+";
}
sstream << "\nType: ";
for (auto &d : detectors) {
sstream << d->getDetectorTypeAsString() << "+";
sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getDetectorTypeAsString() : "Unknown") << "+";
}
sstream << "\nPID: " << multi_shm()->lastPID
@ -310,7 +313,6 @@ void multiSlsDetector::initializeDetectorStructure() {
multi_shm()->numberOfDetectors = 0;
multi_shm()->numberOfDetector[X] = 0;
multi_shm()->numberOfDetector[Y] = 0;
multi_shm()->stoppedFlag = 0;
multi_shm()->dataBytes = 0;
multi_shm()->dataBytesInclGapPixels = 0;
multi_shm()->numberOfChannels = 0;
@ -992,14 +994,8 @@ void multiSlsDetector::stopAcquisition(int detPos) {
// thread)
std::lock_guard<std::mutex> lock(mg);
if (detPos >= 0) {
// if only 1 detector, set flag to stop current acquisition
if (detectors.size() == 1) {
multi_shm()->stoppedFlag = 1;
}
detectors[detPos]->stopAcquisition();
} else {
multi_shm()->stoppedFlag = 1;
parallelCall(&slsDetector::stopAcquisition);
}
}
@ -4188,7 +4184,6 @@ int multiSlsDetector::acquire() {
bool receiver = getUseReceiverFlag();
progressIndex = 0;
multi_shm()->stoppedFlag = 0;
setJoinThreadFlag(false);
// verify receiver is idle
@ -4202,21 +4197,19 @@ int multiSlsDetector::acquire() {
startProcessingThread();
// resets frames caught in receiver
if (receiver && multi_shm()->stoppedFlag == 0) {
if (receiver) {
std::lock_guard<std::mutex> lock(mg);
resetFramesCaught();
}
// start receiver
if (receiver && multi_shm()->stoppedFlag == 0) {
if (receiver) {
std::lock_guard<std::mutex> lock(mg);
startReceiver();
// let processing thread listen to these packets
if (multi_shm()->stoppedFlag == 0)
sem_post(&sem_newRTAcquisition);
}
if (multi_shm()->stoppedFlag == 0)
startAndReadAll();
// stop receiver

View File

@ -54,6 +54,10 @@ slsDetector::slsDetector(int multi_id, int det_id, bool verify)
slsDetector::~slsDetector() = default;
bool slsDetector::isFixedPatternSharedMemoryCompatible() {
return (shm()->shmversion >= SLS_SHMAPIVERSION);
}
void slsDetector::checkDetectorVersionCompatibility() {
int fnum = F_CHECK_VERSION;
int64_t arg = 0;
@ -107,8 +111,8 @@ int64_t slsDetector::getId(idMode mode) {
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting id type " << mode;
sendToDetector(F_GET_ID, arg, retval);
FILE_LOG(logDEBUG1)
<< "Id (" << mode << "): 0x" << std::hex << retval << std::dec;
FILE_LOG(logDEBUG1) << "Id (" << mode << "): 0x" << std::hex << retval
<< std::dec;
return retval;
}
@ -161,12 +165,12 @@ void slsDetector::sendToDetectorStop(int fnum, const void *args,
template <typename Arg, typename Ret>
void slsDetector::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) {
sendToDetectorStop(fnum, &args, sizeof(args), &retval,
sizeof(retval));
sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval));
}
template <typename Arg>
void slsDetector::sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) {
void slsDetector::sendToDetectorStop(int fnum, const Arg &args,
std::nullptr_t) {
sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0);
}
@ -252,7 +256,6 @@ void slsDetector::initSharedMemory(detectorType type, int multi_id,
void slsDetector::initializeDetectorStructure(detectorType type) {
shm()->shmversion = SLS_SHMVERSION;
shm()->controlPort = DEFAULT_PORTNO;
shm()->stoppedFlag = 0;
sls::strcpy_safe(shm()->hostname, DEFAULT_HOSTNAME);
shm()->myDetectorType = type;
shm()->offset[X] = 0;
@ -704,8 +707,7 @@ void slsDetector::execCommand(const std::string &cmd) {
FILE_LOG(logDEBUG1) << "Sending command to detector " << arg;
sendToDetector(F_EXEC_COMMAND, arg, retval);
if (strlen(retval) != 0u) {
FILE_LOG(logINFO) << "Detector " << detId << " returned:\n"
<< retval;
FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval;
}
}
@ -713,13 +715,14 @@ void slsDetector::updateCachedDetectorVariables() {
int fnum = F_UPDATE_CLIENT;
FILE_LOG(logDEBUG1) << "Sending update client to detector server";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
if (client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0) == FORCE_UPDATE) {
if (client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0) ==
FORCE_UPDATE) {
int n = 0, i32 = 0;
int64_t i64 = 0;
char lastClientIP[INET_ADDRSTRLEN] = {0};
n += client.Receive(lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1) << "Updating detector last modified by "
<< lastClientIP;
FILE_LOG(logDEBUG1)
<< "Updating detector last modified by " << lastClientIP;
// dr
n += client.Receive(&i32, sizeof(i32));
@ -838,7 +841,6 @@ void slsDetector::updateCachedDetectorVariables() {
}
}
std::vector<std::string> slsDetector::getConfigFileCommands() {
std::vector<std::string> base{"hostname", "port", "stopport",
"settingsdir", "fpath", "lock",
@ -1161,7 +1163,6 @@ void slsDetector::prepareAcquisition() {
void slsDetector::startAcquisition() {
FILE_LOG(logDEBUG1) << "Starting Acquisition";
shm()->stoppedFlag = 0;
sendToDetector(F_START_ACQUISITION);
FILE_LOG(logDEBUG1) << "Starting Acquisition successful";
}
@ -1176,7 +1177,6 @@ void slsDetector::stopAcquisition() {
FILE_LOG(logDEBUG1) << "Stopping Acquisition";
sendToDetectorStop(F_STOP_ACQUISITION);
FILE_LOG(logDEBUG1) << "Stopping Acquisition successful";
shm()->stoppedFlag = 1;
// if rxr streaming and acquisition finished, restream dummy stop packet
if ((shm()->rxUpstream) && (s == IDLE) && (r == IDLE)) {
restreamStopFromReceiver();
@ -1185,14 +1185,12 @@ void slsDetector::stopAcquisition() {
void slsDetector::sendSoftwareTrigger() {
FILE_LOG(logDEBUG1) << "Sending software trigger";
shm()->stoppedFlag = 0;
sendToDetector(F_SOFTWARE_TRIGGER);
FILE_LOG(logDEBUG1) << "Sending software trigger successful";
}
void slsDetector::startAndReadAll() {
FILE_LOG(logDEBUG1) << "Starting and reading all frames";
shm()->stoppedFlag = 0;
sendToDetector(F_START_AND_READ_ALL);
FILE_LOG(logDEBUG1) << "Detector successfully finished acquisition";
}
@ -1206,8 +1204,7 @@ void slsDetector::startReadOut() {
void slsDetector::readAll() {
FILE_LOG(logDEBUG1) << "Reading all frames";
sendToDetector(F_READ_ALL);
FILE_LOG(logDEBUG1)
<< "Detector successfully finished reading all frames";
FILE_LOG(logDEBUG1) << "Detector successfully finished reading all frames";
}
void slsDetector::configureMAC() {
@ -1304,14 +1301,14 @@ void slsDetector::configureMAC() {
if (shm()->detectorMAC != detector_mac) {
shm()->detectorMAC = detector_mac;
FILE_LOG(logINFO)
<< detId << ": Detector MAC updated to " << getDetectorMAC();
FILE_LOG(logINFO) << detId << ": Detector MAC updated to "
<< getDetectorMAC();
}
if (shm()->detectorIP != detector_ip) {
shm()->detectorIP = detector_ip;
FILE_LOG(logINFO)
<< detId << ": Detector IP updated to " << getDetectorIP();
FILE_LOG(logINFO) << detId << ": Detector IP updated to "
<< getDetectorIP();
}
if (ret == FORCE_UPDATE) {
updateCachedDetectorVariables();
@ -1535,8 +1532,8 @@ uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) {
FILE_LOG(logDEBUG1) << "Writing to reg 0x" << std::hex << addr << "data: 0x"
<< std::hex << val << std::dec;
sendToDetector(F_WRITE_REGISTER, args, retval);
FILE_LOG(logDEBUG1) << "Reg 0x" << std::hex << addr << ": 0x"
<< std::hex << retval << std::dec;
FILE_LOG(logDEBUG1) << "Reg 0x" << std::hex << addr << ": 0x" << std::hex
<< retval << std::dec;
return retval;
}
@ -1544,8 +1541,8 @@ uint32_t slsDetector::readRegister(uint32_t addr) {
uint32_t retval = -1;
FILE_LOG(logDEBUG1) << "Reading reg 0x" << std::hex << addr << std::dec;
sendToDetector(F_READ_REGISTER, addr, retval);
FILE_LOG(logDEBUG1) << "Reg 0x" << std::hex << addr << ": 0x"
<< std::hex << retval << std::dec;
FILE_LOG(logDEBUG1) << "Reg 0x" << std::hex << addr << ": 0x" << std::hex
<< retval << std::dec;
return retval;
}
@ -1659,8 +1656,6 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
shm()->useReceiverFlag = true;
checkReceiverVersionCompatibility();
FILE_LOG(logDEBUG)
<< "detector type:"
<< (slsDetectorDefs::detectorTypeToString(shm()->myDetectorType))
@ -1681,16 +1676,14 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
shm()->timerValue[CYCLES_NUMBER]) > 1)
<< "\nframe period:" << (shm()->timerValue[FRAME_PERIOD])
<< "\nframe number:" << (shm()->timerValue[FRAME_NUMBER])
<< "\nsub exp time:"
<< (shm()->timerValue[SUBFRAME_ACQUISITION_TIME])
<< "\nsub exp time:" << (shm()->timerValue[SUBFRAME_ACQUISITION_TIME])
<< "\nsub dead time:" << (shm()->timerValue[SUBFRAME_DEADTIME])
<< "\nasamples:" << (shm()->timerValue[ANALOG_SAMPLES])
<< "\ndsamples:" << (shm()->timerValue[DIGITAL_SAMPLES])
<< "\ndynamic range:" << shm()->dynamicRange
<< "\nflippeddatax:" << (shm()->flippedData[X])
<< "\nactivated: " << shm()->activated
<< "\nreceiver deactivated padding: "
<< shm()->rxPadDeactivatedModules
<< "\nreceiver deactivated padding: " << shm()->rxPadDeactivatedModules
<< "\nsilent Mode:" << shm()->rxSilentMode
<< "\n10GbE:" << shm()->tenGigaEnable
<< "\nGap pixels: " << shm()->gappixels
@ -1728,8 +1721,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
case EIGER:
setTimer(SUBFRAME_ACQUISITION_TIME,
shm()->timerValue[SUBFRAME_ACQUISITION_TIME]);
setTimer(SUBFRAME_DEADTIME,
shm()->timerValue[SUBFRAME_DEADTIME]);
setTimer(SUBFRAME_DEADTIME, shm()->timerValue[SUBFRAME_DEADTIME]);
setDynamicRange(shm()->dynamicRange);
setFlippedData(X, -1);
activate(-1);
@ -1974,8 +1966,7 @@ int slsDetector::setDetectorNetworkParameter(networkParameter index,
FILE_LOG(logDEBUG1) << "Setting network parameter index " << index << " to "
<< delay;
sendToDetector(F_SET_NETWORK_PARAMETER, args, retval);
FILE_LOG(logDEBUG1)
<< "Network Parameter (" << index << "): " << retval;
FILE_LOG(logDEBUG1) << "Network Parameter (" << index << "): " << retval;
return retval;
}
@ -2127,7 +2118,8 @@ void slsDetector::setUDPConnection() {
// called before set up
if (strcmp(shm()->rxHostname, "none") == 0) {
throw RuntimeError("Cannot set udp connection. Receiver hostname not set yet.");
throw RuntimeError(
"Cannot set udp connection. Receiver hostname not set yet.");
}
if (shm()->rxUDPIP == 0) {
@ -2220,7 +2212,8 @@ void slsDetector::sendImageToDetector(imageType index, int16_t imageVals[]) {
}
}
void slsDetector::writeCounterBlockFile(const std::string &fname, int startACQ) {
void slsDetector::writeCounterBlockFile(const std::string &fname,
int startACQ) {
int nChan = getTotalNumberOfChannels();
int16_t retvals[nChan];
FILE_LOG(logDEBUG1) << "Reading Counter to " << fname
@ -2235,8 +2228,7 @@ void slsDetector::getCounterBlock(int16_t image[], int startACQ) {
int nChan = getTotalNumberOfChannels();
int args[] = {startACQ, nChan};
FILE_LOG(logDEBUG1) << "Reading Counter block with startacq: " << startACQ;
sendToDetector(fnum, args, sizeof(args), image,
nChan * sizeof(int16_t));
sendToDetector(fnum, args, sizeof(args), image, nChan * sizeof(int16_t));
}
void slsDetector::resetCounterBlock(int startACQ) {
@ -2311,9 +2303,8 @@ void slsDetector::sendROI(int n, ROI roiLimits[]) {
shm()->roiLimits[i] = retval[i];
FILE_LOG(logDEBUG1)
<< "ROI [" << i << "] (" << shm()->roiLimits[i].xmin << ","
<< shm()->roiLimits[i].xmax << ","
<< shm()->roiLimits[i].ymin << ","
<< shm()->roiLimits[i].ymax << ")";
<< shm()->roiLimits[i].xmax << "," << shm()->roiLimits[i].ymin
<< "," << shm()->roiLimits[i].ymax << ")";
}
}
if (ret == FORCE_UPDATE) {
@ -2386,11 +2377,10 @@ void slsDetector::setADCEnableMask(uint32_t mask) {
uint32_t slsDetector::getADCEnableMask() {
uint32_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting ADC Enable mask";
sendToDetector(F_GET_ADC_ENABLE_MASK, nullptr, 0, &retval,
sizeof(retval));
sendToDetector(F_GET_ADC_ENABLE_MASK, nullptr, 0, &retval, sizeof(retval));
shm()->adcEnableMask = retval;
FILE_LOG(logDEBUG1)
<< "ADC Enable Mask: 0x" << std::hex << retval << std::dec;
FILE_LOG(logDEBUG1) << "ADC Enable Mask: 0x" << std::hex << retval
<< std::dec;
return shm()->adcEnableMask;
}
@ -2404,8 +2394,7 @@ uint32_t slsDetector::getADCInvert() {
uint32_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting ADC Invert";
sendToDetector(F_GET_ADC_INVERT, nullptr, retval);
FILE_LOG(logDEBUG1)
<< "ADC Invert: 0x" << std::hex << retval << std::dec;
FILE_LOG(logDEBUG1) << "ADC Invert: 0x" << std::hex << retval << std::dec;
return retval;
}
@ -2685,15 +2674,15 @@ void slsDetector::programFPGA(std::vector<char> buffer) {
while (count > 0) {
usleep(1 * 1000 * 1000);
--count;
printf("%d%%\r", static_cast<int>(
(static_cast<double>(ERASE_TIME - count) /
ERASE_TIME) *
printf("%d%%\r",
static_cast<int>(
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) *
100));
std::cout << std::flush;
}
printf("\n");
FILE_LOG(logINFO) << "Writing to Flash to detector " << detId
<< " (" << shm()->hostname << ")";
FILE_LOG(logINFO) << "Writing to Flash to detector " << detId << " ("
<< shm()->hostname << ")";
printf("%d%%\r", 0);
std::cout << std::flush;
}
@ -2724,9 +2713,9 @@ void slsDetector::programFPGA(std::vector<char> buffer) {
currentPointer += unitprogramsize;
// print progress
printf("%d%%\r", static_cast<int>((static_cast<double>(
totalsize - filesize) /
totalsize) *
printf("%d%%\r",
static_cast<int>(
(static_cast<double>(totalsize - filesize) / totalsize) *
100));
std::cout << std::flush;
}
@ -2871,7 +2860,6 @@ void slsDetector::printReceiverConfiguration(TLogLevel level) {
<< "\nReceiver UDP Port2:\t" << getReceiverUDPPort2();
}
bool slsDetector::getUseReceiverFlag() const { return shm()->useReceiverFlag; }
std::string slsDetector::checkReceiverOnline() {
@ -3025,8 +3013,8 @@ void slsDetector::updateCachedReceiverVariables() const {
shm()->rxDbitOffset = i32;
if (n == 0) {
throw RuntimeError("Could not update receiver: " +
std::string(shm()->rxHostname) +
throw RuntimeError(
"Could not update receiver: " + std::string(shm()->rxHostname) +
", received 0 bytes\n");
}
}
@ -3413,8 +3401,8 @@ std::array<int, 3> slsDetector::setPatternLoops(int level, int start, int stop,
<< ", start: " << start << ", stop: " << stop
<< ", nloops: " << n;
sendToDetector(F_SET_PATTERN_LOOP, args, retvals);
FILE_LOG(logDEBUG1) << "Set Pat Loops: " << retvals[0] << ", "
<< retvals[1] << ", " << retvals[2];
FILE_LOG(logDEBUG1) << "Set Pat Loops: " << retvals[0] << ", " << retvals[1]
<< ", " << retvals[2];
return retvals;
}