Commit 61f77cb928018d24010edd15c01f1e94307ecc39

Authored by Geoffrey Hunter
Committed by GitHub
2 parents ad1770f8 e1a7d934

Merge pull request #23 from gbmhunter/develop

Release of v2.4.0.
CHANGELOG.md
... ... @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5 5 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6 6 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7 7  
  8 +## [v2.4.0] - 2022-02-12
  9 +
  10 +- Added `Available()` method to return number of bytes ready to be read from the receive buffer (thanks lotricekCZ).
  11 +- Added CMake option for shared library (thanks lotricekCZ).
  12 +
8 13 ## [v2.3.0] - 2021-12-23
9 14  
10 15 - Added support for setting the num. data bits.
... ...
include/CppLinuxSerial/SerialPort.hpp
... ... @@ -168,10 +168,12 @@ namespace mn {
168 168 /// \throws CppLinuxSerial::Exception if state != OPEN.
169 169 void ReadBinary(std::vector<uint8_t>& data);
170 170  
171   - private:
  171 + /// \brief Use to get number of bytes available in receive buffer.
  172 + /// \returns The number of bytes available in the receive buffer (ready to be read).
  173 + /// \throws CppLinuxSerial::Exception if state != OPEN.
  174 + int32_t Available();
172 175  
173   - /// \brief Returns a populated termios structure for the passed in file descriptor.
174   - // termios GetTermios();
  176 + private:
175 177  
176 178 /// \brief Configures the tty device as a serial port.
177 179 /// \warning Device must be open (valid file descriptor) when this is called.
... ...
src/CMakeLists.txt
... ... @@ -6,7 +6,16 @@ file(GLOB_RECURSE CppLinuxSerial_SRC
6 6 file(GLOB_RECURSE CppLinuxSerial_HEADERS
7 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 20 target_include_directories(CppLinuxSerial PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
12 21 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>")
... ...
src/SerialPort.cpp
... ... @@ -629,6 +629,15 @@ namespace CppLinuxSerial {
629 629 THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called while state == OPEN.");
630 630 timeout_ms_ = timeout_ms;
631 631 }
  632 +
  633 + int32_t SerialPort::Available() {
  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 642 } // namespace CppLinuxSerial
634 643 } // namespace mn
... ...