41 #include <px4_platform_common/getopt.h> 53 PX4_WARN(
"running on bus: %u (%s)\n", (
unsigned)bus.
bus_id, bus.
devpath);
64 int fd = open(path, O_RDONLY);
72 errx(1,
"Failed to setup poll rate");
76 PX4_INFO(
"Poll rate set to 100 Hz");
87 if (bus.
dev !=
nullptr) {
88 errx(1,
"bus option already started");
94 if (interface->init() !=
OK) {
96 warnx(
"no device on bus %u", (
unsigned)bus.bus_id);
101 bus.dev =
new RM3100(interface, bus.devpath, rotation);
103 if (bus.dev !=
nullptr &&
104 bus.dev->init() !=
OK) {
116 bool started =
false;
139 bool stopped =
false;
160 const char *path = bus.
devpath;
162 int fd = open(path, O_RDONLY);
165 PX4_WARN(
"%s open failed (try 'rm3100 start')", path);
170 sz =
read(fd, &report,
sizeof(report));
172 if (sz !=
sizeof(report)) {
173 PX4_WARN(
"immediate read failed");
177 print_message(report);
181 PX4_WARN(
"failed to get if mag is onboard or external");
188 for (
unsigned i = 0; i < 5; i++) {
193 ret = poll(&fds, 1, 2000);
196 PX4_WARN(
"timed out waiting for sensor data");
201 sz =
read(fd, &report,
sizeof(report));
203 if (sz !=
sizeof(report)) {
204 PX4_WARN(
"periodic read failed");
208 print_message(report);
219 const char *path = bus.
devpath;
221 int fd = open(path, O_RDONLY);
224 PX4_WARN(
"open failed ");
229 PX4_WARN(
"driver reset failed");
234 PX4_WARN(
"driver poll restart failed");
244 PX4_WARN(
"missing command: try 'start', 'info', 'test', 'reset', 'info'");
245 PX4_WARN(
"options:");
246 PX4_WARN(
" -R rotation");
247 PX4_WARN(
" -X external I2C bus");
248 PX4_WARN(
" -I internal I2C bus");
249 PX4_WARN(
" -S external SPI bus");
250 PX4_WARN(
" -s internal SPI bus");
258 const char *myoptarg =
nullptr;
263 while ((ch = px4_getopt(argc, argv,
"XISR:T", &myoptind, &myoptarg)) != EOF) {
266 rotation = (
enum Rotation)atoi(myoptarg);
291 if (myoptind >= argc) {
296 const char *verb = argv[myoptind];
299 if (!strcmp(verb,
"start")) {
313 if (!strcmp(verb,
"stop")) {
318 if (!strcmp(verb,
"test")) {
323 if (!strcmp(verb,
"reset")) {
328 if (!strcmp(verb,
"info") ||
329 !strcmp(verb,
"status")) {
333 PX4_INFO(
"unrecognized command, try 'start', 'test', 'reset' or 'info'");
347 errx(1,
"bus %u not started", (
unsigned)bus_id);
#define MAGIOCGEXTERNAL
determine if mag is external or onboard
static struct bmp280_bus_option * find_bus(BMP280_BUS busid)
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
bool start_bus(struct rm3100_bus_option &bus, Rotation rotation)
Starts the driver for a specific bus option.
bool init(RM3100_BUS bus_id)
Initializes the driver – sets defaults and starts a cycle.
__EXPORT int rm3100_main(int argc, char *argv[])
Driver 'main' command.
static void read(bootloader_app_shared_t *pshared)
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
int start(RM3100_BUS bus_id, Rotation rotation)
Starts the driver.
struct bmp280::bmp280_bus_option bus_options[]
Rotation
Enum for board and external compass rotations.
void usage()
Prints info about the driver argument usage.
void print_info()
Diagnostics - print some basic information about the driver.
static bool start_bus(bmp280_bus_option &bus)
int info(RM3100_BUS bus_id)
Prints info about the driver.
bool test(RM3100_BUS bus_id)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
int stop()
Stop the driver.
#define SENSORIOCRESET
Reset the sensor to its default configuration.
Fundamental base class for all physical drivers (I2C, SPI).
rm3100_bus_option & find_bus(RM3100_BUS bus_id)
Finds a bus structure for a bus_id.
bool reset(RM3100_BUS bus_id)
Resets the driver.