UAVCAN: Printing all known sensor bridge names with usage info

This commit is contained in:
Pavel Kirienko 2014-08-22 20:33:35 +04:00
parent 6870cd4d3d
commit 7132141cc4
3 changed files with 20 additions and 0 deletions

View File

@ -36,12 +36,17 @@
*/
#include "sensor_bridge.hpp"
#include <systemlib/err.h>
#include "gnss.hpp"
#include "mag.hpp"
#include "baro.hpp"
IUavcanSensorBridge* IUavcanSensorBridge::make(uavcan::INode &node, const char *bridge_name)
{
/*
* TODO: make a linked list of known implementations at startup?
*/
if (!std::strncmp(UavcanGnssBridge::NAME, bridge_name, MAX_NAME_LEN)) {
return new UavcanGnssBridge(node);
} else if (!std::strncmp(UavcanMagnetometerBridge::NAME, bridge_name, MAX_NAME_LEN)) {
@ -52,3 +57,10 @@ IUavcanSensorBridge* IUavcanSensorBridge::make(uavcan::INode &node, const char *
return nullptr;
}
}
void IUavcanSensorBridge::print_known_names(const char *prefix)
{
printf("%s%s\n", prefix, UavcanGnssBridge::NAME);
printf("%s%s\n", prefix, UavcanMagnetometerBridge::NAME);
printf("%s%s\n", prefix, UavcanBarometerBridge::NAME);
}

View File

@ -67,4 +67,9 @@ public:
* @return nullptr if such bridge can't be created.
*/
static IUavcanSensorBridge* make(uavcan::INode &node, const char *bridge_name);
/**
* Prints all valid bridge names into stdout via printf(), one name per line with prefix.
*/
static void print_known_names(const char *prefix);
};

View File

@ -590,6 +590,9 @@ static void print_usage()
"\tuavcan start <node_id> [can_bitrate]\n"
"\tuavcan sensor enable <sensor name>\n"
"\tuavcan sensor list");
warnx("known sensor bridges:");
IUavcanSensorBridge::print_known_names("\t");
}
extern "C" __EXPORT int uavcan_main(int argc, char *argv[]);