kept the same client interface:tb changed when fixing error codes/exceptions, modified multi print, fixed roi bug in indexing to sls

This commit is contained in:
maliakal_d 2018-10-31 14:30:30 +01:00
parent 3d40d5d058
commit aec8c031de
8 changed files with 238 additions and 357 deletions

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 92fc837eb490650d91c2283943cbd729b2e36567 Repsitory UUID: 3d40d5d0585931f7f4a42912dea82d26ca2b3ad0
Revision: 6 Revision: 7
Branch: refactor Branch: refactor
Last Changed Author: Dhanya_Thattil Last Changed Author: Erik_Frojdh
Last Changed Rev: 4131 Last Changed Rev: 4154
Last Changed Date: 2018-10-29 17:14:27.000000002 +0100 ./Beb.c Last Changed Date: 2018-10-30 12:17:09.000000002 +0100 ./FebInterface.c

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "92fc837eb490650d91c2283943cbd729b2e36567" #define GITREPUUID "3d40d5d0585931f7f4a42912dea82d26ca2b3ad0"
#define GITAUTH "Dhanya_Thattil" #define GITAUTH "Erik_Frojdh"
#define GITREV 0x4131 #define GITREV 0x4154
#define GITDATE 0x20181029 #define GITDATE 0x20181030
#define GITBRANCH "refactor" #define GITBRANCH "refactor"

View File

@ -151,18 +151,11 @@ std::string multiSlsDetector::getErrorMessage(int &critical, int detPos) {
if ((multiMask & (1 << idet)) || (detPos >= 0)) { if ((multiMask & (1 << idet)) || (detPos >= 0)) {
// append detector id // append detector id
// sprintf(sNumber, "%ld", idet);
retval.append("Detector " + std::to_string(idet) + retval.append("Detector " + std::to_string(idet) +
std::string(":\n")); std::string(":\n"));
// get sls det error mask // get sls det error mask
slsMask = detectors[idet]->getErrorMask(); slsMask = detectors[idet]->getErrorMask();
#ifdef VERYVERBOSE
// append sls det error mask
// sprintf(sNumber, "0x%lx", slsMask);
retval.append("Error Mask " + std::to_string(slsMask) +
std::string("\n"));
#endif
// get the error critical level // get the error critical level
if ((slsMask > 0xFFFFFFFF) | critical) if ((slsMask > 0xFFFFFFFF) | critical)
@ -207,10 +200,9 @@ bool multiSlsDetector::getAcquiringFlag() const {
bool multiSlsDetector::isAcquireReady() { bool multiSlsDetector::isAcquireReady() {
if (thisMultiDetector->acquiringFlag) { if (thisMultiDetector->acquiringFlag) {
std::cout << "Acquire has already started. " FILE_LOG(logWARNING) << "Acquire has already started. "
"If previous acquisition terminated unexpectedly, " "If previous acquisition terminated unexpectedly, "
"reset busy flag to restart.(sls_detector_put busy 0)" "reset busy flag to restart.(sls_detector_put busy 0)";
<< std::endl;
return FAIL; return FAIL;
} }
thisMultiDetector->acquiringFlag = true; thisMultiDetector->acquiringFlag = true;
@ -329,10 +321,9 @@ void multiSlsDetector::initSharedMemory(bool verify) {
thisMultiDetector = thisMultiDetector =
(sharedMultiSlsDetector *)sharedMemory->OpenSharedMemory(sz); (sharedMultiSlsDetector *)sharedMemory->OpenSharedMemory(sz);
if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) { if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) {
cprintf(RED, FILE_LOG(logERROR) << "Multi shared memory (" << detId << ") version mismatch "
"Multi shared memory (%d) version mismatch " "(expected 0x" << std::hex << MULTI_SHMVERSION <<
"(expected 0x%x but got 0x%x)\n", " but got 0x" << thisMultiDetector->shmversion << std::dec;
detId, MULTI_SHMVERSION, thisMultiDetector->shmversion);
throw SharedMemoryException(); throw SharedMemoryException();
} }
} }
@ -443,8 +434,8 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
// multi // multi
// this check is there only to allow the previous detsizechan command // this check is there only to allow the previous detsizechan command
if (thisMultiDetector->numberOfDetectors) { if (thisMultiDetector->numberOfDetectors) {
cprintf(RED, "Warning: There are already detector(s) in shared memory." FILE_LOG(logWARNING) << "There are already detector(s) in shared memory."
"Freeing Shared memory now.\n"); "Freeing Shared memory now.";
freeSharedMemory(); freeSharedMemory();
setupMultiDetector(); setupMultiDetector();
} }
@ -471,15 +462,13 @@ void multiSlsDetector::addMultipleDetectors(const char *name) {
} }
void multiSlsDetector::addSlsDetector(std::string s) { void multiSlsDetector::addSlsDetector(std::string s) {
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Adding detector " << s;
std::cout << "Adding detector " << s << std::endl;
#endif
for (auto &d : detectors) { for (auto &d : detectors) {
if (d->getHostname() == s) { if (d->getHostname() == s) {
std::cout << "Detector " << s FILE_LOG(logWARNING) << "Detector " << s
<< "already part of the multiDetector!" << std::endl << "already part of the multiDetector!" << std::endl
<< "Remove it before adding it back in a new position!" << "Remove it before adding it back in a new position!";
<< std::endl;
return; return;
} }
} }
@ -491,8 +480,8 @@ void multiSlsDetector::addSlsDetector(std::string s) {
// get type by connecting // get type by connecting
detectorType type = slsDetector::getDetectorType(s.c_str(), DEFAULT_PORTNO); detectorType type = slsDetector::getDetectorType(s.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) { if (type == GENERIC) {
std::cout << "Could not connect to Detector " << s FILE_LOG(logERROR) << "Could not connect to Detector " << s
<< " to determine the type!" << std::endl; << " to determine the type!";
setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED); setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED);
appendNotAddedList(s.c_str()); appendNotAddedList(s.c_str());
return; return;
@ -595,11 +584,8 @@ void multiSlsDetector::setDetectorOffset(dimension d, int off, int detPos) {
} }
void multiSlsDetector::updateOffsets() { void multiSlsDetector::updateOffsets() {
// cannot paralllize due to slsdetector calling this via parentdet-> FILE_LOG(logDEBUG1) << "Updating Multi-Detector Offsets";
#ifdef VERBOSE
std::cout << std::endl
<< "Updating Multi-Detector Offsets" << std::endl;
#endif
int offsetX = 0, offsetY = 0, numX = 0, numY = 0; int offsetX = 0, offsetY = 0, numX = 0, numY = 0;
int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X]; int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X];
int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y]; int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y];
@ -619,43 +605,27 @@ void multiSlsDetector::updateOffsets() {
thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0; thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0;
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "offsetX:" << offsetX << " prevChanX:" << prevChanX <<
std::cout << "offsetX:" << offsetX << " prevChanX:" << prevChanX " offsetY:" << offsetY << " prevChanY:" << prevChanY <<
<< " " " offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp <<
"offsetY:" " offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp;
<< offsetY << " prevChanY:" << prevChanY << std::endl;
std::cout << "offsetX_gp:" << offsetX_gp
<< " "
"prevChanX_gp:"
<< prevChanX_gp
<< " "
"offsetY_gp:"
<< offsetY_gp
<< " "
"prevChanY_gp:"
<< prevChanY_gp << std::endl;
#endif
// std::cout<<" totalchan:"<<
// detectors[idet]->getTotalNumberOfChannels(Y)
//<<" maxChanY:"<<maxChanY<<std::endl;
// incrementing in both direction // incrementing in both direction
if (firstTime) { if (firstTime) {
// incrementing in both directions // incrementing in both directions
firstTime = false; firstTime = false;
if ((maxChanX > 0) && if ((maxChanX > 0) &&
((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > ((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
maxChanX)) FILE_LOG(logWARNING) << "\nDetector[" << idet
std::cout << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in X dimension!" "allowed for complete detector set in X dimension!";
<< std::endl; }
if ((maxChanY > 0) && if ((maxChanY > 0) &&
((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > ((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > maxChanY)) {
maxChanY)) FILE_LOG(logERROR) << "\nDetector[" << idet
std::cout << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in Y dimension!" "allowed for complete detector set in Y dimension!";
<< std::endl; }
prevChanX = detectors[idet]->getTotalNumberOfChannels(X); prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanX_gp = prevChanX_gp =
@ -670,9 +640,7 @@ void multiSlsDetector::updateOffsets() {
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++thisMultiDetector->numberOfDetector[X]; ++thisMultiDetector->numberOfDetector[X];
++thisMultiDetector->numberOfDetector[Y]; ++thisMultiDetector->numberOfDetector[Y];
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "incrementing in both direction";
std::cout << "incrementing in both direction" << std::endl;
#endif
} }
// incrementing in y direction // incrementing in y direction
@ -689,20 +657,18 @@ void multiSlsDetector::updateOffsets() {
numY_gp += numY_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y); detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++thisMultiDetector->numberOfDetector[Y]; ++thisMultiDetector->numberOfDetector[Y];
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "incrementing in y direction";
std::cout << "incrementing in y direction" << std::endl;
#endif
} }
// incrementing in x direction // incrementing in x direction
else { else {
if ((maxChanX > 0) && if ((maxChanX > 0) &&
((offsetX + prevChanX + ((offsetX + prevChanX +
detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
std::cout << "\nDetector[" << idet FILE_LOG(logDEBUG1) << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in X dimension!" "allowed for complete detector set in X dimension!";
<< std::endl; }
offsetY = 0; offsetY = 0;
offsetY_gp = 0; offsetY_gp = 0;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
@ -720,9 +686,7 @@ void multiSlsDetector::updateOffsets() {
numX_gp += numX_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
++thisMultiDetector->numberOfDetector[X]; ++thisMultiDetector->numberOfDetector[X];
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "incrementing in x direction";
std::cout << "incrementing in x direction" << std::endl;
#endif
} }
double bytesperchannel = double bytesperchannel =
@ -734,11 +698,9 @@ void multiSlsDetector::updateOffsets() {
detectors[idet]->setDetectorOffset( detectors[idet]->setDetectorOffset(
Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY); Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY);
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets ("
std::cout << "Detector[" << idet << "] has offsets ("
<< detectors[idet]->getDetectorOffset(X) << ", " << detectors[idet]->getDetectorOffset(X) << ", "
<< detectors[idet]->getDetectorOffset(Y) << ")" << std::endl; << detectors[idet]->getDetectorOffset(Y) << ")";
#endif
// offsetY has been reset sometimes and offsetX the first time, // offsetY has been reset sometimes and offsetX the first time,
// but remember the highest values // but remember the highest values
if (numX > thisMultiDetector->numberOfChannel[X]) if (numX > thisMultiDetector->numberOfChannel[X])
@ -750,19 +712,15 @@ void multiSlsDetector::updateOffsets() {
if (numY_gp > thisMultiDetector->numberOfChannelInclGapPixels[Y]) if (numY_gp > thisMultiDetector->numberOfChannelInclGapPixels[Y])
thisMultiDetector->numberOfChannelInclGapPixels[Y] = numY_gp; thisMultiDetector->numberOfChannelInclGapPixels[Y] = numY_gp;
} }
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "\n\tNumber of Channels in X direction:" <<
std::cout << "Number of Channels in X direction:" thisMultiDetector->numberOfChannel[X] <<
<< thisMultiDetector->numberOfChannel[X] << std::endl; "\n\tNumber of Channels in Y direction:" <<
std::cout << "Number of Channels in Y direction:" thisMultiDetector->numberOfChannel[Y] <<
<< thisMultiDetector->numberOfChannel[Y] << std::endl "\n\tNumber of Channels in X direction with Gap Pixels:" <<
<< std::endl; thisMultiDetector->numberOfChannelInclGapPixels[X] <<
std::cout << "Number of Channels in X direction with Gap Pixels:" "\n\tNumber of Channels in Y direction with Gap Pixels:" <<
<< thisMultiDetector->numberOfChannelInclGapPixels[X] thisMultiDetector->numberOfChannelInclGapPixels[Y];
<< std::endl;
std::cout << "Number of Channels in Y direction with Gap Pixels:"
<< thisMultiDetector->numberOfChannelInclGapPixels[Y] << std::endl
<< std::endl;
#endif
thisMultiDetector->numberOfChannels = thisMultiDetector->numberOfChannels =
thisMultiDetector->numberOfChannel[0] * thisMultiDetector->numberOfChannel[0] *
thisMultiDetector->numberOfChannel[1]; thisMultiDetector->numberOfChannel[1];
@ -853,7 +811,7 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
char *args[100]; char *args[100];
char myargs[100][1000]; char myargs[100][1000];
std::cout << "Loading configuration file: " << fname << std::endl; FILE_LOG(logINFO) << "Loading configuration file: " << fname;
std::ifstream input_file; std::ifstream input_file;
input_file.open(fname, std::ios_base::in); input_file.open(fname, std::ios_base::in);
@ -863,10 +821,7 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
getline(input_file, current_line); getline(input_file, current_line);
if (current_line.find('#') != std::string::npos) if (current_line.find('#') != std::string::npos)
current_line.erase(current_line.find('#')); current_line.erase(current_line.find('#'));
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "current_line after removing comments:\n\t" << current_line;
std::cout << "current_line after removing comments:" << current_line
<< std::endl;
#endif
if (current_line.length() > 1) { if (current_line.length() > 1) {
std::istringstream line_stream(current_line); std::istringstream line_stream(current_line);
int n_arguments = 0; int n_arguments = 0;
@ -882,17 +837,15 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
} }
input_file.close(); input_file.close();
} else { } else {
std::cout << "Error opening configuration file " << fname FILE_LOG(logERROR) << "Could not openconfiguration file " << fname << " for reading";
<< " for reading" << std::endl;
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
return FAIL; return FAIL;
} }
if (getErrorMask()) { if (getErrorMask()) {
int c; int c;
cprintf(RED, FILE_LOG(logERROR) << "----------------\n Error Messages\n----------------";
"\n----------------\n Error Messages\n----------------\n%s\n", FILE_LOG(logERROR) << getErrorMessage(c);
getErrorMessage(c).c_str());
return FAIL; return FAIL;
} }
return OK; return OK;
@ -915,14 +868,14 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
auto cmd = slsDetectorCommand(this); auto cmd = slsDetectorCommand(this);
// complete size of detector // complete size of detector
std::cout << iline << " " << names[iline] << std::endl; FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION)
<< std::endl; << std::endl;
++iline; ++iline;
// hostname of the detectors // hostname of the detectors
std::cout << iline << " " << names[iline] << std::endl; FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION)
<< std::endl; << std::endl;
@ -941,20 +894,16 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
outfile << std::endl; outfile << std::endl;
// other configurations // other configurations
while (iline < names.size()) { while (iline < names.size()) {
std::cout << iline << " " << names[iline] << std::endl; FILE_LOG(logINFO) << "Command to write:" << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " outfile << names[iline] << " "
<< cmd.executeLine(1, args, GET_ACTION) << std::endl; << cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline; ++iline;
} }
outfile.close(); outfile.close();
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "wrote " << iline << " lines to configuration file ";
std::cout << "wrote " << iline << " lines to configuration file "
<< std::endl;
#endif
} else { } else {
std::cout << "Error opening configuration file " << fname FILE_LOG(logERROR) << "Could not open configuration file " << fname << " for writing";
<< " for writing" << std::endl;
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
ret = FAIL; ret = FAIL;
} }
@ -1818,14 +1767,14 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
} }
// multi // multi
int i, xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX, int xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX,
lastChannelY, index, offsetX, offsetY; lastChannelY, index, offsetX, offsetY;
bool invalidroi = false; bool invalidroi = false;
int ndet = detectors.size(); int ndet = detectors.size();
ROI allroi[ndet][n]; ROI allroi[ndet][n];
int nroi[ndet]; int nroi[ndet];
for (i = 0; i < ndet; ++i) for (int i = 0; i < ndet; ++i)
nroi[i] = 0; nroi[i] = 0;
if ((n < 0) || (roiLimits == NULL)) if ((n < 0) || (roiLimits == NULL))
@ -1833,15 +1782,12 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// ensures min < max // ensures min < max
verifyMinMaxROI(n, roiLimits); verifyMinMaxROI(n, roiLimits);
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:";
std::cout << "Setting ROI for " << n << "rois:" << std::endl; for (int i = 0; i < n; ++i)
for (i = 0; i < n; ++i) FILE_LOG(logDEBUG1) << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax
std::cout << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax << "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax;
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax
<< std::endl;
#endif
// for each roi // for each roi
for (i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
xmin = roiLimits[i].xmin; xmin = roiLimits[i].xmin;
xmax = roiLimits[i].xmax; xmax = roiLimits[i].xmax;
ymin = roiLimits[i].ymin; ymin = roiLimits[i].ymin;
@ -1849,13 +1795,11 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// check roi max values // check roi max values
idet = decodeNChannel(xmax, ymax, channelX, channelY); idet = decodeNChannel(xmax, ymax, channelX, channelY);
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl <<
std::cout << "Decoded Channel max vals: " << std::endl; "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" <<
std::cout << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" channelX << "\t" << channelY;
<< channelX << "\t" << channelY << std::endl;
#endif
if (idet == -1) { if (idet == -1) {
std::cout << "invalid roi" << std::endl; FILE_LOG(logERROR) << "invalid roi";
continue; continue;
} }
@ -1867,13 +1811,11 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
while (ymin <= ymax) { while (ymin <= ymax) {
// get offset for each detector // get offset for each detector
idet = decodeNChannel(xmin, ymin, channelX, channelY); idet = decodeNChannel(xmin, ymin, channelX, channelY);
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Decoded Channel min vals: " << std::endl <<
std::cout << "Decoded Channel min vals: " << std::endl; "det:" << idet << "\t" << xmin << "\t" << ymin <<
std::cout << "det:" << idet << "\t" << xmin << "\t" << ymin "\t" << channelX << "\t" << channelY;
<< "\t" << channelX << "\t" << channelY << std::endl;
#endif
if (idet < 0 || idet >= (int)detectors.size()) { if (idet < 0 || idet >= (int)detectors.size()) {
std::cout << "invalid roi" << std::endl; FILE_LOG(logDEBUG1) << "invalid roi";
invalidroi = true; invalidroi = true;
break; break;
} }
@ -1896,10 +1838,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
if ((offsetY + lastChannelY) >= ymax) if ((offsetY + lastChannelY) >= ymax)
lastChannelY = ymax - offsetY; lastChannelY = ymax - offsetY;
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "lastChannelX:" << lastChannelX << "\t" <<
std::cout << "lastChannelX:" << lastChannelX << "\t" "lastChannelY:" << lastChannelY;
<< "lastChannelY:" << lastChannelY << std::endl;
#endif
// creating the list of roi for corresponding detector // creating the list of roi for corresponding detector
index = nroi[idet]; index = nroi[idet];
@ -1913,10 +1853,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
if ((lastChannelY + offsetY) == ymax) if ((lastChannelY + offsetY) == ymax)
ymin = ymax + 1; ymin = ymax + 1;
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin;
std::cout << "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin
<< std::endl;
#endif
} }
if (invalidroi) if (invalidroi)
break; break;
@ -1927,22 +1864,19 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
} }
} }
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Setting ROI :";
std::cout << "Setting ROI :" << std::endl; for (size_t i = 0; i < detectors.size(); ++i) {
for (i = 0; i < detectors.size(); ++i) { FILE_LOG(logDEBUG1) << "detector " << i;
std::cout << "detector " << i << std::endl;
for (int j = 0; j < nroi[i]; ++j) { for (int j = 0; j < nroi[i]; ++j) {
std::cout << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t" FILE_LOG(logDEBUG1) << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t"
<< allroi[i][j].ymin << "\t" << allroi[i][j].ymax << allroi[i][j].ymin << "\t" << allroi[i][j].ymax;
<< std::endl;
} }
} }
#endif
// settings the rois for each detector // settings the rois for each detector
std::vector<int> r; std::vector<int> r;
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
r.push_back(detectors[idet]->setROI(nroi[i], allroi[i])); r.push_back(detectors[idet]->setROI(nroi[idet], allroi[idet]));
} }
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
@ -1968,15 +1902,12 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
temp = detectors[idet]->getROI(index); temp = detectors[idet]->getROI(index);
if (temp) { if (temp) {
//#ifdef VERBOSE if (index) {
if (index) FILE_LOG(logINFO) << "detector " << idet << ":";
std::cout << "detector " << idet << ":" << std::endl; }
//#endif
for (j = 0; j < index; ++j) { for (j = 0; j < index; ++j) {
//#ifdef VERBOSE FILE_LOG(logINFO) << temp[j].xmin << "\t" << temp[j].xmax << "\t"
std::cout << temp[j].xmin << "\t" << temp[j].xmax << "\t" << temp[j].ymin << "\t" << temp[j].ymax;
<< temp[j].ymin << "\t" << temp[j].ymax << std::endl;
//#endif
int x = detectors[idet]->getDetectorOffset(X); int x = detectors[idet]->getDetectorOffset(X);
int y = detectors[idet]->getDetectorOffset(Y); int y = detectors[idet]->getDetectorOffset(Y);
roiLimits[n].xmin = temp[j].xmin + x; roiLimits[n].xmin = temp[j].xmin + x;
@ -1992,14 +1923,12 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
if (!n) if (!n)
return NULL; return NULL;
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "ROI :" << std::endl;
std::cout << "ROI :" << std::endl;
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
std::cout << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax << roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
<< std::endl;
} }
#endif
// combine all the adjacent rois in x direction // combine all the adjacent rois in x direction
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
@ -2033,15 +1962,11 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
} }
} }
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector " << i;
std::cout << "Combined along x axis Getting ROI :" << std::endl;
std::cout << "detector " << i << std::endl;
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
std::cout << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax << roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
<< std::endl;
} }
#endif
// combine all the adjacent rois in y direction // combine all the adjacent rois in y direction
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
@ -2094,10 +2019,10 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
} }
n = num; n = num;
std::cout << "\nxmin\txmax\tymin\tymax" << std::endl; FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax";
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
std::cout << retval[i].xmin << "\t" << retval[i].xmax << "\t" FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t"
<< retval[i].ymin << "\t" << retval[i].ymax << std::endl; << retval[i].ymin << "\t" << retval[i].ymax;
return retval; return retval;
} }
@ -2689,7 +2614,7 @@ int multiSlsDetector::resetFramesCaught(int detPos) {
int multiSlsDetector::createReceivingDataSockets(const bool destroy) { int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
if (destroy) { if (destroy) {
cprintf(MAGENTA, "Going to destroy data sockets\n"); FILE_LOG(logINFO) << "Going to destroy data sockets";
// close socket // close socket
zmqSocket.clear(); zmqSocket.clear();
@ -2698,7 +2623,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
return OK; return OK;
} }
cprintf(MAGENTA, "Going to create data sockets\n"); FILE_LOG(logINFO) << "Going to create data sockets";
size_t numSockets = detectors.size(); size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1; size_t numSocketsPerDetector = 1;
@ -2717,11 +2642,10 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
->getClientStreamingIP() ->getClientStreamingIP()
.c_str(), .c_str(),
portnum)); portnum));
printf("Zmq Client[%lu] at %s\n", iSocket, FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " <<
zmqSocket.back()->GetZmqServerAddress()); zmqSocket.back()->GetZmqServerAddress();
} catch (...) { } catch (...) {
cprintf(RED, "Error: Could not create Zmq socket on port %d\n", FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
portnum);
createReceivingDataSockets(true); createReceivingDataSockets(true);
return FAIL; return FAIL;
} }
@ -2756,8 +2680,7 @@ void multiSlsDetector::readFrameFromReceiver() {
} else { } else {
// to remember the list it connected to, to disconnect later // to remember the list it connected to, to disconnect later
connectList[i] = false; connectList[i] = false;
cprintf(RED, "Error: Could not connect to socket %s\n", FILE_LOG(logERROR) << "Could not connect to socket " << zmqSocket[i]->GetZmqServerAddress();
zmqSocket[i]->GetZmqServerAddress());
runningList[i] = false; runningList[i] = false;
} }
} }
@ -2822,18 +2745,14 @@ void multiSlsDetector::readFrameFromReceiver() {
nPixelsX = doc["shape"][0].GetUint(); nPixelsX = doc["shape"][0].GetUint();
nPixelsY = doc["shape"][1].GetUint(); nPixelsY = doc["shape"][1].GetUint();
#ifdef VERBOSE FILE_LOG(logDEBUG1) <<
cprintf(BLUE, "One Time Header Info:"
"(Debug) One Time Header Info:\n" "\n\tsize: " << size <<
"size: %u\n" "\n\tmultisize: " << multisize <<
"multisize: %u\n" "\n\tdynamicRange: " << dynamicRange <<
"dynamicRange: %u\n" "\n\tbytesPerPixel: " << bytesPerPixel <<
"bytesPerPixel: %f\n" "\n\tnPixelsX: " << nPixelsX <<
"nPixelsX: %u\n" "\n\tnPixelsY: " << nPixelsY;
"nPixelsY: %u\n",
size, multisize, dynamicRange, bytesPerPixel,
nPixelsX, nPixelsY);
#endif
} }
// each time, parse rest of header // each time, parse rest of header
currentFileName = doc["fname"].GetString(); currentFileName = doc["fname"].GetString();
@ -2845,24 +2764,17 @@ void multiSlsDetector::readFrameFromReceiver() {
coordX = doc["column"].GetUint(); coordX = doc["column"].GetUint();
if (eiger) if (eiger)
coordY = (nY - 1) - coordY; coordY = (nY - 1) - coordY;
// std::cout << "X:" << doc["row"].GetUint() <<"
// Y:"<<doc["column"].GetUint();
flippedDataX = doc["flippedDataX"].GetUint(); flippedDataX = doc["flippedDataX"].GetUint();
#ifdef VERBOSE FILE_LOG(logDEBUG1) <<
cprintf(BLUE, "Header Info:"
"(Debug) Header Info:\n" "\n\tcurrentFileName: " << currentFileName <<
"currentFileName: %s\n" "\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex <<
"currentAcquisitionIndex: %lu\n" "\n\tcurrentFrameIndex: " << currentFrameIndex <<
"currentFrameIndex: %lu\n" "\n\tcurrentFileIndex: " << currentFileIndex <<
"currentFileIndex: %lu\n" "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex <<
"currentSubFrameIndex: %u\n" "\n\tcoordX: " << coordX <<
"coordX: %u\n" "\n\tcoordY: " << coordY <<
"coordY: %u\n" "\n\tflippedDataX: " << flippedDataX;
"flippedDataX: %u\n",
currentFileName.c_str(), currentAcquisitionIndex,
currentFrameIndex, currentFileIndex,
currentSubFrameIndex, coordX, coordY, flippedDataX);
#endif
} }
// DATA // DATA
@ -2875,15 +2787,13 @@ void multiSlsDetector::readFrameFromReceiver() {
uint32_t yoffset = coordY * nPixelsY; uint32_t yoffset = coordY * nPixelsY;
uint32_t singledetrowoffset = nPixelsX * bytesPerPixel; uint32_t singledetrowoffset = nPixelsX * bytesPerPixel;
uint32_t rowoffset = nX * singledetrowoffset; uint32_t rowoffset = nX * singledetrowoffset;
#ifdef VERBOSE FILE_LOG(logDEBUG1) <<
cprintf(BLUE, "Multi Image Info:"
"(Debug) Multi Image Info:\n" "\n\txoffset: " << xoffset <<
"xoffset: %u\n" "\n\tyoffset: " << yoffset <<
"yoffset: %u\n" "\n\tsingledetrowoffset: " << singledetrowoffset <<
"singledetrowoffset: %u\n" "\n\trowoffset: " << rowoffset;
"rowoffset: %u\n",
xoffset, yoffset, singledetrowoffset, rowoffset);
#endif
if (eiger && flippedDataX) { if (eiger && flippedDataX) {
for (uint32_t i = 0; i < nPixelsY; ++i) { for (uint32_t i = 0; i < nPixelsY; ++i) {
memcpy(((char *)multiframe) + memcpy(((char *)multiframe) +
@ -3288,9 +3198,7 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
int iline = 0; int iline = 0;
if (level == 2) { if (level == 2) {
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "config file read";
std::cout << "config file read" << std::endl;
#endif
fname = fname1 + std::string(".det"); fname = fname1 + std::string(".det");
} else } else
fname = fname1; fname = fname1;
@ -3303,14 +3211,9 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
sargval = "0"; sargval = "0";
getline(infile, str); getline(infile, str);
iline++; iline++;
#ifdef VERBOSE FILE_LOG(logDEBUG1) << str;
std::cout << str << std::endl;
#endif
if (str.find('#') != std::string::npos) { if (str.find('#') != std::string::npos) {
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Line is a comment \n" << str;
std::cout << "Line is a comment " << std::endl;
std::cout << str << std::endl;
#endif
continue; continue;
} else { } else {
std::istringstream ssstr(str); std::istringstream ssstr(str);
@ -3320,9 +3223,7 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
// if (ssstr.good()) { // if (ssstr.good()) {
strcpy(myargs[iargval], sargname.c_str()); strcpy(myargs[iargval], sargname.c_str());
args[iargval] = myargs[iargval]; args[iargval] = myargs[iargval];
#ifdef VERBOSE FILE_LOG(logDEBUG1) << args[iargval];
std::cout << args[iargval] << std::endl;
#endif
iargval++; iargval++;
// } // }
skip = 0; skip = 0;
@ -3340,12 +3241,10 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
infile.close(); infile.close();
} else { } else {
std::cout << "Error opening " << fname << " for reading" << std::endl; FILE_LOG(logERROR) << "Error opening " << fname << " for reading";
return FAIL; return FAIL;
} }
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "Read " << iline << " lines";
std::cout << "Read " << iline << " lines" << std::endl;
#endif
if (getErrorMask()) if (getErrorMask())
return FAIL; return FAIL;
@ -3457,14 +3356,11 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
} }
outfile.close(); outfile.close();
} else { } else {
std::cout << "Error opening parameters file " << fname1 FILE_LOG(logERROR) << "Could not open parameters file " << fname1 << " for writing";
<< " for writing" << std::endl;
return FAIL; return FAIL;
} }
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "wrote " << iv << " lines to " << fname1;
std::cout << "wrote " << iv << " lines to " << fname1 << std::endl;
#endif
return OK; return OK;
} }
@ -3515,13 +3411,8 @@ int multiSlsDetector::setTotalProgress() {
totalProgress = nm * nf * nc * ns; totalProgress = nm * nf * nc * ns;
#ifdef VERBOSE FILE_LOG(logDEBUG1) << "nm " << nm << " nf " << nf << " nc " << nc << " ns " << ns;
std::cout << "nm " << nm << std::endl; FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl;
std::cout << "nf " << nf << std::endl;
std::cout << "nc " << nc << std::endl;
std::cout << "ns " << ns << std::endl;
std::cout << "Set total progress " << totalProgress << std::endl;
#endif
return totalProgress; return totalProgress;
} }
@ -3553,10 +3444,8 @@ int multiSlsDetector::acquire() {
if (isAcquireReady() == FAIL) if (isAcquireReady() == FAIL)
return FAIL; return FAIL;
#ifdef VERBOSE
struct timespec begin, end; struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
#endif
// in the real time acquisition loop, processing thread will wait for a post // in the real time acquisition loop, processing thread will wait for a post
// each time // each time
@ -3601,7 +3490,7 @@ int multiSlsDetector::acquire() {
if (receiver) { if (receiver) {
std::lock_guard<std::mutex> lock(mg); std::lock_guard<std::mutex> lock(mg);
if (startReceiver() == FAIL) { if (startReceiver() == FAIL) {
std::cout << "Start receiver failed " << std::endl; FILE_LOG(logERROR) << "Start receiver failed ";
stopReceiver(); stopReceiver();
thisMultiDetector->stoppedFlag = 1; thisMultiDetector->stoppedFlag = 1;
break; break;
@ -3651,13 +3540,11 @@ int multiSlsDetector::acquire() {
sem_destroy(&sem_newRTAcquisition); sem_destroy(&sem_newRTAcquisition);
sem_destroy(&sem_endRTAcquisition); sem_destroy(&sem_endRTAcquisition);
#ifdef VERBOSE
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
std::cout << "Elapsed time for acquisition:" FILE_LOG(logDEBUG1) << "Elapsed time for acquisition:"
<< ((end.tv_sec - begin.tv_sec) + << ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0) (end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds" << std::endl; << " seconds";
#endif
setAcquiringFlag(false); setAcquiringFlag(false);
@ -3688,8 +3575,7 @@ void multiSlsDetector::processData() {
// to exit acquire by typing q // to exit acquire by typing q
if (kbhit() != 0) { if (kbhit() != 0) {
if (fgetc(stdin) == 'q') { if (fgetc(stdin) == 'q') {
std::cout << "Caught the command to stop acquisition" FILE_LOG(logINFO) << "Caught the command to stop acquisition";
<< std::endl;
stopAcquisition(); stopAcquisition();
} }
} }

View File

@ -648,16 +648,19 @@ void slsDetector::disconnectControl() {
controlSocket->Disconnect(); controlSocket->Disconnect();
} }
void slsDetector::connectDataError() {
FILE_LOG(logERROR) << "Cannot connect to receiver";
setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER));
}
int slsDetector::connectData() { int slsDetector::connectData() {
if (dataSocket) { if (dataSocket) {
if (dataSocket->Connect() >= 0) if (dataSocket->Connect() >= 0)
return OK; return OK;
else { else {
FILE_LOG(logERROR) << "Cannot connect to receiver"; connectDataError();
setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); return FAIL;
return FAIL;} }
} }
return UNDEFINED; return UNDEFINED;
} }

View File

@ -353,6 +353,11 @@ public:
*/ */
void disconnectControl(); void disconnectControl();
/**
* Could not connect to receiver, log error
*/
void connectDataError();
/** /**
* Connect to the data port * Connect to the data port
* @returns OK, FAIL or undefined * @returns OK, FAIL or undefined

View File

@ -14,22 +14,33 @@ void ClientInterface::SetSocket(MySocketTCP *socket) {
} }
int ClientInterface::Client_GetMesage(char* mess) { void ClientInterface::Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval) {
bool created = false; // get result of operation
int ret = OK; mySocket->ReceiveDataOnly(&ret,sizeof(ret));
if (!mess){
created = true;
mess = new char[MAX_STR_LENGTH];
memset(mess, 0, MAX_STR_LENGTH);
}
mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH);
cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
if(strstr(mess,"Unrecognized Function")!=NULL)
ret = FAIL;
if (created) bool unrecognizedFunction = false;
delete [] mess; if (ret == FAIL) {
return ret; bool created = false;
// allocate mess if null
if (!mess){
created = true;
mess = new char[MAX_STR_LENGTH];
memset(mess, 0, MAX_STR_LENGTH);
}
// get error message
mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH);
cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
// unrecognized function, do not ask for retval
if(strstr(mess,"Unrecognized Function") != NULL)
unrecognizedFunction = true;
// delete allocated mess
if (created)
delete [] mess;
}
// get retval
if (!unrecognizedFunction)
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
} }
@ -37,18 +48,10 @@ int ClientInterface::Client_Send(int fnum,
void* args, int sizeOfArgs, void* args, int sizeOfArgs,
void* retval, int sizeOfRetval, void* retval, int sizeOfRetval,
char* mess) { char* mess) {
int ret = FAIL;
mySocket->SendDataOnly(&fnum,sizeof(fnum)); mySocket->SendDataOnly(&fnum,sizeof(fnum));
mySocket->SendDataOnly(args, sizeOfArgs); mySocket->SendDataOnly(args, sizeOfArgs);
Client_Receive(ret, mess, retval, sizeOfRetval);
int ret = FAIL;
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret == FAIL) {
if (Client_GetMesage(mess) == FAIL)
return FAIL;
}
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
return ret; return ret;
} }

View File

@ -34,23 +34,23 @@ public:
void SetSocket(MySocketTCP *socket); void SetSocket(MySocketTCP *socket);
/** /**
* Get message from server * Receive ret, mess or retval from Server
* Print appropriate message * @param ret result of operation
* Check for Unrecognized function in message and return fail if it does * @param mess pointer to message
* to prevent getting retval from the server afterwards * @param retval poitner to retval
* @param mess message * @param sizeOfRetval size of retval
* @returns FAIL if unrecognized function found in message, else OK
*/ */
int Client_GetMesage(char* mess = 0); void Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval);
/** /**
* Send Arguments to server and get result back * Send Arguments to server and receives result back
* @param fnum function enum to determine what parameter * @param fnum function enum to determine what parameter
* @param args pointer to arguments * @param args pointer to arguments
* @param sizeOfArgs argument size * @param sizeOfArgs argument size
* @param retval pointer to return value * @param retval pointer to return value
* @param sizeOfRetval return value size * @param sizeOfRetval return value size
* @param mess pointer to message if message required externally * @param mess pointer to message if message required externally
* @returns sucess of operation
*/ */
int Client_Send(int fnum, int Client_Send(int fnum,
void* args, int sizeOfArgs, void* args, int sizeOfArgs,

View File

@ -150,7 +150,7 @@ public:
sockfd.fd = socket(AF_INET, getProtocol(),0); //tcp sockfd.fd = socket(AF_INET, getProtocol(),0); //tcp
if (sockfd.fd < 0) { if (sockfd.fd < 0) {
cprintf(RED, "Can not create socket\n"); FILE_LOG(logERROR) << "Can not create socket";
sockfd.fd =-1; sockfd.fd =-1;
throw SocketException(); throw SocketException();
} }
@ -173,7 +173,7 @@ public:
int val=1; int val=1;
if (setsockopt(sockfd.fd,SOL_SOCKET,SO_REUSEADDR, if (setsockopt(sockfd.fd,SOL_SOCKET,SO_REUSEADDR,
&val,sizeof(int)) == -1) { &val,sizeof(int)) == -1) {
cprintf(RED, "setsockopt REUSEADDR failed\n"); FILE_LOG(logERROR) << "setsockopt REUSEADDR failed";
sockfd.fd =-1; sockfd.fd =-1;
throw SocketException(); throw SocketException();
} }
@ -192,10 +192,8 @@ public:
"Could not get rx socket receive buffer size"; "Could not get rx socket receive buffer size";
} else if (ret_size >= real_size) { } else if (ret_size >= real_size) {
actual_udp_socket_buffer_size = ret_size; actual_udp_socket_buffer_size = ret_size;
#ifdef VEBOSE FILE_LOG(logDEBUG1) << "[Port " << port_number << "] "
FILE_LOG(logINFO) << "[Port " << port_number << "] "
"UDP rx socket buffer size is sufficient (" << ret_size << ")"; "UDP rx socket buffer size is sufficient (" << ret_size << ")";
#endif
} }
// not sufficient, enhance size // not sufficient, enhance size
@ -244,7 +242,7 @@ public:
if(bind(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){ if(bind(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cprintf(RED, "Can not bind socket\n"); FILE_LOG(logERROR) << "Can not bind socket";
sockfd.fd =-1; sockfd.fd =-1;
throw SocketException(); throw SocketException();
} }
@ -313,7 +311,7 @@ public:
case UDP: case UDP:
return SOCK_DGRAM; return SOCK_DGRAM;
default: default:
cprintf(RED, "unknown protocol %d\n", p); FILE_LOG(logERROR) << "unknown protocol: " << p;
return -1; return -1;
} }
}; };
@ -365,74 +363,70 @@ public:
if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection
if (sockfd.fd>0) { if (sockfd.fd>0) {
if ((sockfd.newfd = accept(sockfd.fd,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { if ((sockfd.newfd = accept(sockfd.fd,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
cprintf(RED, "Error: with server accept, connection refused\n"); FILE_LOG(logERROR) << "with server accept, connection refused";
switch(errno) { switch(errno) {
case EWOULDBLOCK: case EWOULDBLOCK:
printf("ewouldblock eagain\n"); FILE_LOG(logERROR) << "ewouldblock eagain";
break; break;
case EBADF: case EBADF:
printf("ebadf\n"); FILE_LOG(logERROR) << "ebadf";
break; break;
case ECONNABORTED: case ECONNABORTED:
printf("econnaborted\n"); FILE_LOG(logERROR) << "econnaborted";
break; break;
case EFAULT: case EFAULT:
printf("efault\n"); FILE_LOG(logERROR) << "efault";
break; break;
case EINTR: case EINTR:
printf("eintr\n"); FILE_LOG(logERROR) << "eintr";
break; break;
case EINVAL: case EINVAL:
printf("einval\n"); FILE_LOG(logERROR) << "einval";
break; break;
case EMFILE: case EMFILE:
printf("emfile\n"); FILE_LOG(logERROR) << "emfile";
break; break;
case ENFILE: case ENFILE:
printf("enfile\n"); FILE_LOG(logERROR) << "enfile";
break; break;
case ENOTSOCK: case ENOTSOCK:
printf("enotsock\n"); FILE_LOG(logERROR) << "enotsock";
break; break;
case EOPNOTSUPP: case EOPNOTSUPP:
printf("eOPNOTSUPP\n"); FILE_LOG(logERROR) << "eOPNOTSUPP";
break; break;
case ENOBUFS: case ENOBUFS:
printf("ENOBUFS\n"); FILE_LOG(logERROR) << "ENOBUFS";
break; break;
case ENOMEM: case ENOMEM:
printf("ENOMEM\n"); FILE_LOG(logERROR) << "ENOMEM";
break; break;
case ENOSR: case ENOSR:
printf("ENOSR\n"); FILE_LOG(logERROR) << "ENOSR";
break; break;
case EPROTO: case EPROTO:
printf("EPROTO\n"); FILE_LOG(logERROR) << "EPROTO";
break; break;
default: default:
printf("unknown error\n"); FILE_LOG(logERROR) << "unknown error";
} }
} }
else{ else{
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN); inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
#ifdef VERY_VERBOSE FILE_LOG(logDEBUG1) << "client connected " << sockfd.newfd;
cout << "client connected "<< sockfd.newfd << endl;
#endif
} }
} }
#ifdef VERY_VERBOSE FILE_LOG(logDEBUG1) << "fd " << sockfd.newfd;
cout << "fd " << sockfd.newfd << endl;
#endif
return sockfd.newfd; return sockfd.newfd;
} else { } else {
if (sockfd.fd<=0) if (sockfd.fd<=0)
sockfd.fd = socket(AF_INET, getProtocol(),0); sockfd.fd = socket(AF_INET, getProtocol(),0);
// SetTimeOut(10); // SetTimeOut(10);
if (sockfd.fd < 0){ if (sockfd.fd < 0){
cprintf(RED, "Can not create socket\n"); FILE_LOG(logERROR) << "Can not create socket";
} else { } else {
if(connect(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){ if(connect(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cprintf(RED, "Can not connect to socket\n"); FILE_LOG(logERROR) << "Can not connect to socket";
return -1; return -1;
} }
} }
@ -470,13 +464,13 @@ public:
tout.tv_usec = 0; tout.tv_usec = 0;
if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_RCVTIMEO, if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_RCVTIMEO,
&tout, sizeof(struct timeval)) <0) { &tout, sizeof(struct timeval)) <0) {
cprintf(RED, "Error in setsockopt SO_RCVTIMEO %d\n", 0); FILE_LOG(logERROR) << "setsockopt SO_RCVTIMEO " << 0;
} }
tout.tv_sec = ts; tout.tv_sec = ts;
tout.tv_usec = 0; tout.tv_usec = 0;
if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_SNDTIMEO, if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_SNDTIMEO,
&tout, sizeof(struct timeval)) < 0) { &tout, sizeof(struct timeval)) < 0) {
cprintf(RED, "Error in setsockopt SO_SNDTIMEO %d\n", ts); FILE_LOG(logERROR) << "setsockopt SO_SNDTIMEO " << ts;
} }
return 0; return 0;
}; };
@ -508,7 +502,6 @@ public:
sa = (struct sockaddr_in *)(iap->ifa_addr); sa = (struct sockaddr_in *)(iap->ifa_addr);
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, buf_len); inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, buf_len);
if (ip==std::string(buf)) { if (ip==std::string(buf)) {
//printf("%s\n", iap->ifa_name);
strcpy(buf,iap->ifa_name); strcpy(buf,iap->ifa_name);
break; break;
} }
@ -615,17 +608,17 @@ public:
// get host info into res // get host info into res
int errcode = getaddrinfo (hostname, NULL, &hints, res); int errcode = getaddrinfo (hostname, NULL, &hints, res);
if (errcode != 0) { if (errcode != 0) {
cprintf (RED,"Error: Could not convert %s hostname to internet address (zmq):" FILE_LOG(logERROR) << "Could not convert hostname (" << hostname << ") to internet address (zmq):" <<
"%s\n", hostname, gai_strerror(errcode)); gai_strerror(errcode);
} else { } else {
if (*res == NULL) { if (*res == NULL) {
cprintf (RED,"Error: Could not convert %s hostname to internet address (zmq): " FILE_LOG(logERROR) << "Could not converthostname (" << hostname << ") to internet address (zmq):"
"gettaddrinfo returned null\n", hostname); "gettaddrinfo returned null";
} else{ } else{
return 0; return 0;
} }
} }
cprintf(RED, "Error: Could not convert hostname to internet address\n"); FILE_LOG(logERROR) << "Could not convert hostname to internet address";
return 1; return 1;
}; };
@ -643,7 +636,7 @@ public:
freeaddrinfo(res); freeaddrinfo(res);
return 0; return 0;
} }
cprintf(RED, "Error: Could not convert internet address to ip string\n"); FILE_LOG(logERROR) << "Could not convert internet address to ip string";
return 1; return 1;
} }
@ -697,7 +690,7 @@ public:
continue; continue;
if(nsent != nsending){ if(nsent != nsending){
if(nsent && (nsent != -1)) if(nsent && (nsent != -1))
cprintf(RED,"Incomplete Packet size %d\n",nsent); FILE_LOG(logERROR) << "Incomplete Packet size " << nsent;
break; break;
} }
length-=nsent; length-=nsent;
@ -709,16 +702,13 @@ public:
//normal //normal
nsending=packet_size; nsending=packet_size;
while(1){ while(1){
#ifdef VERYVERBOSE
cprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout);
#endif
nsent = recvfrom(sockfd.fd,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); nsent = recvfrom(sockfd.fd,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
//break out of loop only if read one packets size or read didnt work (cuz of shutdown) //break out of loop only if read one packets size or read didnt work (cuz of shutdown)
if(nsent<=0 || nsent == packet_size) if(nsent<=0 || nsent == packet_size)
break; break;
//incomplete packets or header packets ignored and read buffer again //incomplete packets or header packets ignored and read buffer again
if(nsent != packet_size && nsent != header_packet_size) if(nsent != packet_size && nsent != header_packet_size)
cprintf(RED,"%d Incomplete Packet size %d\n", portno, nsent); FILE_LOG(logERROR) << portno << ": Incomplete Packet size " << nsent;
} }
//nsent = 1040; //nsent = 1040;
if(nsent > 0)total_sent+=nsent; if(nsent > 0)total_sent+=nsent;
@ -727,9 +717,7 @@ public:
default: default:
; ;
} }
#ifdef VERY_VERBOSE FILE_LOG(logDEBUG1) << "sent " << total_sent << " Bytes";
cout << "sent "<< total_sent << " Bytes" << endl;
#endif
return total_sent; return total_sent;
} }
@ -740,9 +728,7 @@ public:
* @returns size of data sent * @returns size of data sent
*/ */
int SendDataOnly(void *buf, int length) { int SendDataOnly(void *buf, int length) {
#ifdef VERY_VERBOSE FILE_LOG(logDEBUG1) << "want to send " << length << " Bytes";
cout << "want to send "<< length << " Bytes" << endl;
#endif
if (buf==NULL) return -1; if (buf==NULL) return -1;
total_sent=0; total_sent=0;
@ -757,7 +743,7 @@ public:
nsending = (length>packet_size) ? packet_size:length; nsending = (length>packet_size) ? packet_size:length;
nsent = write(tcpfd,(char*)buf+total_sent,nsending); nsent = write(tcpfd,(char*)buf+total_sent,nsending);
if(is_a_server && nsent < 0) { if(is_a_server && nsent < 0) {
cprintf(BG_RED, "Error writing to socket. Possible client socket crash\n"); FILE_LOG(logERROR) << "Could not write to socket. Possible client socket crash";
break; break;
} }
if(!nsent) break; if(!nsent) break;
@ -779,9 +765,7 @@ public:
default: default:
; ;
} }
#ifdef VERY_VERBOSE FILE_LOG(logDEBUG1) << "sent "<< total_sent << " Bytes";
cout << "sent "<< total_sent << " Bytes" << endl;
#endif
return total_sent; return total_sent;
} }