From f517eb7a41d7f57aa594e0201365a6cf9f8e278a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 16 Sep 2016 17:19:37 +0200 Subject: [PATCH] included json example with dummy values --- slsDetectorSoftware/CMakeLists.txt | 6 +++ .../multiSlsDetector/multiSlsDetector.cpp | 47 +++++++++++++++---- .../slsDetector/slsDetectorUtils.cpp | 2 +- .../slsDetectorClient/CMakeLists.txt | 8 ++++ 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 5263ea204..69f395cc9 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -39,6 +39,12 @@ add_definitions( -DDACS_INT ) +add_library(zmq STATIC IMPORTED ) + +set_target_properties(zmq PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../slsReceiverSoftware/include/libzmq.a +) + add_library(slsDetectorStatic STATIC ${SOURCES} ${HEADERS} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 21b50a023..5d613e080 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -24,6 +24,7 @@ ID: $Id$ #include #include #include +#include //to scan json header in zmq stream using namespace std; @@ -5012,16 +5013,44 @@ void multiSlsDetector::startReceivingData(){ if(!idet) framecount++; //update indices, count only once - // receive a message, this is a blocking function - len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/ - if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,ithread); continue; } //error + + //scan header-------------------------------------------------------- + zmq_msg_init (&message); + len = zmq_msg_recv(&message, zmqsocket, 0); + if (len == -1) { + zmq_msg_close(&message); + cprintf(RED, "%d message null\n",ithread); + continue; + } + rapidjson::Document d; + d.Parse((char*)zmq_msg_data(&message)); + // htype is an array of strings + rapidjson::Value::Array htype = d["htype"].GetArray(); + for(int i=0; i< htype.Size(); i++) + cout << ithread << "htype: " << htype[i].GetString() << endl;/*print*/ + // shape is an array of ints + rapidjson::Value::Array shape = d["shape"].GetArray(); + cout << ithread << "shape: "; /*print*/ + for(int i=0; i< shape.Size(); i++) + cout << ithread << shape[i].GetInt() << " ";/*print*/ + cout << endl; + + cout << ithread << "type: " << d["type"].GetString() << endl;/*print*/ + // close the message + zmq_msg_close(&message); + + + //scan data-------------------------------------------------------- + zmq_msg_init (&message); len = zmq_msg_recv(&message, zmqsocket, 0); - //if(len<1024*256) - //cprintf(RED,"got less than planned for socket %d\n",ithread); + //last one + if(len<1024*256){ + cprintf(RED,"got less than planned for socket %d\n",ithread); //end of socket - if (len <= 3 ) { + //if (len <= 3 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); + zmq_msg_close(&message); //cout<