@@ -11,6 +11,13 @@ namespace am
11
11
{
12
12
ResourceStatus::ResourceStatus (std::shared_ptr<am::ResourceMonitorStats> stats) : stats_(stats)
13
13
{
14
+
15
+ sys_rep_pub_ = am::Node::node->create_publisher <brain_box_msgs::msg::SystemReport>(system_status_topic_,1 );
16
+
17
+ log_ctrl_sub_ = am::Node::node->create_subscription <brain_box_msgs::msg::LogControl>(" /ctrl/log_control" , 1 , std::bind (&ResourceStatus::logCtrlCB, this , std::placeholders::_1));
18
+
19
+ level_ = BagLogger::OFF;
20
+
14
21
transformer_ = std::make_shared<am::Transformer>();
15
22
16
23
sub_nets_add_ = getInetAddresses ();
@@ -37,6 +44,42 @@ ResourceStatus::~ResourceStatus()
37
44
38
45
}
39
46
47
+ void ResourceStatus::logCtrlCB (const brain_box_msgs::msg::LogControl::SharedPtr msg)
48
+ {
49
+ if (msg->enable )
50
+ {
51
+ ROS_INFO_STREAM (am::Node::node->get_name () << " : start logging to RS, level " << (int )msg->level );
52
+ BagLogger::instance ()->startLogging (" RS" , msg->level );
53
+ enabled_ = true ;
54
+ switch (msg->level )
55
+ {
56
+ case 1 :
57
+ level_ = BagLogger::NORM;
58
+ break ;
59
+ case 2 :
60
+ level_ = BagLogger::FINE;
61
+ break ;
62
+ case 3 :
63
+ level_ = BagLogger::EXTRA;
64
+ break ;
65
+ case 4 :
66
+ level_ = BagLogger::ALL;
67
+ break ;
68
+ default :
69
+ level_ = BagLogger::OFF;
70
+ break ;
71
+ }
72
+ }
73
+ else
74
+ {
75
+ ROS_INFO_STREAM (am::Node::node->get_name () << " : stop logging" );
76
+ BagLogger::instance ()->stopLogging ();
77
+ enabled_ = false ;
78
+ level_ = BagLogger::OFF;
79
+
80
+ }
81
+ }
82
+
40
83
void ResourceStatus::getParams ()
41
84
{
42
85
@@ -152,14 +195,19 @@ am::CpuInfo ResourceStatus::parseCpuLine(const std::string& line)
152
195
return info;
153
196
}
154
197
155
- void ResourceStatus::updateInfos ()
198
+ void ResourceStatus::updateInfos (brain_box_msgs::msg::SystemReport &sys_report )
156
199
{
157
200
getMemoryInfo ();
201
+ sys_report.mem_free_percentage = (float )(100 - mi.used_percent );
202
+ sys_report.mem_total_mb = (float )mi.total ;
203
+ sys_report.mem_used_percentage = (float )mi.used_percent ;
204
+ sys_report.cores_count = cpu_cnt_;
158
205
if (cpu_cnt_ < 0 )
159
206
{
160
207
cpu_cnt_ = getCPUCoresCount ();
161
208
if (cpu_cnt_ < 0 )
162
209
{
210
+ sys_report.error_msg += " , Cannot get CPU count" ;
163
211
ROS_ERROR (" Cannot get CPU count" );
164
212
return ;
165
213
}
@@ -182,20 +230,25 @@ void ResourceStatus::updateInfos()
182
230
double load = calculateCpuLoad (cpu_infos_[i], cpu_infos_old_[i]);
183
231
avg_load+=load;
184
232
cpu_loads_[i] = load;
233
+ sys_report.cpu_percent_cores .push_back (load);
185
234
}
186
235
187
236
if (cpu_cnt_ > 0 )
188
237
{
189
238
avg_load = avg_load/cpu_cnt_;
239
+ sys_report.cpu_percent_total = avg_load;
190
240
stats_->cpu_stats = (avg_load > 80.0 ?100 :50 );
191
241
}
192
242
193
243
194
244
uptime_seconds_ = getUpTime ();
245
+ sys_report.uptime_seconds = uptime_seconds_;
195
246
196
247
cpu_infos_old_ = cpu_infos_;
197
248
198
249
gpu_info_ = getGPUInfo ();
250
+ sys_report.gpu_used_percentage = (float )gpu_info_.load_percent ;
251
+ sys_report.gpu_temp = (float )gpu_info_.temp ;
199
252
stats_->gpu_stats = 50 ;
200
253
// ROS_INFO("GPU Load Percent: %d , Temp: %d", gpu_info_.load_percent, gpu_info_.temp);
201
254
if (gpu_info_.load_percent > 90 )
@@ -207,11 +260,14 @@ void ResourceStatus::updateInfos()
207
260
208
261
// check the drive stats
209
262
stats_->drive_stats = 50 ;
263
+ int coef = 1024 *1024 ;
210
264
am::DiskInfo disk_info = getDiskInfo ();
265
+ sys_report.hd_used_percentage = disk_info.percentUsed ;
266
+ sys_report.hd_used = (float )(disk_info.usedSpace /coef);
211
267
if (disk_info.percentUsed > 98.0 )
212
268
{
213
269
stats_->drive_stats = 100 ;
214
- int coef = 1024 * 1024 ;
270
+
215
271
ROS_ERROR (" Disk total: %lld MB, available: %lld MB, used: %lld MB, percentage: %f" , (disk_info.totalSpace /coef), (disk_info.availableSpace /coef), (disk_info.usedSpace /coef), disk_info.percentUsed );
216
272
}
217
273
@@ -478,11 +534,12 @@ void ResourceStatus::print()
478
534
ROS_INFO (" %s" , msg.c_str ());
479
535
}
480
536
481
- void ResourceStatus::checkNodeNames ()
537
+ void ResourceStatus::checkNodeNames (brain_box_msgs::msg::SystemReport &sys_report )
482
538
{
483
539
rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph = am::Node::node->get_node_graph_interface ();
484
540
485
541
std::vector<std::string> running_nodes = node_graph->get_node_names ();
542
+ sys_report.nodes = running_nodes;
486
543
487
544
std::unordered_map<std::string, int > string_count;
488
545
@@ -497,36 +554,48 @@ void ResourceStatus::checkNodeNames()
497
554
}
498
555
499
556
// Collect strings that appear more than once
557
+ std::string error_msg = " " ;
500
558
bool node_check = true ;
501
559
for (const auto & [str, count] : string_count)
502
560
{
503
561
if (count > 1 )
504
562
{
505
- ROS_ERROR (" Found a duplicate Node: %s" , str.c_str ());
506
- node_check = false ;
563
+ error_msg += " Found a duplicate Node: " + str;
564
+ ROS_ERROR (" %s" , error_msg.c_str ());
565
+ sys_report.error_msg += error_msg;
507
566
}
508
567
}
509
568
stats_->node_stats = (node_check?50 :100 );
510
569
}
511
570
512
- void ResourceStatus::checkTransforms ()
571
+ void ResourceStatus::checkTransforms (brain_box_msgs::msg::SystemReport &sys_report )
513
572
{
514
573
bool tf_check = true ;
515
574
for (std::pair<std::string, std::string> &tf_str : transform_list_)
516
575
{
517
576
geometry_msgs::msg::TransformStamped transform;
577
+ brain_box_msgs::msg::TransformStatus tf_status_msg;
578
+ tf_status_msg.source = tf_str.first ;
579
+ tf_status_msg.target = tf_str.second ;
580
+ tf_status_msg.status = brain_box_msgs::msg::TransformStatus::CONNECTED;
518
581
if (!transformer_->getTransform (tf_str.first , tf_str.second , transform, 1.0 , false ))
519
582
{
583
+ std::string error_msg = std::string (" , Transform tree is broken between: " ) + tf_str.first + " and " + tf_str.second ;
520
584
// ROS_ERROR("Transform tree is broken: %s, %s", tf_str.first.c_str(), tf_str.second.c_str());
521
585
tf_check = false ;
586
+ tf_status_msg.status = brain_box_msgs::msg::TransformStatus::DISCONNECTED;
587
+ sys_report.error_msg += error_msg;
522
588
}
589
+
590
+ sys_report.tf_tree_status .push_back (tf_status_msg);
523
591
}
524
592
stats_->tf_stats = (tf_check?50 :100 );
525
593
}
526
594
527
- void ResourceStatus::checkSensorIPs ()
595
+ void ResourceStatus::checkSensorIPs (brain_box_msgs::msg::SystemReport &sys_report )
528
596
{
529
597
598
+
530
599
// IP Address Check
531
600
stats_->lidar_ip = 50 ;
532
601
stats_->fl_ip = 50 ;
@@ -539,36 +608,53 @@ void ResourceStatus::checkSensorIPs()
539
608
std::map<std::string, std::string>::iterator it = ip_addresses_.begin ();
540
609
for (; it != ip_addresses_.end (); ++it)
541
610
{
542
-
611
+ brain_box_msgs::msg::IPSensorStatus ip_sensor_msg;
612
+ ip_sensor_msg.ip = it->first ;
613
+ ip_sensor_msg.alias = it->second ;
614
+ ip_sensor_msg.status = brain_box_msgs::msg::IPSensorStatus::CONNECTED;
543
615
if (!isReachable (it->first ))
544
616
{
617
+ ip_sensor_msg.status = brain_box_msgs::msg::IPSensorStatus::DISCONNECTED;
618
+ std::string error_msg;
545
619
// THE DEVICE CANNOT BE REACHED
546
620
if (it->second == " lidar" )
547
621
{
622
+
548
623
stats_->lidar_ip = 100 ;
549
- ROS_ERROR (" Lidar is not reachable" );
624
+ error_msg = " Lidar is not reachable" ;
625
+ sys_report.error_msg += error_msg;
626
+ ROS_ERROR (" %s" , error_msg.c_str ());
550
627
}
551
628
if (it->second == " front_left" )
552
629
{
553
630
stats_->fl_ip = 100 ;
554
- ROS_ERROR (" Front Left Camera is not reachable" );
631
+ error_msg = " Front Left is not reachable" ;
632
+ sys_report.error_msg += error_msg;
633
+ ROS_ERROR (" %s" , error_msg.c_str ());
555
634
}
556
635
if (it->second == " front_right" )
557
636
{
558
637
stats_->fr_ip = 100 ;
559
- ROS_ERROR (" Front Right Camera is not reachable" );
638
+ error_msg = " Front Right is not reachable" ;
639
+ sys_report.error_msg += error_msg;
640
+ ROS_ERROR (" %s" , error_msg.c_str ());
560
641
}
561
642
if (it->second == " rear_right" )
562
643
{
563
644
stats_->rr_ip = 100 ;
564
- ROS_ERROR (" Rear Right Camera is not reachable" );
645
+ error_msg = " Rear Right Left is not reachable" ;
646
+ sys_report.error_msg += error_msg;
647
+ ROS_ERROR (" %s" , error_msg.c_str ());
565
648
}
566
649
if (it->second == " rear_left" )
567
650
{
568
651
stats_->rl_ip = 100 ;
569
- ROS_ERROR (" Rear Left Camera is not reachable" );
652
+ error_msg = " Rear Left is not reachable" ;
653
+ sys_report.error_msg += error_msg;
654
+ ROS_ERROR (" %s" , error_msg.c_str ());
570
655
}
571
656
}
657
+ sys_report.ip_sensors .push_back (ip_sensor_msg);
572
658
}
573
659
}
574
660
}
@@ -665,17 +751,25 @@ DiskInfo ResourceStatus::getDiskInfo(const std::string& path)
665
751
*/
666
752
void ResourceStatus::timerCB ()
667
753
{
754
+
755
+ brain_box_msgs::msg::SystemReport sr_msg;
756
+ sr_msg.header .stamp = am::ClockNow ();
757
+
668
758
// Checking the repeated node name
669
- checkNodeNames ();
759
+ checkNodeNames (sr_msg );
670
760
671
761
// Transform check
672
- checkTransforms ();
762
+ checkTransforms (sr_msg );
673
763
674
764
// sensor ip check
675
- checkSensorIPs ();
765
+ checkSensorIPs (sr_msg );
676
766
677
767
// Resource Check
678
- updateInfos ();
768
+ updateInfos (sr_msg);
769
+
770
+ sys_rep_pub_->publish (sr_msg);
771
+
772
+ LOG_MSG (system_status_topic_, sr_msg, 2 );
679
773
680
774
}
681
775
}
0 commit comments