42 #include <px4_platform_common/px4_config.h> 43 #include <px4_platform_common/log.h> 44 #include <px4_platform_common/module.h> 54 #include <arch/board/board.h> 65 static int do_gyro(
int argc,
char *argv[]);
66 static int do_accel(
int argc,
char *argv[]);
67 static int do_mag(
int argc,
char *argv[]);
68 static int do_device(
int argc,
char *argv[]);
74 bool is_device_cmd = argc >= 2 && (!strcmp(argv[1],
"block") || !strcmp(argv[1],
"unblock"));
77 if (!is_device_cmd && !strncmp(argv[2],
"/dev/gyro", 9)) {
78 return do_gyro(argc - 1, argv + 1);
80 }
else if (!is_device_cmd && !strncmp(argv[2],
"/dev/accel", 10)) {
83 }
else if (!is_device_cmd && !strncmp(argv[2],
"/dev/mag", 8)) {
84 return do_mag(argc - 1, argv + 1);
97 PRINT_MODULE_DESCRIPTION(
"Configure a sensor driver (sampling & publication rate, range, etc.)");
99 PRINT_MODULE_USAGE_NAME(
"config",
"command");
100 PRINT_MODULE_USAGE_PARAM_COMMENT(
"The <file:dev> argument is typically one of /dev/{gyro,accel,mag}i");
102 PRINT_MODULE_USAGE_COMMAND_DESCR(
"block",
"Block sensor topic publication");
103 PRINT_MODULE_USAGE_ARG(
"<file:dev>",
"Sensor device file",
false);
104 PRINT_MODULE_USAGE_COMMAND_DESCR(
"unblock",
"Unblock sensor topic publication");
105 PRINT_MODULE_USAGE_ARG(
"<file:dev>",
"Sensor device file",
false);
107 PRINT_MODULE_USAGE_COMMAND_DESCR(
"sampling",
"Set sensor sampling rate");
108 PRINT_MODULE_USAGE_ARG(
"<file:dev> <rate>",
"Sensor device file and sampling rate in Hz",
false);
109 PRINT_MODULE_USAGE_COMMAND_DESCR(
"rate",
"Set sensor publication rate");
110 PRINT_MODULE_USAGE_ARG(
"<file:dev> <rate>",
"Sensor device file and publication rate in Hz",
false);
111 PRINT_MODULE_USAGE_COMMAND_DESCR(
"range",
"Set sensor measurement range");
112 PRINT_MODULE_USAGE_ARG(
"<file:dev> <rate>",
"Sensor device file and range",
false);
113 PRINT_MODULE_USAGE_COMMAND_DESCR(
"check",
"Perform sensor self-test (and print info)");
114 PRINT_MODULE_USAGE_ARG(
"<file:dev>",
"Sensor device file",
false);
127 fd = open(argv[1], 0);
130 PX4_ERR(
"open %s failed (%i)", argv[1], errno);
137 if (argc == 2 && !strcmp(argv[0],
"block")) {
140 ret = ioctl(fd, DEVIOCSPUBBLOCK, 1);
143 PX4_ERR(
"uORB publications could not be blocked");
147 }
else if (argc == 2 && !strcmp(argv[0],
"unblock")) {
150 ret = ioctl(fd, DEVIOCSPUBBLOCK, 0);
153 PX4_ERR(
"uORB publications could not be unblocked");
171 fd = open(argv[1], 0);
174 PX4_ERR(
"open %s failed (%i)", argv[1], errno);
181 if (argc == 3 && !strcmp(argv[0],
"rate")) {
187 PX4_ERR(
"pollrate could not be set");
196 int id = ioctl(fd, DEVIOCGDEVICEID, 0);
197 int32_t calibration_id = 0;
201 PX4_INFO(
"gyro: \n\tdevice id:\t0x%X\t(calibration is for device id 0x%X)",
215 fd = open(argv[1], 0);
218 PX4_ERR(
"open %s failed (%i)", argv[1], errno);
225 if (argc == 3 && !strcmp(argv[0],
"rate")) {
231 PX4_ERR(
"pollrate could not be set");
235 }
else if (argc == 3 && !strcmp(argv[0],
"range")) {
238 ret = ioctl(fd,
MAGIOCSRANGE, strtoul(argv[2], NULL, 0));
241 PX4_ERR(
"range could not be set");
250 int id = ioctl(fd, DEVIOCGDEVICEID, 0);
251 int32_t calibration_id = 0;
255 PX4_INFO(
"mag: \n\tdevice id:\t0x%X\t(calibration is for device id 0x%X)",
269 fd = open(argv[1], 0);
272 PX4_ERR(
"open %s failed (%i)", argv[1], errno);
279 if (argc == 3 && !strcmp(argv[0],
"rate")) {
285 PX4_ERR(
"pollrate could not be set");
294 int id = ioctl(fd, DEVIOCGDEVICEID, 0);
295 int32_t calibration_id = 0;
299 PX4_INFO(
"accel: \n\tdevice id:\t0x%X\t(calibration is for device id 0x%X)",
Accelerometer driver interface.
Gyroscope driver interface.
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
static int do_gyro(int argc, char *argv[])
static int do_accel(int argc, char *argv[])
Global flash based parameter store.
static int do_mag(int argc, char *argv[])
static int do_device(int argc, char *argv[])
#define MAGIOCSRANGE
set the measurement range to handle (at least) arg Gauss
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
Generic device / sensor interface.
__EXPORT int config_main(int argc, char *argv[])
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
static void print_usage(void)