Commit eb5698ae8ff2ebeae0fcd932d3481a228e17a050
Committed by
GitHub
Merge pull request #22 from lotricekCZ/master
Added InWaiting and option for shared library (CMake)
Showing
3 changed files
with
22 additions
and
1 deletions
include/CppLinuxSerial/SerialPort.hpp
| @@ -168,6 +168,9 @@ namespace mn { | @@ -168,6 +168,9 @@ namespace mn { | ||
| 168 | /// \throws CppLinuxSerial::Exception if state != OPEN. | 168 | /// \throws CppLinuxSerial::Exception if state != OPEN. |
| 169 | void ReadBinary(std::vector<uint8_t>& data); | 169 | void ReadBinary(std::vector<uint8_t>& data); |
| 170 | 170 | ||
| 171 | + /// \brief Use to get number of bytes available in buffer | ||
| 172 | + /// \throws CppLinuxSerial::Exception if state != OPEN. | ||
| 173 | + int32_t InWaiting(); | ||
| 171 | private: | 174 | private: |
| 172 | 175 | ||
| 173 | /// \brief Returns a populated termios structure for the passed in file descriptor. | 176 | /// \brief Returns a populated termios structure for the passed in file descriptor. |
src/CMakeLists.txt
| @@ -6,7 +6,16 @@ file(GLOB_RECURSE CppLinuxSerial_SRC | @@ -6,7 +6,16 @@ file(GLOB_RECURSE CppLinuxSerial_SRC | ||
| 6 | file(GLOB_RECURSE CppLinuxSerial_HEADERS | 6 | file(GLOB_RECURSE CppLinuxSerial_HEADERS |
| 7 | "${CMAKE_SOURCE_DIR}/include/*.hpp") | 7 | "${CMAKE_SOURCE_DIR}/include/*.hpp") |
| 8 | 8 | ||
| 9 | -add_library(CppLinuxSerial ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS}) | 9 | +option(SERIAL_BUILD_SHARED_LIBS "Build CppLinuxSerial shared library" OFF) |
| 10 | + | ||
| 11 | +if (SERIAL_BUILD_SHARED_LIBS) | ||
| 12 | + set(LibType SHARED) | ||
| 13 | +else() | ||
| 14 | + set(LibType STATIC) | ||
| 15 | +endif() | ||
| 16 | + | ||
| 17 | +add_library(CppLinuxSerial ${LibType} ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS}) | ||
| 18 | + | ||
| 10 | 19 | ||
| 11 | target_include_directories(CppLinuxSerial PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>" | 20 | target_include_directories(CppLinuxSerial PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>" |
| 12 | "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>") | 21 | "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>") |
src/SerialPort.cpp
| @@ -629,6 +629,15 @@ namespace CppLinuxSerial { | @@ -629,6 +629,15 @@ namespace CppLinuxSerial { | ||
| 629 | THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called while state == OPEN."); | 629 | THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called while state == OPEN."); |
| 630 | timeout_ms_ = timeout_ms; | 630 | timeout_ms_ = timeout_ms; |
| 631 | } | 631 | } |
| 632 | + | ||
| 633 | + int32_t SerialPort::InWaiting() { | ||
| 634 | + if(state_ != State::OPEN) | ||
| 635 | + THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called but state != OPEN. Please call Open() first."); | ||
| 636 | + int32_t ret = 0; | ||
| 637 | + ioctl(fileDesc_, FIONREAD, &ret); | ||
| 638 | + return ret; | ||
| 639 | + | ||
| 640 | + } | ||
| 632 | 641 | ||
| 633 | } // namespace CppLinuxSerial | 642 | } // namespace CppLinuxSerial |
| 634 | } // namespace mn | 643 | } // namespace mn |