USRP_Server  2.0
A flexible, GPU-accelerated radio-frequency readout software.
usrp_server.cpp
Go to the documentation of this file.
7 #include "USRP_demodulator.hpp"
10 #include "USRP_file_writer.hpp"
11 #include "USRP_server_network.hpp"
12 
13 #include "kernels.cuh"
14 #include <boost/program_options.hpp>
15 
16 namespace po = boost::program_options;
17 
18 
19 int main(int argc, char **argv){
20  uhd::set_thread_priority_safe(1.);
21  init_logger();
22  set_this_thread_name("Main");
23  logging::add_common_attributes();
24  std::cout << "\033[40;1;32mUSRP GPU Server v 2.0\033[0m" << std::endl;
25  BOOST_LOG_TRIVIAL(debug) << "Server started";
26  bool file_write, net_streaming, sw_loop;
27  std::string clock;
28  int port_async,port_sync;
29 
30  bool active = true;
31  bool uhd_dbg = false;
32  std::string* json_res;
33 
34  po::options_description desc("Allowed options");
35  desc.add_options()
36  ("help", "help message")
37 
38 
39  ("fw", po::value<bool>(&file_write)->default_value(false)->implicit_value(true), "Enable local file writing")
40  ("no_net", po::value<bool>(&net_streaming)->default_value(true)->implicit_value(false), "Disable network streaming")
41  ("sw_loop", po::value<bool>(&sw_loop)->default_value(false)->implicit_value(true), "Bypass USRP interaction")
42  ("clock", po::value<std::string>(&clock)->default_value("internal")->implicit_value("external"), "Clock selector")
43  ("async", po::value<int>(&port_async)->default_value(22001), "Define ascynchronous TCP communication port")
44  ("data", po::value<int>(&port_sync)->default_value(61360), "Define scynchronous TCP data streaming port")
45  ("uhd_dbg", po::value<bool>(&uhd_dbg)->default_value(false), "Enable UHD degug logging on console.")
46  ("args", po::value<std::string>(&device_arguments)->default_value("noarg"), "Device argument to pass (experimental use)")
47  ;
48  po::variables_map vm;
49  po::store(po::parse_command_line(argc, argv, desc), vm);
50  po::notify(vm);
51 
52  if (vm.count("help")){
53  std::cout << "USRP GPU server version 2.0. Consult online documentation on how to use this server." << std::endl;
54  return ~0;
55  }
56 
57  if(uhd_dbg)uhd::log::set_console_level(uhd::log::severity_level::trace);
58  server_settings settings;
59  settings.autoset();
60  settings.TCP_streaming = net_streaming;
61  settings.FILE_writing = file_write;
62 
63  //look for USRP
64  hardware_manager usrp(&settings,sw_loop);
65 
66  //look for CUDA, initialize memory (last arg is debug)
67  //blocks until tcp data connection is on-line if TCP streamer is enabled
68  TXRX thread_manager(&settings, &usrp, false);
69 
70  //look for USER
71  Async_server async(true);
72 
73 
74 
75  while(active){
76  BOOST_LOG_TRIVIAL(info) << "Main loop";
77  std::this_thread::sleep_for(std::chrono::milliseconds(50));
78  if(async.connected()){
79  usrp_param global_parameters;
80  bool res = async.recv_async(global_parameters);//add here the action code as argument
81  res = chk_param(&global_parameters);
82  BOOST_LOG_TRIVIAL(info) << "Sending response to client application";
83  json_res = new std::string(res?server_ack("Message received"):server_nack("Cannot convert JSON to params"));
84  async.send_async(json_res);
85  if(res){
86  BOOST_LOG_TRIVIAL(info) << "Implementing parameter configuration";
87  print_params(global_parameters);
88  thread_manager.set(&global_parameters);
89  thread_manager.start(&global_parameters);
90  bool done = false;
91  std::cout<< "DAq in progress:" <<std::flush;
92  while(not done){
93  done = thread_manager.stop();
94  if(not done){
95  std::cout<<"."<<std::flush;
96  }else{
97  std::cout<<"*Measure complete"<<std::endl;
98  }
99  boost::this_thread::sleep_for(boost::chrono::milliseconds{500});
100  //if (async.chk_new_command())done = thread_manager.stop(true); //this is not working
101  }
102  json_res = new std::string(server_ack("EOM: end of measurement"));
103  BOOST_LOG_TRIVIAL(info) << "Measure ended";
104  async.send_async(json_res);
105  }else{
106  BOOST_LOG_TRIVIAL(warning) << "Parameter in the received message cannot be implemented";
107  }
108  }
109  }
110 
111  return 0;
112 
113 
114 }
std::string device_arguments
void start(usrp_param *global_param)
Start the threads.
void set(usrp_param *global_param)
Launches the setting functions for the required signals, antennas...
std::string server_ack(std::string payload)
bool chk_param(usrp_param *parameter)
std::string server_nack(std::string payload)
void set_this_thread_name(std::string thread_name)
Set the htread name reported in the logging.
void print_params(usrp_param my_parameter)
Print parameters on the terminal in a readable way.
bool recv_async(usrp_param &my_parameter, bool blocking=true)
bool stop(bool force=false)
int main(int argc, char **argv)
Definition: usrp_server.cpp:19
Manages the hardware I/O of one usrp unit.
void init_logger()
initialize the logger for the server. Creates or access the folder logs. each time the server starts...
void send_async(std::string *message)