added log printouts. Added hardcoded REST configuration

This commit is contained in:
2014-11-05 11:43:17 +01:00
committed by Manuel Guizar
parent f05248cd32
commit 8a63e7e184
5 changed files with 115 additions and 97 deletions

View File

@ -1,4 +1,3 @@
include ../Makefile.include include ../Makefile.include
DESTDIR ?= ../bin DESTDIR ?= ../bin

View File

@ -74,14 +74,11 @@ class RestHelper {
*/ */
//Check for http:// string //Check for http:// string
FILE_LOG(logDEBUG) << __func__ << " starting"; FILE_LOG(logDEBUG4) << __func__ << " starting";
string proto_str = "http://"; string proto_str = "http://";
if( size_t found = hostname.find(proto_str) != string::npos ){ if( size_t found = hostname.find(proto_str) != string::npos ){
cout << hostname << endl;
char c1[hostname.size()-found-1]; char c1[hostname.size()-found-1];
cout << c1 << endl;
size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size()); size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size());
c1[length1]='\0'; c1[length1]='\0';
hostname = c1; hostname = c1;
@ -168,7 +165,7 @@ class RestHelper {
string answer; string answer;
int code = send_request(session, req, &answer); int code = send_request(session, req, &answer);
if(code == 0 ) { if(code == 0 ) {
FILE_LOG(logDEBUG) << "ANSWER " << answer; FILE_LOG(logDEBUG4) << "REQUEST: " << " ANSWER: " << answer;
json_value->loadFromString(answer); json_value->loadFromString(answer);
} }
delete uri; delete uri;
@ -192,7 +189,6 @@ class RestHelper {
if (path.empty()) path = "/"; if (path.empty()) path = "/";
HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 );
req.setContentType("application/json\r\n"); req.setContentType("application/json\r\n");
cout << "REQUEST BODY " << request_body << endl;
req.setContentLength( request_body.length() ); req.setContentLength( request_body.length() );
int code = send_request(session, req, answer, request_body); int code = send_request(session, req, answer, request_body);
@ -266,9 +262,8 @@ class RestHelper {
if (request_body == "") if (request_body == "")
session->sendRequest( (req) ); session->sendRequest( (req) );
else{ else{
cout << request_body << endl; ostream &os = session->sendRequest( req ) ;
ostream &os = session->sendRequest( req ) ; os << request_body;
os << request_body;
} }
HTTPResponse res; HTTPResponse res;
@ -276,7 +271,7 @@ class RestHelper {
StreamCopier::copyToString(is, *answer); StreamCopier::copyToString(is, *answer);
code = res.getStatus(); code = res.getStatus();
if (code != 200){ if (code != 200){
cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ;
code = -1; code = -1;
} }
else else

View File

@ -50,6 +50,8 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
protected: protected:
void initialize_REST(); void initialize_REST();
int get_rest_state(RestHelper * rest, string *rest_state);
public: public:
void configure(map<string, string> config_map); void configure(map<string, string> config_map);

View File

@ -147,17 +147,17 @@ int UDPBaseImplementation::setDetectorType(detectorType det){
/*Frame indices and numbers caught*/ /*Frame indices and numbers caught*/
bool UDPBaseImplementation::getAcquistionStarted(){return acqStarted;}; bool UDPBaseImplementation::getAcquistionStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return acqStarted;};
bool UDPBaseImplementation::getMeasurementStarted(){return measurementStarted;}; bool UDPBaseImplementation::getMeasurementStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return measurementStarted;};
int UDPBaseImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (packetsCaught/packetsPerFrame);}
int UDPBaseImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);}
uint32_t UDPBaseImplementation::getStartFrameIndex(){return startFrameIndex;} uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;}
uint32_t UDPBaseImplementation::getFrameIndex(){ uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(!packetsCaught) if(!packetsCaught)
frameIndex=-1; frameIndex=-1;
else else
@ -166,7 +166,7 @@ uint32_t UDPBaseImplementation::getFrameIndex(){
} }
uint32_t UDPBaseImplementation::getAcquisitionIndex(){ uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(!totalPacketsCaught) if(!totalPacketsCaught)
acquisitionIndex=-1; acquisitionIndex=-1;
else else
@ -175,7 +175,7 @@ uint32_t UDPBaseImplementation::getAcquisitionIndex(){
} }
void UDPBaseImplementation::resetTotalFramesCaught(){ void UDPBaseImplementation::resetTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
acqStarted = false; acqStarted = false;
startAcquisitionIndex = 0; startAcquisitionIndex = 0;
totalPacketsCaught = 0; totalPacketsCaught = 0;
@ -185,10 +185,12 @@ void UDPBaseImplementation::resetTotalFramesCaught(){
/*file parameters*/ /*file parameters*/
char* UDPBaseImplementation::getFilePath() const{ char* UDPBaseImplementation::getFilePath() const{
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
return (char*)filePath; return (char*)filePath;
} }
inline char* UDPBaseImplementation::setFilePath(const char c[]){ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG) << __AT__ << "called"; FILE_LOG(logDEBUG) << __AT__ << "called";
if(strlen(c)){ if(strlen(c)){
//check if filepath exists //check if filepath exists
@ -207,10 +209,12 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){
char* UDPBaseImplementation::getFileName() const{ char* UDPBaseImplementation::getFileName() const{
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
return (char*)fileName; return (char*)fileName;
} }
inline char* UDPBaseImplementation::setFileName(const char c[]){ inline char* UDPBaseImplementation::setFileName(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
if(strlen(c)) if(strlen(c))
@ -220,11 +224,11 @@ inline char* UDPBaseImplementation::setFileName(const char c[]){
} }
int UDPBaseImplementation::getFileIndex(){ int UDPBaseImplementation::getFileIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileIndex; return fileIndex;
} }
int UDPBaseImplementation::setFileIndex(int i){ int UDPBaseImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
if(i>=0) if(i>=0)
fileIndex = i; fileIndex = i;
@ -232,7 +236,7 @@ int UDPBaseImplementation::setFileIndex(int i){
} }
int UDPBaseImplementation::setFrameIndexNeeded(int i){ int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
frameIndexNeeded = i; frameIndexNeeded = i;
return frameIndexNeeded; return frameIndexNeeded;
@ -240,19 +244,23 @@ int UDPBaseImplementation::setFrameIndexNeeded(int i){
int UDPBaseImplementation::getEnableFileWrite() const{ int UDPBaseImplementation::getEnableFileWrite() const{
return enableFileWrite; FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
return enableFileWrite;
} }
int UDPBaseImplementation::setEnableFileWrite(int i){ int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
enableFileWrite=i; enableFileWrite=i;
return getEnableFileWrite(); return getEnableFileWrite();
} }
int UDPBaseImplementation::getEnableOverwrite() const{ int UDPBaseImplementation::getEnableOverwrite() const{
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
return overwrite; return overwrite;
} }
int UDPBaseImplementation::setEnableOverwrite(int i){ int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
overwrite=i; overwrite=i;
return getEnableOverwrite(); return getEnableOverwrite();
} }
@ -268,7 +276,7 @@ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{
} }
void UDPBaseImplementation::initialize(const char *detectorHostName){ void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(detectorHostName)) if(strlen(detectorHostName))
strcpy(detHostname,detectorHostName); strcpy(detHostname,detectorHostName);
} }
@ -278,12 +286,12 @@ char *UDPBaseImplementation::getDetectorHostname() const{
return (char*)detHostname; return (char*)detHostname;
} }
void UDPBaseImplementation::setEthernetInterface(char* c){ void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(eth,c); strcpy(eth,c);
} }
void UDPBaseImplementation::setUDPPortNo(int p){ void UDPBaseImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " starting";
for(int i=0;i<numListeningThreads;i++){ for(int i=0;i<numListeningThreads;i++){
server_port[i] = p+i; server_port[i] = p+i;
} }
@ -295,7 +303,7 @@ int UDPBaseImplementation::getNumberOfFrames() const {
} }
int32_t UDPBaseImplementation::setNumberOfFrames(int32_t fnum){ int32_t UDPBaseImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(fnum >= 0) if(fnum >= 0)
numberOfFrames = fnum; numberOfFrames = fnum;
@ -308,7 +316,7 @@ int UDPBaseImplementation::getScanTag() const{
} }
int32_t UDPBaseImplementation::setScanTag(int32_t stag){ int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(stag >= 0) if(stag >= 0)
scanTag = stag; scanTag = stag;
@ -320,7 +328,7 @@ int UDPBaseImplementation::getDynamicRange() const{
return dynamicRange; return dynamicRange;
} }
int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting";
cout << "Setting Dynamic Range" << endl; cout << "Setting Dynamic Range" << endl;
int olddr = dynamicRange; int olddr = dynamicRange;
@ -380,7 +388,7 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){
int UDPBaseImplementation::setShortFrame(int i){ int UDPBaseImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
shortFrame=i; shortFrame=i;
if(shortFrame!=-1){ if(shortFrame!=-1){
@ -410,7 +418,7 @@ int UDPBaseImplementation::setShortFrame(int i){
} }
int UDPBaseImplementation::setNFrameToGui(int i){ int UDPBaseImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(i>=0){ if(i>=0){
nFrameToGui = i; nFrameToGui = i;
setupFifoStructure(); setupFifoStructure();
@ -420,7 +428,7 @@ int UDPBaseImplementation::setNFrameToGui(int i){
int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if(index >= 0){ if(index >= 0){
if(index != acquisitionPeriod){ if(index != acquisitionPeriod){
@ -432,9 +440,9 @@ int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){
} }
bool UDPBaseImplementation::getDataCompression(){return dataCompression;} bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;}
int UDPBaseImplementation::enableDataCompression(bool enable){ int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting";
cout << "Data compression "; cout << "Data compression ";
if(enable) if(enable)
cout << "enabled" << endl; cout << "enabled" << endl;
@ -487,7 +495,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){
/*other functions*/ /*other functions*/
void UDPBaseImplementation::deleteFilter(){ void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
cmSub=NULL; cmSub=NULL;
@ -504,7 +512,7 @@ void UDPBaseImplementation::deleteFilter(){
} }
void UDPBaseImplementation::setupFilter(){ void UDPBaseImplementation::setupFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
double hc = 0; double hc = 0;
double sigma = 5; double sigma = 5;
int sign = 1; int sign = 1;
@ -540,7 +548,7 @@ void UDPBaseImplementation::setupFilter(){
//LEO: it is not clear to me.. //LEO: it is not clear to me..
void UDPBaseImplementation::setupFifoStructure(){ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int64_t i; int64_t i;
int oldn = numJobsPerThread; int oldn = numJobsPerThread;
@ -629,7 +637,7 @@ void UDPBaseImplementation::setupFifoStructure(){
/** acquisition functions */ /** acquisition functions */
void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL)
guiData = latestData; guiData = latestData;
@ -663,7 +671,7 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//random read when gui not ready //random read when gui not ready
if((!nFrameToGui) && (!guiData)){ if((!nFrameToGui) && (!guiData)){
@ -718,9 +726,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char
int UDPBaseImplementation::createUDPSockets(){ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
//if eth is mistaken with ip address //if eth is mistaken with ip address
if (strchr(eth,'.')!=NULL) if (strchr(eth,'.')!=NULL)
@ -764,7 +770,7 @@ int UDPBaseImplementation::createUDPSockets(){
int UDPBaseImplementation::shutDownUDPSockets(){ int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
for(int i=0;i<numListeningThreads;i++){ for(int i=0;i<numListeningThreads;i++){
if(udpSocket[i]){ if(udpSocket[i]){
udpSocket[i]->ShutDownSocket(); udpSocket[i]->ShutDownSocket();
@ -779,7 +785,7 @@ int UDPBaseImplementation::shutDownUDPSockets(){
int UDPBaseImplementation::createListeningThreads(bool destroy){ int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
void* status; void* status;
@ -834,7 +840,7 @@ int UDPBaseImplementation::createListeningThreads(bool destroy){
int UDPBaseImplementation::createWriterThreads(bool destroy){ int UDPBaseImplementation::createWriterThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
void* status; void* status;
@ -895,7 +901,7 @@ int UDPBaseImplementation::createWriterThreads(bool destroy){
void UDPBaseImplementation::setThreadPriorities(){ void UDPBaseImplementation::setThreadPriorities(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
//assign priorities //assign priorities
struct sched_param tcp_param, listen_param, write_param; struct sched_param tcp_param, listen_param, write_param;
@ -932,7 +938,7 @@ void UDPBaseImplementation::setThreadPriorities(){
int UDPBaseImplementation::setupWriter(){ int UDPBaseImplementation::setupWriter(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//reset writing thread variables //reset writing thread variables
packetsInFile=0; packetsInFile=0;
@ -1017,7 +1023,7 @@ int UDPBaseImplementation::setupWriter(){
int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ FILE_LOG(logDEBUG) << __AT__ << " starting";
#ifdef MYROOT1 #ifdef MYROOT1
char temp[MAX_STR_LENGTH]; char temp[MAX_STR_LENGTH];
//create file name for gui purposes, and set up acquistion parameters //create file name for gui purposes, and set up acquistion parameters
@ -1045,7 +1051,7 @@ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){
int UDPBaseImplementation::createNewFile(){ int UDPBaseImplementation::createNewFile(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl;
@ -1168,7 +1174,7 @@ void UDPBaseImplementation::closeFile(int ithr)
int UDPBaseImplementation::startReceiver(char message[]){ int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
@ -1236,7 +1242,7 @@ int UDPBaseImplementation::startReceiver(char message[]){
int UDPBaseImplementation::stopReceiver(){ int UDPBaseImplementation::stopReceiver(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//#ifdef VERBOSE //#ifdef VERBOSE
@ -1266,7 +1272,7 @@ int UDPBaseImplementation::stopReceiver(){
void UDPBaseImplementation::startReadout(){ void UDPBaseImplementation::startReadout(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//#ifdef VERBOSE //#ifdef VERBOSE
cout << "Start Receiver Readout" << endl; cout << "Start Receiver Readout" << endl;
@ -1289,7 +1295,7 @@ void UDPBaseImplementation::startReadout(){
void* UDPBaseImplementation::startListeningThread(void* this_pointer){ void* UDPBaseImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting";
((UDPBaseImplementation*)this_pointer)->startListening(); ((UDPBaseImplementation*)this_pointer)->startListening();
return this_pointer; return this_pointer;
@ -1297,7 +1303,7 @@ void* UDPBaseImplementation::startListeningThread(void* this_pointer){
void* UDPBaseImplementation::startWritingThread(void* this_pointer){ void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting";
((UDPBaseImplementation*)this_pointer)->startWriting(); ((UDPBaseImplementation*)this_pointer)->startWriting();
return this_pointer; return this_pointer;
} }
@ -1307,7 +1313,7 @@ void* UDPBaseImplementation::startWritingThread(void* this_pointer){
int UDPBaseImplementation::startListening(){ int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int ithread = currentListeningThreadIndex; int ithread = currentListeningThreadIndex;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "In startListening() " << endl; cout << "In startListening() " << endl;
@ -1508,7 +1514,7 @@ int UDPBaseImplementation::startListening(){
int UDPBaseImplementation::startWriting(){ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int ithread = currentWriterThreadIndex; int ithread = currentWriterThreadIndex;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << ithread << "In startWriting()" <<endl; cout << ithread << "In startWriting()" <<endl;
@ -1701,7 +1707,7 @@ int loop;
void UDPBaseImplementation::startFrameIndices(int ithread){ void UDPBaseImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " starting";
if (myDetectorType == EIGER) if (myDetectorType == EIGER)
//add currframenum later in this method for scans //add currframenum later in this method for scans
@ -1735,7 +1741,7 @@ void UDPBaseImplementation::startFrameIndices(int ithread){
void UDPBaseImplementation::stopListening(int ithread, int rc, int &pc, int &t){ void UDPBaseImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i; int i;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
@ -1813,7 +1819,7 @@ int i;
void UDPBaseImplementation::stopWriting(int ithread, char* wbuffer[]){ void UDPBaseImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " starting";
int i,j; int i,j;
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl;
@ -1881,6 +1887,10 @@ void UDPBaseImplementation::stopWriting(int ithread, char* wbuffer[]){
void UDPBaseImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){ void UDPBaseImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
int packetsToSave, offset,lastpacket; int packetsToSave, offset,lastpacket;
uint32_t tempframenum = framenum; uint32_t tempframenum = framenum;
@ -1983,6 +1993,8 @@ void UDPBaseImplementation::writeToFile_withoutCompression(char* buf,int numpack
void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
#if defined(MYROOT1) && defined(ALLFILE_DEBUG) #if defined(MYROOT1) && defined(ALLFILE_DEBUG)
writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); writeToFile_withoutCompression(wbuf[0], numpackets,currframenum);
@ -2082,6 +2094,8 @@ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[],
int UDPBaseImplementation::enableTenGiga(int enable){ int UDPBaseImplementation::enableTenGiga(int enable){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
cout << "Enabling 10Gbe to" << enable << endl; cout << "Enabling 10Gbe to" << enable << endl;

View File

@ -73,6 +73,17 @@ void UDPRESTImplementation::configure(map<string, string> config_map){
}; };
int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state){
JsonBox::Value answer;
//string rest_state = "";
int code = rest->get_json("state", &answer);
if ( code != -1 ){
(*rest_state) = answer["state"].getString();
}
return code;
};
void UDPRESTImplementation::initialize_REST(){ void UDPRESTImplementation::initialize_REST(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
@ -91,7 +102,7 @@ void UDPRESTImplementation::initialize_REST(){
int code; int code;
try{ try{
rest->init(rest_hostname, rest_port); rest->init(rest_hostname, rest_port);
code = rest->get_json("state", &answer); code = get_rest_state(rest, &answer);
if (code != 0){ if (code != 0){
throw answer; throw answer;
@ -115,7 +126,7 @@ void UDPRESTImplementation::initialize_REST(){
stringstream ss; stringstream ss;
string test; string test;
std::cout << "GetSTring: " << json_request << std::endl; //std::cout << "GetSTring: " << json_request << std::endl;
json_request.writeToStream(ss, false); json_request.writeToStream(ss, false);
//ss << json_request; //ss << json_request;
ss >> test; ss >> test;
@ -125,7 +136,7 @@ void UDPRESTImplementation::initialize_REST(){
code = rest->post_json("state/initialize", &answer, test); code = rest->post_json("state/initialize", &answer, test);
FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code;
code = rest->get_json("state", &answer); code = rest->get_json("state", &answer);
FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer << "\n";
/* /*
@ -692,32 +703,28 @@ int UDPRESTImplementation::shutDownUDPSockets(){
FILE_LOG(logDEBUG) << __AT__ << "called"; FILE_LOG(logDEBUG) << __AT__ << "called";
std::string answer; JsonBox::Value answer;
int code = rest->get_json("state", &answer); int code;
std::cout << answer << std::endl; string be_state = "";
code = rest->post_json("state/close", &answer); // LEO: this is probably wrong
std::cout << answer << std::endl; if (be_state == "OPEN"){
code = rest->post_json("state/reset", &answer); while (be_state != "TRANSIENT"){
std::cout << answer << std::endl; code = rest->get_json("state", &answer);
be_state = answer["state"].getString();
code = rest->get_json("state", &answer); cout << be_state << endl;
std::cout << answer << std::endl; usleep(10000);
status = slsReceiverDefs::RUN_FINISHED;
/*
for(int i=0;i<numListeningThreads;i++){
if(udpSocket[i]){
FILE_LOG(logDEBUG) << __AT__ << " UDP socket " << i;
udpSocket[i]->ShutDownSocket();
delete udpSocket[i];
udpSocket[i] = NULL;
} }
} }
*/ code = rest->post_json("state/close", &answer);
std::cout <<code << " " << answer << std::endl;
code = rest->post_json("state/reset", &answer);
std::cout << code << " " << answer << std::endl;
code = rest->get_json("state", &answer);
std::cout << code << " " << answer << std::endl;
status = slsReceiverDefs::RUN_FINISHED;
FILE_LOG(logDEBUG) << __AT__ << "finished"; FILE_LOG(logDEBUG) << __AT__ << "finished";
@ -1131,17 +1138,14 @@ int UDPRESTImplementation::startReceiver(char message[]){
std::string answer; std::string answer;
int code; int code;
// TODO: remove hardcode!!!
//test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}"; std::string request_body = "{\"settings\": {\"bit_depth\": 16, \"nimages\": 1}}"; //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}";
code = rest->post_json("state/configure", &answer); FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body;
std::cout << answer << std::endl; code = rest->post_json("state/configure", &answer, request_body);
code = rest->get_json("state", &answer); code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
code = rest->post_json("state/open", &answer); code = rest->post_json("state/open", &answer);
std::cout << answer << std::endl;
code = rest->get_json("state", &answer); code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
status = slsReceiverDefs::RUNNING; status = slsReceiverDefs::RUNNING;
@ -1234,17 +1238,21 @@ int UDPRESTImplementation::stopReceiver(){
void UDPRESTImplementation::startReadout(){ void UDPRESTImplementation::startReadout(){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << " starting";
//wait so that all packets which take time has arrived //wait so that all packets which take time has arrived
usleep(50000); usleep(50000);
status = TRANSMITTING;
/********************************************/ /********************************************/
/*
usleep(2000000); usleep(2000000);
pthread_mutex_lock(&status_mutex); pthread_mutex_lock(&status_mutex);
status = TRANSMITTING; status = TRANSMITTING;
pthread_mutex_unlock(&status_mutex); pthread_mutex_unlock(&status_mutex);
cout << "Status: Transmitting" << endl; cout << "Status: Transmitting" << endl;
*/
//kill udp socket to tell the listening thread to push last packet //kill udp socket to tell the listening thread to push last packet
shutDownUDPSockets(); shutDownUDPSockets();