diagnostic_parser.cpp
Go to the documentation of this file.
00001 
00027 #include "sr_self_test/diagnostic_parser.hpp"
00028 #include <boost/foreach.hpp>
00029 
00030 namespace shadow_robot
00031 {
00032   DiagnosticParser::DiagnosticParser(self_test::TestRunner* test_runner)
00033     : test_runner_(test_runner)
00034   {
00035     diagnostics_.push_back( new RTLoopDiagnostics("Realtime Control Loop", test_runner_));
00036     diagnostics_.push_back( new EtherCATMasterDiagnostics("EtherCAT Master", test_runner_));
00037     diagnostics_.push_back( new MotorDiagnostics("SRDMotor", test_runner_));
00038     diagnostics_.push_back( new IsOKDiagnostics("EtherCAT Dual CAN Palm", test_runner_));
00039     diagnostics_.push_back( new IsOKDiagnostics("SRBridge", test_runner_)); //TODO: not sure what's the 00
00040 
00041     run_tests_();
00042   }
00043 
00044   void DiagnosticParser::run_tests_()
00045   {
00046     diag_sub_ = nh_.subscribe("diagnostics_agg", 1, &DiagnosticParser::diagnostics_agg_cb_, this);
00047 
00048     //wait for 5 seconds while we parse the diagnostics.
00049     // spin to make sure we get the messages
00050     for(size_t i=0; i<50; ++i)
00051     {
00052       ros::Duration(0.1).sleep();
00053       ros::spinOnce();
00054     }
00055 
00056     BOOST_FOREACH(DiagnosticsMap::value_type diag, all_diagnostics_)
00057     {
00058       diag.second->add_test();
00059     }
00060 
00061     diag_sub_.shutdown();
00062   }
00063 
00064   void DiagnosticParser::diagnostics_agg_cb_(const diagnostic_msgs::DiagnosticArray::ConstPtr& msg)
00065   {
00066     for( size_t status_i = 0; status_i < msg->status.size(); ++status_i )
00067     {
00068       for( size_t diag_i = 0; diag_i < diagnostics_.size() ; ++diag_i )
00069       {
00070         if( msg->status[status_i].name.find(diagnostics_[diag_i].name) != std::string::npos )
00071         {
00072           std::string full_name = msg->status[status_i].name;
00073           DiagnosticsMap::iterator it;
00074           it = all_diagnostics_.find(full_name);
00075 
00076           //insert a new diag if it doesn't exist already
00077           if( it == all_diagnostics_.end() )
00078           {
00079             all_diagnostics_.insert( full_name,
00080                                      diagnostics_[diag_i].shallow_clone(full_name) );
00081 
00082             it = all_diagnostics_.find(full_name);
00083           }
00084 
00085           it->second->parse_diagnostics( msg->status[status_i].values,
00086                                          msg->status[status_i].level,
00087                                          full_name );
00088         }
00089       }
00090     }
00091   }
00092 }
00093 
00094 /* For the emacs weenies in the crowd.
00095    Local Variables:
00096    c-basic-offset: 2
00097    End:
00098 */
00099 


sr_self_test
Author(s): Ugo Cupcic
autogenerated on Fri Aug 28 2015 13:09:38