43 #include <boost/foreach.hpp> 47 #define NAME_BUFFER_SIZE 250 50 const std::vector<std::string> &ignore) :
51 internal_name_(chip_name)
60 sensors_feature
const *feature;
63 while ((feature = sensors_get_features(
internal_name_, &number)) != NULL) {
64 sensors_feature_type type = feature->type;
67 case SENSORS_FEATURE_FAN:
68 feature_ptr.reset(
new FanSensor(*
this, feature));
70 case SENSORS_FEATURE_TEMP:
71 feature_ptr.reset(
new TempSensor(*
this, feature));
73 case SENSORS_FEATURE_IN:
81 if( std::count(ignore.begin(), ignore.end(),
82 feature_ptr->getFullName()) > 0 ) {
89 std::stringstream info_msg;
90 info_msg <<
"Found sensor " <<
getName();
92 info_msg <<
" with features: ";
96 info_msg << feature->getFeatureName();
97 if( remain > 0 ) info_msg <<
", ";
100 info_msg <<
" with no features?";
108 sensors_feature
const *feature) :
114 if( label_c_str == NULL ) {
133 sensors_subfeature
const *subfeature;
146 if(subfeature->getType()==type)
154 sensors_subfeature
const *subfeature) :
156 subfeature_(subfeature),
157 name_(subfeature->name)
177 double speed_val = speed->getValue();
179 stat.
summary(diagnostic_msgs::DiagnosticStatus::WARN,
180 "Fan stalled or not connected");
182 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::OK,
"Fan OK (%.2f RPM)",
184 stat.
add(
"Fan Speed (RPM)", speed_val);
187 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"No Fan Input!!!");
197 double temp_val = temp->getValue();
198 stat.
add(
"Temperature (C)", temp_val);
200 if(max_temp && max_temp->getValue()!=0)
201 stat.
add(
"Max Temperature (C)", max_temp->getValue());
202 if(temp_crit && temp_crit->getValue()!=0)
203 stat.
add(
"Temperature Critical (C)", temp_crit->getValue());
205 if(temp_crit_alarm && temp_crit_alarm->getValue()!=0)
206 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::WARN,
207 "Critical Temp Alarm (%.2f C)", temp_val);
208 else if(temp_crit && temp_crit->getValue()!=0 &&
209 temp_val > temp_crit->getValue())
210 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::WARN,
211 "Critical Temp Alarm (%.2f C)", temp_val);
212 else if(max_temp && max_temp->getValue()!=0 &&
213 temp_val > max_temp->getValue())
214 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::WARN,
215 "Max Temp Alarm (%.2f C)", temp_val);
217 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::OK,
218 "Temp OK (%.2f C)", temp_val);
221 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"NO TEMP Input!!!");
226 SENSORS_SUBFEATURE_IN_INPUT);
228 SENSORS_SUBFEATURE_IN_MIN);
230 SENSORS_SUBFEATURE_IN_MAX);
232 SENSORS_SUBFEATURE_IN_LCRIT);
234 SENSORS_SUBFEATURE_IN_CRIT);
238 SENSORS_SUBFEATURE_IN_ALARM);
240 SENSORS_SUBFEATURE_IN_MIN_ALARM);
242 SENSORS_SUBFEATURE_IN_MAX_ALARM);
244 SENSORS_SUBFEATURE_IN_LCRIT_ALARM);
246 SENSORS_SUBFEATURE_IN_CRIT_ALARM);
249 double voltage_val = voltage->getValue();
250 stat.
add(
"Voltage (V)", voltage_val);
252 bool low_warn =
false;
253 bool low_err =
false;
254 bool high_warn =
false;
255 bool high_err =
false;
259 stat.
add(
"Max Voltage (V)", max->getValue());
260 if(max_alarm && max_alarm->getValue()!=0) {
262 }
else if(voltage_val >= max->getValue()) {
269 stat.
add(
"Min Voltage (V)", min->getValue());
270 if(min_alarm && min_alarm->getValue()!=0) {
272 }
else if(voltage_val <= min->
getValue()) {
278 stat.
add(
"Critical Max Voltage (V)", crit->getValue());
279 if(crit_alarm && crit_alarm->getValue()!=0) {
281 }
else if(voltage_val >= crit->getValue()) {
287 stat.
add(
"Critical Min Voltage (V)", lcrit->getValue());
288 if(lcrit_alarm && lcrit_alarm->getValue()!=0) {
290 }
else if(voltage_val <= lcrit->
getValue()) {
297 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::ERROR,
298 "High Voltage CRITICAL (%.2f V)", voltage_val);
300 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::ERROR,
301 "Low Voltage CRITICAL (%.2f V)", voltage_val);
302 }
else if(high_warn) {
303 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::WARN,
304 "High Voltage ALARM (%.2f V)", voltage_val);
305 }
else if(low_warn) {
306 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::WARN,
307 "Low Voltage ALARM (%.2f V)", voltage_val);
309 stat.
summaryf(diagnostic_msgs::DiagnosticStatus::OK,
310 "Voltage OK (%.2f V)", voltage_val);
313 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
314 "NO Voltage Input!!!");
319 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Unkown sensor type");
321 stat.
add(subfeature->getName(), subfeature->getValue());
SensorChipFeature(const SensorChip &chip, sensors_feature const *feature)
friend class SensorChipSubFeature
SensorChip(sensors_chip_name const *chip_name, const std::vector< std::string > &ignore)
virtual void buildStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
const SensorChipFeature & feature_
SensorChipSubFeature(const SensorChipFeature &feature, sensors_subfeature const *subfeature)
void summary(unsigned char lvl, const std::string s)
const std::string & getName()
const std::string & getFeatureName() const
boost::shared_ptr< SensorChipSubFeature > SensorChipSubFeaturePtr
sensors_feature const * feature_
const std::string & getFeatureLabel() const
void summaryf(unsigned char lvl, const char *format,...)
sensors_subfeature const * subfeature_
const std::string & getName() const
sensors_chip_name const * internal_name_
std::vector< SensorChipSubFeaturePtr > sub_features_
virtual void buildStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
#define ROS_WARN_STREAM(args)
std::vector< SensorChipFeaturePtr > features_
#define ROS_INFO_STREAM(args)
const std::string & getFullName() const
SensorChipSubFeaturePtr getSubFeatureByType(sensors_subfeature_type type)
virtual void buildStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
void add(const std::string &key, const T &val)
void enumerate_subfeatures()
const std::string & getFullLabel() const
virtual void buildStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
std::string getChipName()