diff options
author | Lorenz Meier <lorenz@px4.io> | 2015-04-13 12:28:51 +0200 |
---|---|---|
committer | Lorenz Meier <lorenz@px4.io> | 2015-04-13 12:28:51 +0200 |
commit | 3c36a615692d746996e4d32a97e8e24285330913 (patch) | |
tree | 62514ce1aa2552c60de428a647fdf8b160381cc0 /src | |
parent | ac6ffd36d9f475b658944eb1da9ffb6da8afcb77 (diff) | |
parent | 8fd6b3da212cde1b164431bdb5ba909178dc4199 (diff) | |
download | px4-firmware-3c36a615692d746996e4d32a97e8e24285330913.tar.gz px4-firmware-3c36a615692d746996e4d32a97e8e24285330913.tar.bz2 px4-firmware-3c36a615692d746996e4d32a97e8e24285330913.zip |
Merge pull request #2017 from UAVenture/sf02_fix
Store the port so the in use port will be referenced when reopening.
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/sf0x/sf0x.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/drivers/sf0x/sf0x.cpp b/src/drivers/sf0x/sf0x.cpp index d6599c036..66641d640 100644 --- a/src/drivers/sf0x/sf0x.cpp +++ b/src/drivers/sf0x/sf0x.cpp @@ -114,6 +114,7 @@ protected: virtual int probe(); private: + char _port[20]; float _min_distance; float _max_distance; work_s _work; @@ -199,8 +200,13 @@ SF0X::SF0X(const char *port) : _comms_errors(perf_alloc(PC_COUNT, "sf0x_comms_errors")), _buffer_overflows(perf_alloc(PC_COUNT, "sf0x_buffer_overflows")) { + /* store port name */ + strncpy(_port, port, sizeof(_port)); + /* enforce null termination */ + _port[sizeof(_port) - 1] = '\0'; + /* open fd */ - _fd = ::open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); + _fd = ::open(_port, O_RDWR | O_NOCTTY | O_NONBLOCK); if (_fd < 0) { warnx("FAIL: laser fd"); @@ -633,7 +639,7 @@ SF0X::cycle() /* fds initialized? */ if (_fd < 0) { /* open fd */ - _fd = ::open(SF0X_DEFAULT_PORT, O_RDWR | O_NOCTTY | O_NONBLOCK); + _fd = ::open(_port, O_RDWR | O_NOCTTY | O_NONBLOCK); } /* collection phase? */ |