mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 11:33:33 +08:00
Allow access to both device handles, make external use a special handle
This commit is contained in:
@@ -91,12 +91,13 @@ static const int ERROR = -1;
|
||||
/* internal conversion time: 9.17 ms, so should not be read at rates higher than 100 Hz */
|
||||
#define MS5611_CONVERSION_INTERVAL 10000 /* microseconds */
|
||||
#define MS5611_MEASUREMENT_RATIO 3 /* pressure measurements per temperature measurement */
|
||||
#define MS5611_BARO_DEVICE_PATH "/dev/ms5611"
|
||||
#define MS5611_BARO_DEVICE_PATH_EXT "/dev/ms5611_ext"
|
||||
#define MS5611_BARO_DEVICE_PATH_INT "/dev/ms5611_int"
|
||||
|
||||
class MS5611 : public device::CDev
|
||||
{
|
||||
public:
|
||||
MS5611(device::Device *interface, ms5611::prom_u &prom_buf);
|
||||
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char* path);
|
||||
~MS5611();
|
||||
|
||||
virtual int init();
|
||||
@@ -195,8 +196,8 @@ protected:
|
||||
*/
|
||||
extern "C" __EXPORT int ms5611_main(int argc, char *argv[]);
|
||||
|
||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf) :
|
||||
CDev("MS5611", MS5611_BARO_DEVICE_PATH),
|
||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char* path) :
|
||||
CDev("MS5611", path),
|
||||
_interface(interface),
|
||||
_prom(prom_buf.s),
|
||||
_measure_ticks(0),
|
||||
@@ -224,7 +225,7 @@ MS5611::~MS5611()
|
||||
stop_cycle();
|
||||
|
||||
if (_class_instance != -1)
|
||||
unregister_class_devname(MS5611_BARO_DEVICE_PATH, _class_instance);
|
||||
unregister_class_devname(get_devname(), _class_instance);
|
||||
|
||||
/* free any existing reports */
|
||||
if (_reports != nullptr)
|
||||
@@ -792,10 +793,10 @@ MS5611 *g_dev_ext = nullptr;
|
||||
MS5611 *g_dev_int = nullptr;
|
||||
|
||||
void start(bool external_bus);
|
||||
void test();
|
||||
void reset();
|
||||
void test(bool external_bus);
|
||||
void reset(bool external_bus);
|
||||
void info();
|
||||
void calibrate(unsigned altitude);
|
||||
void calibrate(unsigned altitude, bool external_bus);
|
||||
void usage();
|
||||
|
||||
/**
|
||||
@@ -879,27 +880,34 @@ start(bool external_bus)
|
||||
}
|
||||
|
||||
if (external_bus) {
|
||||
g_dev_ext = new MS5611(interface, prom_buf);
|
||||
g_dev_ext = new MS5611(interface, prom_buf, MS5611_BARO_DEVICE_PATH_EXT);
|
||||
if (g_dev_ext == nullptr) {
|
||||
delete interface;
|
||||
errx(1, "failed to allocate driver");
|
||||
}
|
||||
|
||||
if (g_dev_ext->init() != OK)
|
||||
goto fail;
|
||||
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_EXT, O_RDONLY);
|
||||
|
||||
} else {
|
||||
|
||||
g_dev_int = new MS5611(interface, prom_buf);
|
||||
g_dev_int = new MS5611(interface, prom_buf, MS5611_BARO_DEVICE_PATH_INT);
|
||||
if (g_dev_int == nullptr) {
|
||||
delete interface;
|
||||
errx(1, "failed to allocate driver");
|
||||
}
|
||||
|
||||
if (g_dev_int->init() != OK)
|
||||
goto fail;
|
||||
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_INT, O_RDONLY);
|
||||
|
||||
}
|
||||
|
||||
/* set the poll rate to default, starts automatic data collection */
|
||||
fd = open(MS5611_BARO_DEVICE_PATH, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
warnx("can't open baro device");
|
||||
goto fail;
|
||||
@@ -932,16 +940,22 @@ fail:
|
||||
* and automatic modes.
|
||||
*/
|
||||
void
|
||||
test()
|
||||
test(bool external_bus)
|
||||
{
|
||||
struct baro_report report;
|
||||
ssize_t sz;
|
||||
int ret;
|
||||
|
||||
int fd = open(MS5611_BARO_DEVICE_PATH, O_RDONLY);
|
||||
int fd;
|
||||
|
||||
if (external_bus) {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_EXT, O_RDONLY);
|
||||
} else {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_INT, O_RDONLY);
|
||||
}
|
||||
|
||||
if (fd < 0)
|
||||
err(1, "%s open failed (try 'ms5611 start' if the driver is not running)", MS5611_BARO_DEVICE_PATH);
|
||||
err(1, "open failed (try 'ms5611 start' if the driver is not running)");
|
||||
|
||||
/* do a simple demand read */
|
||||
sz = read(fd, &report, sizeof(report));
|
||||
@@ -995,9 +1009,15 @@ test()
|
||||
* Reset the driver.
|
||||
*/
|
||||
void
|
||||
reset()
|
||||
reset(bool external_bus)
|
||||
{
|
||||
int fd = open(MS5611_BARO_DEVICE_PATH, O_RDONLY);
|
||||
int fd;
|
||||
|
||||
if (external_bus) {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_EXT, O_RDONLY);
|
||||
} else {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_INT, O_RDONLY);
|
||||
}
|
||||
|
||||
if (fd < 0)
|
||||
err(1, "failed ");
|
||||
@@ -1037,16 +1057,22 @@ info()
|
||||
* Calculate actual MSL pressure given current altitude
|
||||
*/
|
||||
void
|
||||
calibrate(unsigned altitude)
|
||||
calibrate(unsigned altitude, bool external_bus)
|
||||
{
|
||||
struct baro_report report;
|
||||
float pressure;
|
||||
float p1;
|
||||
|
||||
int fd = open(MS5611_BARO_DEVICE_PATH, O_RDONLY);
|
||||
int fd;
|
||||
|
||||
if (external_bus) {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_EXT, O_RDONLY);
|
||||
} else {
|
||||
fd = open(MS5611_BARO_DEVICE_PATH_INT, O_RDONLY);
|
||||
}
|
||||
|
||||
if (fd < 0)
|
||||
err(1, "%s open failed (try 'ms5611 start' if the driver is not running)", MS5611_BARO_DEVICE_PATH);
|
||||
err(1, "open failed (try 'ms5611 start' if the driver is not running)");
|
||||
|
||||
/* start the sensor polling at max */
|
||||
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_MAX))
|
||||
@@ -1141,13 +1167,13 @@ ms5611_main(int argc, char *argv[])
|
||||
* Test the driver/device.
|
||||
*/
|
||||
if (!strcmp(verb, "test"))
|
||||
ms5611::test();
|
||||
ms5611::test(external_bus);
|
||||
|
||||
/*
|
||||
* Reset the driver.
|
||||
*/
|
||||
if (!strcmp(verb, "reset"))
|
||||
ms5611::reset();
|
||||
ms5611::reset(external_bus);
|
||||
|
||||
/*
|
||||
* Print driver information.
|
||||
@@ -1164,7 +1190,7 @@ ms5611_main(int argc, char *argv[])
|
||||
|
||||
long altitude = strtol(argv[optind+1], nullptr, 10);
|
||||
|
||||
ms5611::calibrate(altitude);
|
||||
ms5611::calibrate(altitude, external_bus);
|
||||
}
|
||||
|
||||
errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'");
|
||||
|
||||
Reference in New Issue
Block a user