mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 17:47:59 +02:00
added log printouts. Added hardcoded REST configuration
This commit is contained in:
@ -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(){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " called";
|
||||
@ -91,7 +102,7 @@ void UDPRESTImplementation::initialize_REST(){
|
||||
int code;
|
||||
try{
|
||||
rest->init(rest_hostname, rest_port);
|
||||
code = rest->get_json("state", &answer);
|
||||
code = get_rest_state(rest, &answer);
|
||||
|
||||
if (code != 0){
|
||||
throw answer;
|
||||
@ -115,7 +126,7 @@ void UDPRESTImplementation::initialize_REST(){
|
||||
|
||||
stringstream ss;
|
||||
string test;
|
||||
std::cout << "GetSTring: " << json_request << std::endl;
|
||||
//std::cout << "GetSTring: " << json_request << std::endl;
|
||||
json_request.writeToStream(ss, false);
|
||||
//ss << json_request;
|
||||
ss >> test;
|
||||
@ -125,7 +136,7 @@ void UDPRESTImplementation::initialize_REST(){
|
||||
code = rest->post_json("state/initialize", &answer, test);
|
||||
FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code;
|
||||
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";
|
||||
|
||||
std::string answer;
|
||||
int code = rest->get_json("state", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
JsonBox::Value answer;
|
||||
int code;
|
||||
string be_state = "";
|
||||
|
||||
code = rest->post_json("state/close", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
code = rest->post_json("state/reset", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
code = rest->get_json("state", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
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;
|
||||
// LEO: this is probably wrong
|
||||
if (be_state == "OPEN"){
|
||||
while (be_state != "TRANSIENT"){
|
||||
code = rest->get_json("state", &answer);
|
||||
be_state = answer["state"].getString();
|
||||
cout << be_state << endl;
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
*/
|
||||
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";
|
||||
|
||||
@ -1131,17 +1138,14 @@ int UDPRESTImplementation::startReceiver(char message[]){
|
||||
std::string answer;
|
||||
int code;
|
||||
|
||||
|
||||
//test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}";
|
||||
code = rest->post_json("state/configure", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
// TODO: remove hardcode!!!
|
||||
std::string request_body = "{\"settings\": {\"bit_depth\": 16, \"nimages\": 1}}"; //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}";
|
||||
FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body;
|
||||
code = rest->post_json("state/configure", &answer, request_body);
|
||||
code = rest->get_json("state", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
code = rest->post_json("state/open", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
code = rest->get_json("state", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
status = slsReceiverDefs::RUNNING;
|
||||
|
||||
@ -1234,17 +1238,21 @@ int UDPRESTImplementation::stopReceiver(){
|
||||
|
||||
|
||||
void UDPRESTImplementation::startReadout(){
|
||||
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
//wait so that all packets which take time has arrived
|
||||
usleep(50000);
|
||||
|
||||
status = TRANSMITTING;
|
||||
|
||||
/********************************************/
|
||||
/*
|
||||
usleep(2000000);
|
||||
pthread_mutex_lock(&status_mutex);
|
||||
status = TRANSMITTING;
|
||||
pthread_mutex_unlock(&status_mutex);
|
||||
cout << "Status: Transmitting" << endl;
|
||||
*/
|
||||
|
||||
//kill udp socket to tell the listening thread to push last packet
|
||||
shutDownUDPSockets();
|
||||
|
Reference in New Issue
Block a user