6 boost::log::core::get()->add_thread_attribute(
"ThreadName",
7 boost::log::attributes::constant< std::string >(thread_name));
9 pthread_setname_np(pthread_self(), thread_name.c_str());
18 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_NONE:
19 print_warning(
"RX error: Interpreter called on a error free packet.");
21 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_TIMEOUT:
22 print_warning(
"RX error: No packet received, implementation timed-out.");
24 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_LATE_COMMAND:
25 print_warning(
"RX error: A stream command was issued in the past.");
27 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_BROKEN_CHAIN:
30 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_OVERFLOW:
31 print_warning(
"RX error: An internal receive buffer has filled or a sequence error has been detected (see next warning).");
33 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_ALIGNMENT:
36 case uhd::rx_metadata_t::error_code_t::ERROR_CODE_BAD_PACKET:
50 if(metadata->error_code != uhd::rx_metadata_t::error_code_t::ERROR_CODE_NONE){
54 if(metadata->out_of_sequence)
print_warning(
"RX error: was a sequence error.");
58 if(metadata->more_fragments)
print_error(
"RX buffer mismatch!");
65 switch(async_md->event_code){
71 case uhd::async_metadata_t::EVENT_CODE_TIME_ERROR:
72 if(verbose)
print_warning(
"TX thread encountered a time error");
76 case uhd::async_metadata_t::EVENT_CODE_BURST_ACK:
79 case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW:
80 if(verbose)
print_warning(
"TX thread encountered an undeflow");
83 case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR:
84 if(verbose)
print_warning(
"TX thread encountered a sequence error");
87 case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET:
88 if(verbose)
print_warning(
"TX thread encountered an undeflow in packet");
91 case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST:
92 if(verbose)
print_warning(
"TX thread encountered a sequence error in burst");
98 ss << boost::format(
"TX thread got unexpected event code 0x%x.\n") % async_md->event_code << std::endl;
115 std::stringstream ss;
116 boost::format position_formatting(
"%=1.1e");
118 ss <<
"\033[40;1;37m A N A L O G P A R A M E T E R S \033[0m"<<std::endl;
119 ss <<
"------------------------------------------------------------------------"<<std::endl;
120 ss <<
" device on-server ID: "<< my_parameter.usrp_number <<
" "<<std::endl;
121 ss <<
"------------------------------------------------------------------------"<<std::endl;
122 ss <<
" board-> \033[40;1;37m RF A \033[0m";
123 ss <<
" \033[40;1;37m RF B \033[0m"<<std::endl<<std::endl;
124 ss <<
" ant-> " <<
"\033[40;1;32m TX/RX \033[0m ";
125 ss <<
"\033[40;1;32m RX2 \033[0m ";
126 ss <<
"\033[40;1;32m TX/RX \033[0m ";
127 ss <<
"\033[40;1;32m RX2 \033[0m "<<std::endl<<std::endl;
128 ss <<
" param "<<std::endl;
130 ss <<
"\033[47;1;30m MODE \033[0m"<<
"\t ";
137 ss << std::scientific;
139 if(my_parameter.A_TXRX.mode == OFF) A_TXRX =
false;
140 if(my_parameter.B_TXRX.mode == OFF) B_TXRX =
false;
141 if(my_parameter.A_RX2.mode == OFF) A_RX2 =
false;
142 if(my_parameter.B_RX2.mode == OFF) B_RX2 =
false;
144 ss <<
"\033[47;1;30m RATE \033[0m"<<
" ";
146 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.rate/1e6)).str():(std::string)
" - ") <<
" ";
147 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.rate/1e6)).str():(std::string)
" - ") <<
" ";
148 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.rate/1e6)).str():(std::string)
" - ") <<
" ";
149 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.rate/1e6)).str():(std::string)
" - ") <<
"\t[MHz]"<<std::endl;
152 ss <<
"\033[47;1;30m GAIN \033[0m"<<
" ";
154 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.gain/1.)).str():(std::string)
" - ") <<
" ";
155 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.gain/1.)).str():(std::string)
" - ") <<
" ";
156 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.gain/1.)).str():(std::string)
" - ") <<
" ";
157 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.gain/1.)).str():(std::string)
" - ") <<
"\t[dB]"<<std::endl;
159 ss <<
"\033[47;1;30m TONE \033[0m"<<
" ";
161 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.tone/1e6)).str():(std::string)
" - ") <<
" ";
162 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.tone/1e6)).str():(std::string)
" - ") <<
" ";
163 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.tone/1e6)).str():(std::string)
" - ") <<
" ";
164 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.tone/1e6)).str():(std::string)
" - ") <<
"\t[MHz]"<<std::endl;
166 ss <<
"\033[47;1;30m DELAY \033[0m"<<
" ";
168 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.delay*1e3)).str():(std::string)
" - ") <<
" ";
169 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.delay*1e3)).str():(std::string)
" - ") <<
" ";
170 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.delay*1e3)).str():(std::string)
" - ") <<
" ";
171 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.delay*1e3)).str():(std::string)
" - ") <<
"\t[msec]"<<std::endl;
173 ss <<
"\033[47;1;30m BW \033[0m"<<
" ";
175 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.bw/1e6)).str():(std::string)
" - ") <<
" ";
176 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.bw/1e6)).str():(std::string)
" - ") <<
" ";
177 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.bw/1e6)).str():(std::string)
" - ") <<
" ";
178 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.bw/1e6)).str():(std::string)
" - ") <<
"\t[MHz]"<<std::endl;
180 ss <<
"\033[47;1;30m #SIGs \033[0m"<<
" ";
182 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.wave_type.size()/1.)).str():(std::string)
" - ") <<
" ";
183 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.wave_type.size()/1.)).str():(std::string)
" - ") <<
" ";
184 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.wave_type.size()/1.)).str():(std::string)
" - ") <<
" ";
185 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.wave_type.size()/1.)).str():(std::string)
" - ") <<
"\t[#]"<<std::endl;
187 ss <<
"\033[47;1;30m #samp \033[0m"<<
" ";
189 ss << (A_TXRX?(position_formatting % (my_parameter.A_TXRX.samples/1.)).str():(std::string)
" - ") <<
" ";
190 ss << (A_RX2?(position_formatting % (my_parameter.A_RX2.samples/1.)).str():(std::string)
" - ") <<
" ";
191 ss << (B_TXRX?(position_formatting % (my_parameter.B_TXRX.samples/1.)).str():(std::string)
" - ") <<
" ";
192 ss << (B_RX2?(position_formatting % (my_parameter.B_RX2.samples/1.)).str():(std::string)
" - ") <<
"\t[#]"<<std::endl;
194 ss <<
"\033[47;1;30m tun_m \033[0m"<<
" ";
195 ss << (A_TXRX?(my_parameter.A_TXRX.tuning_mode?
"fractio":
"integer"):(std::string)
" - ") <<
" ";
196 ss << (A_RX2?(my_parameter.A_TXRX.tuning_mode?
"fractio":
"integer"):(std::string)
" - ") <<
" ";
197 ss << (B_TXRX?(my_parameter.A_TXRX.tuning_mode?
"fractio":
"integer"):(std::string)
" - ") <<
" ";
198 ss << (B_RX2?(my_parameter.A_TXRX.tuning_mode?
"fractio":
"integer"):(std::string)
" - ") <<
"\t[-]"<<std::endl;
201 ss <<
"\033[40;1;37m S I G N A L S P A R A M E T E R S \033[0m"<<std::endl<<std::endl;
205 ss <<
"\033[40;1;32mRF A TX/RX No. of signals: ";
206 ss << my_parameter.A_TXRX.wave_type.size()<<
" \033[0m"<<std::endl<<std::endl;
207 ss <<
"\033[40;1;32mRF Buffer lenght: "<<my_parameter.A_TXRX.buffer_len;
208 if(my_parameter.A_TXRX.wave_type[0] != CHIRP and my_parameter.A_TXRX.mode == RX){
209 ss <<
" PFB points: "<<my_parameter.A_TXRX.fft_tones;
210 ss <<
" PFB average: "<< my_parameter.A_TXRX.pf_average<<
" \033[0m"<<std::endl<<std::endl;
212 ss <<
" "<<
" \033[0m"<<std::endl<<std::endl;
215 ss <<
"\033[47;1;30m No \033[0m"<<
" "<<
"\033[47;1;30m AMP \033[0m"<<
" "<<
"\033[47;1;30m FREQ \033[0m"<<
" ";
216 ss <<
"\033[47;1;30m 2 FRQ \033[0m"<<
" "<<
"\033[47;1;30m STEPS \033[0m"<<
" "<<
"\033[47;1;30m LAPSE \033[0m"<<
"";
217 ss <<
"\033[47;1;30m TYPE \033[0m"<<std::endl;
218 for(
size_t i = 0; i<my_parameter.A_TXRX.wave_type.size();i++){
220 ss <<
" "<<(position_formatting % (i)).str() <<
" ";
221 ss << (position_formatting % (my_parameter.A_TXRX.ampl[i]/1.)).str() <<
" ";
222 ss << (position_formatting % (my_parameter.A_TXRX.freq[i]/1e6)).str() <<
" ";
224 ss << ((my_parameter.A_TXRX.wave_type[i] == CHIRP )?((position_formatting % (my_parameter.A_TXRX.chirp_f.at(i)/1e6)).str()):(std::string)(
" - "))<<
" ";
225 ss << ((my_parameter.A_TXRX.wave_type[i] == CHIRP )?((position_formatting % (my_parameter.A_TXRX.swipe_s.at(i)/1.)).str()):(std::string)
" - ") <<
" ";
226 ss << ((my_parameter.A_TXRX.wave_type[i] == CHIRP )?((position_formatting % (my_parameter.A_TXRX.chirp_t.at(i)*1e3)).str()):(std::string)
" - ") <<
" ";
227 }
catch(std::exception& error){
228 print_error(
"Cannot print parameters! description of CHIRP signals inside global param is not coehrent!");
231 ss <<
w_type_to_str(my_parameter.A_TXRX.wave_type[i]) <<std::endl;
233 ss <<
" [#] [linear] [MHZ] [MHz] [#] [msec]"<<std::endl<<std::endl;
237 ss <<
"\033[40;1;32mRF A RX2 No. of signals: ";
238 ss << my_parameter.A_RX2.wave_type.size()<<
" \033[0m"<<std::endl<<std::endl;
239 ss <<
"\033[40;1;32mRF Buffer lenght: "<<my_parameter.A_RX2.buffer_len;
240 if(my_parameter.A_RX2.wave_type[0] != CHIRP and my_parameter.A_RX2.mode == RX){
241 ss <<
" PFB points: "<<my_parameter.A_RX2.fft_tones;
242 ss <<
" PFB average: "<< my_parameter.A_RX2.pf_average<<
" \033[0m"<<std::endl<<std::endl;
244 ss <<
" "<<
" \033[0m"<<std::endl<<std::endl;
246 ss <<
"\033[47;1;30m No \033[0m"<<
" "<<
"\033[47;1;30m AMP \033[0m"<<
" "<<
"\033[47;1;30m FREQ \033[0m"<<
" ";
247 ss <<
"\033[47;1;30m 2 FRQ \033[0m"<<
" "<<
"\033[47;1;30m STEPS \033[0m"<<
" "<<
"\033[47;1;30m LAPSE \033[0m"<<
"";
248 ss <<
"\033[47;1;30m TYPE \033[0m"<<std::endl;
249 for(
size_t i = 0; i<my_parameter.A_RX2.wave_type.size();i++){
250 ss <<
" "<<(position_formatting % (i)).str() <<
" ";
251 ss << (position_formatting % (my_parameter.A_RX2.ampl[i]/1.)).str() <<
" ";
252 ss << (position_formatting % (my_parameter.A_RX2.freq[i]/1e6)).str() <<
" ";
254 ss << ((my_parameter.A_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.A_RX2.chirp_f.at(i)/1e6)).str()):(std::string)(
" - "))<<
" ";
255 ss << ((my_parameter.A_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.A_RX2.swipe_s.at(i)/1.)).str()):(std::string)
" - ") <<
" ";
256 ss << ((my_parameter.A_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.A_RX2.chirp_t.at(i)*1e3)).str()):(std::string)
" - ") <<
" ";
257 }
catch(std::exception& error){
258 print_error(
"Cannot print parameters! description of CHIRP signals inside global param is not coehrent!");
261 ss <<
w_type_to_str(my_parameter.A_RX2.wave_type[i]) <<std::endl;
263 ss <<
" [#] [linear] [MHZ] [MHz] [#] [msec]"<<std::endl<<std::endl;
267 ss <<
"\033[40;1;32mRF B TX/RX No. of signals: ";
268 ss << my_parameter.B_TXRX.wave_type.size()<<
" \033[0m"<<std::endl<<std::endl;
269 ss <<
"\033[40;1;32mRF Buffer lenght: "<<my_parameter.B_TXRX.buffer_len;
270 if(my_parameter.B_TXRX.wave_type[0] != CHIRP and my_parameter.B_TXRX.mode == RX){
271 ss <<
" PFB points: "<<my_parameter.B_TXRX.fft_tones;
272 ss <<
" PFB average: "<< my_parameter.B_TXRX.pf_average<<
" \033[0m"<<std::endl<<std::endl;
274 ss <<
" "<<
" \033[0m"<<std::endl<<std::endl;
276 ss <<
"\033[47;1;30m No \033[0m"<<
" "<<
"\033[47;1;30m AMP \033[0m"<<
" "<<
"\033[47;1;30m FREQ \033[0m"<<
" ";
277 ss <<
"\033[47;1;30m 2 FRQ \033[0m"<<
" "<<
"\033[47;1;30m STEPS \033[0m"<<
" "<<
"\033[47;1;30m LAPSE \033[0m"<<
"";
278 ss <<
"\033[47;1;30m TYPE \033[0m"<<std::endl;
281 for(
size_t i = 0; i<my_parameter.B_TXRX.wave_type.size();i++){
282 ss <<
" "<<(position_formatting % (i)).str() <<
" ";
283 ss << (position_formatting % (my_parameter.B_TXRX.ampl[i]/1.)).str() <<
" ";
284 ss << (position_formatting % (my_parameter.B_TXRX.freq[i]/1e6)).str() <<
" ";
286 ss << ((my_parameter.B_TXRX.wave_type[i] == CHIRP )?((position_formatting % (my_parameter.B_TXRX.chirp_f.at(i)/1e6)).str()):(std::string)(
" - "))<<
" ";
287 ss << ((my_parameter.B_TXRX.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.B_TXRX.swipe_s.at(i)/1.)).str()):(std::string)
" - ") <<
" ";
288 ss << ((my_parameter.B_TXRX.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.B_TXRX.chirp_t.at(i)*1e3)).str()):(std::string)
" - ") <<
" ";
289 }
catch(std::exception& error){
290 print_error(
"Cannot print parameters! description of SWIPE signals inside global param is not coehrent!");
293 ss <<
w_type_to_str(my_parameter.B_TXRX.wave_type[i]) <<std::endl;
295 ss <<
" [#] [linear] [MHZ] [MHz] [#] [msec]"<<std::endl<<std::endl;
299 ss <<
"\033[40;1;32mRF B RX2 No. of signals: ";
300 ss << my_parameter.B_RX2.wave_type.size()<<
" \033[0m"<<std::endl<<std::endl;
301 ss <<
"\033[40;1;32mRF Buffer lenght: "<<my_parameter.B_RX2.buffer_len;
302 if(my_parameter.B_RX2.wave_type[0] != CHIRP and my_parameter.B_RX2.mode == RX){
303 ss <<
" PFB points: "<<my_parameter.B_RX2.fft_tones;
304 ss <<
" PFB average: "<< my_parameter.B_RX2.pf_average<<
" \033[0m"<<std::endl<<std::endl;
306 ss <<
" "<<
" \033[0m"<<std::endl<<std::endl;
308 ss <<
"\033[47;1;30m No \033[0m"<<
" "<<
"\033[47;1;30m AMP \033[0m"<<
" "<<
"\033[47;1;30m FREQ \033[0m"<<
" ";
309 ss <<
"\033[47;1;30m 2 FRQ \033[0m"<<
" "<<
"\033[47;1;30m STEPS \033[0m"<<
" "<<
"\033[47;1;30m LAPSE \033[0m"<<
"";
310 ss <<
"\033[47;1;30m TYPE \033[0m"<<std::endl;
311 for(
size_t i = 0; i<my_parameter.B_RX2.wave_type.size();i++){
312 ss <<
" "<<(position_formatting % (i)).str() <<
" ";
313 ss << (position_formatting % (my_parameter.B_RX2.ampl[i]/1.)).str() <<
" ";
314 ss << (position_formatting % (my_parameter.B_RX2.freq[i]/1e6)).str() <<
" ";
316 ss << ((my_parameter.B_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.B_RX2.chirp_f.at(i)/1e6)).str()):(std::string)(
" - "))<<
" ";
317 ss << ((my_parameter.B_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.B_RX2.swipe_s.at(i)/1.)).str()):(std::string)
" - ") <<
" ";
318 ss << ((my_parameter.B_RX2.wave_type[i] == CHIRP)?((position_formatting % (my_parameter.B_RX2.chirp_t.at(i)*1e3)).str()):(std::string)
" - ") <<
" ";
319 }
catch(std::exception& error){
320 print_error(
"Cannot print parameters! description of SWIPE signals inside global param is not coehrent!");
323 ss <<
w_type_to_str(my_parameter.B_RX2.wave_type[i]) <<std::endl;
325 ss <<
" [#] [linear] [MHZ] [MHz] [#] [msec]"<<std::endl<<std::endl;
328 std::cout << ss.str();
334 start_t = boost::chrono::high_resolution_clock::now();
339 start_t = boost::chrono::high_resolution_clock::now();
340 elapsed_time = get_time();
345 double y = get_time();
346 double x = y - elapsed_time;
354 start_t = boost::chrono::high_resolution_clock::now();
367 acc.push_back(total_time);
378 for(
size_t i = 0; i < acc.size(); i++){
391 double stop_watch::get_time(){
392 boost::chrono::nanoseconds ns = boost::chrono::high_resolution_clock::now() - start_t;
393 return 1e-9 * ns.count();
397 template<
typename CharT,
typename TraitsT >
399 std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
401 static const char*
const str[] =
410 if (static_cast< std::size_t >(lvl) < (
sizeof(str) /
sizeof(*str)))
413 strm << static_cast< int >(lvl);
422 boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >(
"Severity");
425 keywords::file_name =
"logs/%Y%m%d_%H%M%S_%5N.log",
426 keywords::rotation_size = 10 * 1024 * 1024,
427 keywords::auto_flush =
true,
428 keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
429 keywords::format =
"%TimeStamp%;%ThreadName%;%Severity%;%Message%" 431 logging::core::get()->add_global_attribute(
"ThreadName", boost::log::attributes::constant<std::string> (
"Unknown"));
std::string ant_mode_to_str(ant_mode enumerator)
void interptet_rx_error(uhd::rx_metadata_t::error_code_t error)
boost::shared_ptr< file_sink > pLogSink
Shared pointer to the logfile writer object.
std::string w_type_to_str(w_type enumerator)
void print_error(std::string text)
std::basic_ostream< CharT, TraitsT > & operator<<(std::basic_ostream< CharT, TraitsT > &strm, severity_level lvl)
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.
int get_rx_errors(uhd::rx_metadata_t *metadata, bool verbose)
void print_warning(std::string text)
void init_logger()
initialize the logger for the server. Creates or access the folder logs. each time the server starts...
int get_tx_error(uhd::async_metadata_t *async_md, bool verbose)
Interpret tx errors from the async usrp comunication.