Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Fix clang-tidy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hhenry01 committed Nov 4, 2023
1 parent 64fd6fd commit e8b24bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 11 additions & 1 deletion projects/local_transceiver/inc/local_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ class LocalTransceiver
LocalTransceiver(const std::string & port_name, uint32_t baud_rate);

/**
* @brief Destroy the Local Transceiver object and close the serial port
* @brief Destroy the Local Transceiver object
*
* @note must call stop() to properly cleanup the object
*
*/
~LocalTransceiver();

/**
* @brief Cleanup the Local Transceiver object by closing the serial port
*
* @note must be called before the object is destroyed
*
*/
void stop();

/**
* @brief Callback function for when new sensor data is received from the ROS network on Polaris
*
Expand Down
13 changes: 12 additions & 1 deletion projects/local_transceiver/src/local_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/asio/serial_port.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/system/error_code.hpp>
#include <exception>
#include <mutex>
#include <stdexcept>
Expand Down Expand Up @@ -59,7 +60,17 @@ LocalTransceiver::LocalTransceiver(const std::string & port_name, const uint32_t
serial_.set_option(bio::serial_port_base::baud_rate(baud_rate));
};

LocalTransceiver::~LocalTransceiver() { serial_.close(); }
LocalTransceiver::~LocalTransceiver()
{
// Intentionally left blank
}

void LocalTransceiver::stop()
{
std::lock_guard<std::mutex> lock(serial_mtx_);
// TODO(Jng468): Flush the serial port
serial_.close(); // Can throw an exception so cannot be put in the destructor
}

template <typename T>
void LocalTransceiver::onNewSensorData(T sensor)
Expand Down
6 changes: 5 additions & 1 deletion projects/local_transceiver/test/test_local_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class TestLocalTransceiver : public ::testing::Test
<< RUN_VIRTUAL_IRIDIUM_SCRIPT_PATH << "\" running?" << std::endl;
}
}
~TestLocalTransceiver() override { delete lcl_trns_; }
~TestLocalTransceiver() override
{
lcl_trns_->stop();
delete lcl_trns_;
}

LocalTransceiver * lcl_trns_;
};
Expand Down

0 comments on commit e8b24bc

Please sign in to comment.