mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 03:25:13 +01:00
zmq fixed to have additional json headers using rx_zmqjsonheader
This commit is contained in:
@@ -25,8 +25,9 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param sEnable pointer to short frame enable
|
||||
* @param fi pointer to file index
|
||||
* @param fd flipped data enable for x and y dimensions
|
||||
* @param ajh additional json header
|
||||
*/
|
||||
DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd);
|
||||
DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@@ -233,5 +234,8 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
|
||||
/** flipped data across both dimensions enable */
|
||||
int* flippedData;
|
||||
|
||||
/** additional json header */
|
||||
char* additionJsonHeader;
|
||||
};
|
||||
|
||||
|
||||
@@ -271,6 +271,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
char *getStreamingSourceIP() const;
|
||||
|
||||
/**
|
||||
* Get additional json header
|
||||
* @return additional json header
|
||||
*/
|
||||
char *getAdditionalJsonHeader() const;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Setters ***************************************************************
|
||||
@@ -555,6 +561,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
void setStreamingSourceIP(const char* c);
|
||||
|
||||
/**
|
||||
* Set additional json header
|
||||
*/
|
||||
void setAdditionalJsonHeader(const char* c);
|
||||
|
||||
/*
|
||||
* Restream stop dummy packet from receiver
|
||||
* @return OK or FAIL
|
||||
@@ -712,6 +723,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
uint32_t streamingPort;
|
||||
/** streaming port */
|
||||
char streamingSrcIP[MAX_STR_LENGTH];
|
||||
/** additional json header */
|
||||
char additionalJsonHeader[MAX_STR_LENGTH];
|
||||
|
||||
//***receiver parameters***
|
||||
uint32_t silentMode;
|
||||
|
||||
@@ -51,6 +51,7 @@ class UDPInterface {
|
||||
* -setGapPixelsEnable
|
||||
* -setStreamingPort
|
||||
* -setStreamingSourceIP
|
||||
* -setAdditionalJsonHeader
|
||||
* -setDataStreamEnable
|
||||
*
|
||||
*
|
||||
@@ -357,6 +358,12 @@ class UDPInterface {
|
||||
*/
|
||||
virtual char *getStreamingSourceIP() const = 0;
|
||||
|
||||
/**
|
||||
* Get additional json header
|
||||
* @return additional json header
|
||||
*/
|
||||
virtual char *getAdditionalJsonHeader() const = 0;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Setters ***************************************************************
|
||||
@@ -643,6 +650,11 @@ class UDPInterface {
|
||||
*/
|
||||
virtual void setStreamingSourceIP(const char* c) = 0;
|
||||
|
||||
/**
|
||||
* Set additional json header
|
||||
*/
|
||||
virtual void setAdditionalJsonHeader(const char* c) = 0;
|
||||
|
||||
/*
|
||||
* Restream stop dummy packet from receiver
|
||||
* @return OK or FAIL
|
||||
|
||||
@@ -276,7 +276,8 @@ public:
|
||||
uint64_t bunchId = 0, uint64_t timestamp = 0,
|
||||
uint16_t modId = 0, uint16_t xCoord = 0, uint16_t yCoord = 0, uint16_t zCoord = 0,
|
||||
uint32_t debug = 0, uint16_t roundRNumber = 0,
|
||||
uint8_t detType = 0, uint8_t version = 0, int* flippedData = 0) {
|
||||
uint8_t detType = 0, uint8_t version = 0, int* flippedData = 0,
|
||||
char* additionalJsonHeader = 0) {
|
||||
|
||||
|
||||
char buf[MAX_STR_LENGTH] = "";
|
||||
@@ -310,7 +311,7 @@ public:
|
||||
//additional stuff
|
||||
"\"flippedDataX\":%u"
|
||||
|
||||
"}\n\0";
|
||||
;//"}\n\0";
|
||||
int length = sprintf(buf, jsonHeaderFormat,
|
||||
jsonversion, dynamicrange, fileIndex, npixelsx, npixelsy, imageSize,
|
||||
acqIndex, fIndex, (fname == NULL)? "":fname, dummy?0:1,
|
||||
@@ -322,9 +323,15 @@ public:
|
||||
//additional stuff
|
||||
((flippedData == 0 ) ? 0 :flippedData[0])
|
||||
);
|
||||
if (additionalJsonHeader && strlen(additionalJsonHeader)) {
|
||||
length = sprintf(buf, "%s, %s}\n%c", buf, additionalJsonHeader, '\0');
|
||||
} else {
|
||||
length = sprintf(buf, "%s}\n%c", buf, '\0');
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
//if(!index)
|
||||
FILE_LOG(logINFO) << index << ": Streamer: buf:" << buf;
|
||||
cprintf(BLUE,"%d : STreamer: buf: %s\n", index, buf);
|
||||
#endif
|
||||
|
||||
if(zmq_send (socketDescriptor, buf, length, dummy?0:ZMQ_SNDMORE) < 0) {
|
||||
|
||||
@@ -297,6 +297,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
|
||||
/** restream stop packet */
|
||||
int restream_stop();
|
||||
|
||||
/** set additional json header */
|
||||
int set_additional_json_header();
|
||||
|
||||
|
||||
|
||||
/** detector type */
|
||||
|
||||
@@ -63,6 +63,8 @@ enum recFuncs{
|
||||
F_SET_RECEIVER_SILENT_MODE, /** < sets the receiver silent mode */
|
||||
F_ENABLE_GAPPIXELS_IN_RECEIVER, /** < sets gap pixels in the receiver */
|
||||
F_RESTREAM_STOP_FROM_RECEIVER, /** < restream stop from receiver */
|
||||
F_ADDITIONAL_JSON_HEADER, /** < additional json header */
|
||||
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
bool DataStreamer::SilentMode(false);
|
||||
|
||||
|
||||
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd) :
|
||||
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh) :
|
||||
ThreadObject(NumberofDataStreamers),
|
||||
generalData(0),
|
||||
fifo(f),
|
||||
@@ -39,7 +39,8 @@ DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, i
|
||||
firstAcquisitionIndex(0),
|
||||
firstMeasurementIndex(0),
|
||||
completeBuffer(0),
|
||||
flippedData(fd)
|
||||
flippedData(fd),
|
||||
additionJsonHeader(ajh)
|
||||
{
|
||||
if(ThreadObject::CreateThread()){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
@@ -287,8 +288,9 @@ int DataStreamer::SendHeader(sls_detector_header* header, uint32_t size, uint32_
|
||||
header->modId, header->xCoord, header->yCoord, header->zCoord,
|
||||
header->debug, header->roundRNumber,
|
||||
header->detType, header->version,
|
||||
flippedData
|
||||
);
|
||||
flippedData,
|
||||
additionJsonHeader
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
dataStreamEnable = false;
|
||||
streamingPort = 0;
|
||||
memset(streamingSrcIP, 0, sizeof(streamingSrcIP));
|
||||
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
|
||||
|
||||
//***receiver parameters***
|
||||
silentMode = 0;
|
||||
@@ -232,6 +233,16 @@ char *UDPBaseImplementation::getStreamingSourceIP() const{
|
||||
return output;
|
||||
}
|
||||
|
||||
char *UDPBaseImplementation::getAdditionalJsonHeader() const{
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
char* output = new char[MAX_STR_LENGTH]();
|
||||
memset(output, 0, MAX_STR_LENGTH);
|
||||
strcpy(output,additionalJsonHeader);
|
||||
//freed by calling function
|
||||
return output;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Setters ***************************************************************
|
||||
* They modify the local cache of configuration or detector parameters ***
|
||||
@@ -597,6 +608,11 @@ void UDPBaseImplementation::setStreamingSourceIP(const char c[]){
|
||||
FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
|
||||
}
|
||||
|
||||
void UDPBaseImplementation::setAdditionalJsonHeader(const char c[]){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
strcpy(additionalJsonHeader, c);
|
||||
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
|
||||
}
|
||||
|
||||
int UDPBaseImplementation::restreamStop() {
|
||||
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
|
||||
|
||||
@@ -218,7 +218,7 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
|
||||
if (enable) {
|
||||
bool error = false;
|
||||
for ( int i = 0; i < numThreads; ++i ) {
|
||||
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &shortFrameEnable, &fileIndex, flippedData));
|
||||
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &shortFrameEnable, &fileIndex, flippedData, additionalJsonHeader));
|
||||
dataStreamer[i]->SetGeneralData(generalData);
|
||||
if (dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP) == FAIL) {
|
||||
error = true;
|
||||
|
||||
@@ -293,6 +293,7 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
|
||||
case F_RECEIVER_STREAMING_SRC_IP: return "F_RECEIVER_STREAMING_SRC_IP";
|
||||
case F_ENABLE_GAPPIXELS_IN_RECEIVER:return "F_ENABLE_GAPPIXELS_IN_RECEIVER";
|
||||
case F_RESTREAM_STOP_FROM_RECEIVER: return "F_RESTREAM_STOP_FROM_RECEIVER";
|
||||
case F_ADDITIONAL_JSON_HEADER: return "F_ADDITIONAL_JSON_HEADER";
|
||||
default: return "Unknown Function";
|
||||
}
|
||||
}
|
||||
@@ -341,6 +342,7 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
flist[F_RECEIVER_STREAMING_SRC_IP] = &slsReceiverTCPIPInterface::set_streaming_source_ip;
|
||||
flist[F_ENABLE_GAPPIXELS_IN_RECEIVER] = &slsReceiverTCPIPInterface::enable_gap_pixels;
|
||||
flist[F_RESTREAM_STOP_FROM_RECEIVER] = &slsReceiverTCPIPInterface::restream_stop;
|
||||
flist[F_ADDITIONAL_JSON_HEADER] = &slsReceiverTCPIPInterface::set_additional_json_header;
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) {
|
||||
@@ -716,6 +718,14 @@ int slsReceiverTCPIPInterface::send_update() {
|
||||
if (path != NULL)
|
||||
delete[] path;
|
||||
|
||||
// additional json header
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
path = receiverBase->getAdditionalJsonHeader();
|
||||
#endif
|
||||
mySock->SendDataOnly(path,MAX_STR_LENGTH);
|
||||
if (path != NULL)
|
||||
delete[] path;
|
||||
|
||||
// gap pixels enable
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
ind = (int)receiverBase->getGapPixelsEnable();
|
||||
@@ -2549,3 +2559,52 @@ int slsReceiverTCPIPInterface::restream_stop(){
|
||||
// return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_additional_json_header() {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg, 0, sizeof(arg));
|
||||
char* retval=NULL;
|
||||
|
||||
// receive arguments
|
||||
if (mySock->ReceiveDataOnly(arg,MAX_STR_LENGTH) < 0 )
|
||||
return printSocketReadError();
|
||||
|
||||
// execute action
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (receiverBase == NULL)
|
||||
invalidReceiverObject();
|
||||
else {
|
||||
// set
|
||||
if (mySock->differentClients && lockStatus)
|
||||
receiverlocked();
|
||||
else if (receiverBase->getStatus() != IDLE)
|
||||
receiverNotIdle();
|
||||
else {
|
||||
receiverBase->setAdditionalJsonHeader(arg);
|
||||
}
|
||||
|
||||
//get
|
||||
retval = receiverBase->getAdditionalJsonHeader();
|
||||
}
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
FILE_LOG(logDEBUG1) << "additional json header:" << retval;
|
||||
#endif
|
||||
|
||||
if (ret == OK && mySock->differentClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL)
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
mySock->SendDataOnly(retval,MAX_STR_LENGTH);
|
||||
delete[] retval;
|
||||
|
||||
// return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user