zmq fixed to have additional json headers using rx_zmqjsonheader

This commit is contained in:
2018-04-09 16:33:14 +02:00
parent ccdc7d22e9
commit 2bd8e6c166
14 changed files with 195 additions and 10 deletions

View File

@ -196,7 +196,8 @@ enum networkParameter {
RECEIVER_STREAMING_PORT, /**< receiever streaming TCP(ZMQ) port */
CLIENT_STREAMING_PORT, /**< client streaming TCP(ZMQ) port */
RECEIVER_STREAMING_SRC_IP,/**< receiever streaming TCP(ZMQ) ip */
CLIENT_STREAMING_SRC_IP /**< client streaming TCP(ZMQ) ip */
CLIENT_STREAMING_SRC_IP, /**< client streaming TCP(ZMQ) ip */
ADDITIONAL_JSON_HEADER /**< additional json header (ZMQ) */
};
/**

View File

@ -563,6 +563,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
memset(thisDetector->zmqip,0,MAX_STR_LENGTH);
/** set zmq tcp src ip address in receiver*/
memset(thisDetector->receiver_zmqip,0,MAX_STR_LENGTH);
/** set additional json header in receiver*/
memset(thisDetector->receiver_additionalJsonHeader,0,MAX_STR_LENGTH);
/** sets onlineFlag to OFFLINE_FLAG */
@ -6214,6 +6216,9 @@ string slsDetector::setNetworkParameter(networkParameter index, string value) {
return setClientStreamingIP(value);
case RECEIVER_STREAMING_SRC_IP:
return setReceiverStreamingIP(value);
case ADDITIONAL_JSON_HEADER:
return setAdditionalJsonHeader(value);
default:
return (char*)("unknown network parameter");
}
@ -6252,6 +6257,8 @@ string slsDetector::getNetworkParameter(networkParameter index) {
return getClientStreamingIP();
case RECEIVER_STREAMING_SRC_IP:
return getReceiverStreamingIP();
case ADDITIONAL_JSON_HEADER:
return getAdditionalJsonHeader();
default:
return (char*)("unknown network parameter");
}
@ -6352,6 +6359,7 @@ string slsDetector::setReceiver(string receiverIP){
std::cout << "flippeddatax:" << thisDetector->flippedData[d] << endl;
std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl;
std::cout << "rx streaming source ip:" << thisDetector->receiver_zmqip << endl;
std::cout << "rx additional json header:" << thisDetector->receiver_additionalJsonHeader << endl;
std::cout << "enable gap pixels:" << thisDetector->gappixels << endl;
std::cout << "rx streaming port:" << thisDetector->receiver_zmqport << endl;
std::cout << "r_readfreq:" << thisDetector->receiver_read_freq << endl << endl;
@ -6399,6 +6407,7 @@ string slsDetector::setReceiver(string receiverIP){
setReadReceiverFrequency(thisDetector->receiver_read_freq);
setReceiverStreamingPort(getReceiverStreamingPort());
setReceiverStreamingIP(getReceiverStreamingIP());
setAdditionalJsonHeader(getAdditionalJsonHeader());
enableDataStreamingFromReceiver(enableDataStreamingFromReceiver(-1));
}
}
@ -6644,6 +6653,39 @@ string slsDetector::setReceiverStreamingIP(string sourceIP) {
string slsDetector::setAdditionalJsonHeader(string jsonheader) {
int fnum=F_ADDITIONAL_JSON_HEADER;
int ret = FAIL;
char arg[MAX_STR_LENGTH];
memset(arg,0,sizeof(arg));
char retval[MAX_STR_LENGTH];
memset(retval,0, sizeof(retval));
strcpy(arg, jsonheader.c_str());
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending additional json header " << arg << std::endl;
#endif
if (connectData() == OK){
ret=thisReceiver->sendString(fnum,retval,arg);
disconnectData();
}
if(ret==FAIL) {
setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER));
std::cout << "Warning: Could not set additional json header" << std::endl;
} else
strcpy(thisDetector->receiver_additionalJsonHeader, retval);
if(ret==FORCE_UPDATE)
updateReceiver();
}
return getAdditionalJsonHeader();
}
string slsDetector::setDetectorNetworkParameter(networkParameter index, int delay){
int fnum = F_SET_NETWORK_PARAMETER;
int ret = FAIL;
@ -8819,6 +8861,10 @@ int slsDetector::updateReceiverNoWait() {
n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
strcpy(thisDetector->receiver_zmqip, path);
// additional json header
n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
strcpy(thisDetector->receiver_additionalJsonHeader, path);
// gap pixels
n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind));
thisDetector->gappixels = ind;

View File

@ -285,6 +285,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int nGappixels[2];
/** data bytes including gap pixels */
int dataBytesInclGapPixels;
/** additional json header */
char receiver_additionalJsonHeader[MAX_STR_LENGTH];
@ -1824,6 +1826,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
string getClientStreamingIP(){return string(thisDetector->zmqip);};
/** gets the zmq source ip in receiver, returns "none" if default setting and no custom ip set*/
string getReceiverStreamingIP(){return string(thisDetector->receiver_zmqip);};
/** gets the additional json header, returns "none" if default setting and no custom set*/
string getAdditionalJsonHeader(){return string(thisDetector->receiver_additionalJsonHeader);};
/** validates the format of detector MAC address and sets it \sa sharedSlsDetector */
string setDetectorMAC(string detectorMAC);
@ -1847,6 +1851,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
string setClientStreamingIP(string sourceIP);
/** sets the zmq source ip in receiver. if empty, uses rx_hostname*/
string setReceiverStreamingIP(string sourceIP);
/** additional json header, returns "none" if default setting and no custom set */
string setAdditionalJsonHeader(string jsonheader);
/** sets the transmission delay for left or right port or for an entire frame*/
string setDetectorNetworkParameter(networkParameter index, int delay);

View File

@ -2034,6 +2034,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>rx_jsonaddheader [t]</b> sets/gets additional json header to be streamed out with the zmq from receiver. Default is empty. \c t must be in the format "\"label1\":\"value1\",\"label2\":\"value2\"" etc. Use only if it needs to be processed by an intermediate process. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName="rx_jsonaddheader"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>configuremac [i]</b> configures the MAC of the detector with these parameters: detectorip, detectormac, rx_udpip, rx_udpmac, rx_udpport, rx_udpport2 (if applicable). This command is already included in \c rx_hsotname. Only put!. \c Returns \c (int)
*/
@ -4089,6 +4096,8 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
// if streaming, switch it off
prev_streaming = myDet->enableDataStreamingFromReceiver();
if (prev_streaming) myDet->enableDataStreamingFromReceiver(0);
} else if (cmd=="rx_jsonaddheader") {
t=ADDITIONAL_JSON_HEADER;
}
else return ("unknown network parameter")+cmd;
@ -4132,6 +4141,9 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
os << "rx_zmqip ip \n sets/gets the 0MQ (TCP) ip of the receiver from where data is streamed from (eg. to GUI or another process for further processing). "
"Default is ip of rx_hostname and works for GUI. This is usually used to stream out to an external process for further processing."
"restarts streaming in receiver with new port" << std::endl;
os << "rx_jsonaddheader [t]\n sets additional json header to be streamed "
"out with the zmq from receiver. Default is empty. \c t must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc."
"Use only if it needs to be processed by an intermediate process." << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "detectormac \n gets detector mac "<< std::endl;
@ -4148,6 +4160,8 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
os << "rx_zmqport \n gets the 0MQ (TCP) port of the receiver from where data is streamed from"<< std::endl;
os << "zmqip \n gets the 0MQ (TCP) ip of the client to where final data is streamed to.If no custom ip, empty until first time connect to receiver" << std::endl;
os << "rx_zmqip \n gets/gets the 0MQ (TCP) ip of the receiver from where data is streamed from. If no custom ip, empty until first time connect to receiver" << std::endl;
os << "rx_jsonaddheader \n gets additional json header to be streamed "
"out with the zmq from receiver." << std::endl;
}
return os.str();