diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index b806c294d..8ae33b24e 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -48,14 +48,16 @@ public: void toggle_print(bool b); void set_metrics(ue_metrics_t &m, float report_period_secs); + void set_ue_handle(ue_metrics_interface *ue_); private: std::string float_to_string(float f, int digits); std::string float_to_eng_string(float f, int digits); std::string int_to_eng_string(int f, int digits); - bool do_print; - uint8_t n_reports; + bool do_print; + uint8_t n_reports; + ue_metrics_interface* ue; }; } // namespace srsue diff --git a/srsue/hdr/ue_metrics_interface.h b/srsue/hdr/ue_metrics_interface.h index bc0614a03..20ee6f031 100644 --- a/srsue/hdr/ue_metrics_interface.h +++ b/srsue/hdr/ue_metrics_interface.h @@ -57,6 +57,7 @@ class ue_metrics_interface : public srslte::metrics_interface { public: virtual bool get_metrics(ue_metrics_t &m) = 0; + virtual bool is_attached() = 0; }; } // namespace srsue diff --git a/srsue/src/main.cc b/srsue/src/main.cc index f140a593d..8ad288b4b 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -366,6 +366,7 @@ int main(int argc, char *argv[]) metricshub.init(ue, args.expert.metrics_period_secs); metricshub.add_listener(&metrics_screen); + metrics_screen.set_ue_handle(ue); pthread_t input; pthread_create(&input, NULL, &input_loop, &args); diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index 3ca4756a3..6828c912f 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -50,9 +50,15 @@ char const * const prefixes[2][9] = metrics_stdout::metrics_stdout() :do_print(false) ,n_reports(10) + ,ue(NULL) { } +void metrics_stdout::set_ue_handle(ue_metrics_interface *ue_) +{ + ue = ue_; +} + void metrics_stdout::toggle_print(bool b) { do_print = b; @@ -61,9 +67,14 @@ void metrics_stdout::toggle_print(bool b) void metrics_stdout::set_metrics(ue_metrics_t &metrics, float metrics_report_period) { - if(!do_print) + if(!do_print || ue == NULL) return; + if (!ue->is_attached()) { + cout << "--- disconnected ---" << endl; + return; + } + if(++n_reports > 10) { n_reports = 0; diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 646b87612..03e4b6546 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -247,7 +247,7 @@ void ue::stop() bool ue::is_attached() { - return (EMM_STATE_REGISTERED == nas.get_state()); + return (RRC_STATE_CONNECTED == rrc.get_state()); } void ue::start_plot() {