|
M5Unit-RS485 0.2.0 git rev:0956c20
|
Non-instantiable base class for RS-485 transceiver units. More...
#include <rs485_component.hpp>
Classes | |
| struct | byteswap_none_tag |
| struct | byteswap_tag_of |
| struct | byteswap_value_tag |
| struct | config_t |
| Settings for begin. More... | |
Public Member Functions | |
| virtual | ~RS485Component ()=default |
| Destructor. | |
| virtual bool | begin () override |
| Begin using the registered UART adapter. | |
Constructor | |
| |
| RS485Component (const RS485Component &)=delete | |
| Deleted: a component owns its serial backend, so it cannot be copied. | |
Assignment | |
| |
| RS485Component & | operator= (const RS485Component &)=delete |
| Deleted: a component owns its serial backend, so it cannot be copied. | |
Settings for begin | |
| config_t | config () const |
| Gets the configuration. | |
| void | config (const config_t &cfg) |
| Sets the configuration. | |
Arduino Serial Compatibility API | |
| |
| operator bool () const | |
| Returns true if the unit is registered. | |
| uint32_t | baudRate () const |
| Returns the baud rate the serial port is running at. | |
| int | available () |
| Returns the number of available bytes to read. | |
| int | availableForWrite () |
| Returns the number of bytes that can be written without blocking. | |
| int | peek () |
| Peeks the next incoming byte without removing it. | |
| int | read () |
| Reads one byte. | |
| size_t | read (uint8_t *buffer, const size_t size) |
| Reads up to size bytes into buffer. | |
| size_t | read (char *buffer, const size_t size) |
| Reads up to size bytes into buffer. | |
| size_t | readBytes (uint8_t *buffer, const size_t length) |
| Reads bytes with timeout defined by underlying Serial. | |
| size_t | readBytes (char *buffer, const size_t length) |
| Reads bytes with timeout defined by underlying Serial. | |
| size_t | readBytes (uint8_t *buffer, const size_t length, const uint32_t timeout_ms) |
| Reads bytes with an explicit timeout. | |
| size_t | readBytes (char *buffer, const size_t length, const uint32_t timeout_ms) |
| Reads bytes with an explicit timeout. | |
| void | flush () |
| Flushes the serial port. | |
| void | flush (const bool txOnly) |
| Flushes the serial port. | |
| size_t | write (const uint8_t d) |
| Writes one byte. | |
| size_t | write (const uint8_t *buffer, const size_t size) |
| Writes bytes from buffer. | |
| size_t | write (const char *buffer, const size_t size) |
| Writes bytes from buffer. | |
| size_t | write (const char *s) |
| Writes a null-terminated string. | |
| template<typename Size , typename std::enable_if<!std::is_integral< Size >::value||std::is_same< Size, char >::value||std::is_same< Size, signed char >::value||std::is_same< Size, bool >::value, int >::type = 0> | |
| size_t | write (const uint8_t *buffer, const Size size)=delete |
| Deleted: the second argument of write() is a byte count. | |
| template<typename Size , typename std::enable_if<!std::is_integral< Size >::value||std::is_same< Size, char >::value||std::is_same< Size, signed char >::value, int >::type = 0> | |
| size_t | write (const char *buffer, const Size size)=delete |
| Deleted: the second argument of write() is a byte count. | |
Deprecated Arduino Serial Compatibility API | |
| template<typename Wait , typename std::enable_if< std::is_same< Wait, bool >::value, int >::type = 0> | |
| size_t | write (const uint8_t d, const Wait wait) |
| Writes one byte, optionally waiting for the transmission to complete. | |
| size_t | write (const uint8_t *buffer, const size_t size, const bool wait) |
| Writes bytes from buffer, optionally waiting for the transmission to complete. | |
| size_t | write (const char *buffer, const size_t size, const bool wait) |
| Writes bytes from buffer, optionally waiting for the transmission to complete. | |
| template<typename Wait , typename std::enable_if< std::is_same< Wait, bool >::value, int >::type = 0> | |
| size_t | write (const char *s, const Wait wait) |
| Writes a null-terminated string, optionally waiting for the transmission to complete. | |
Read/Write a trivially copyable value | |
| template<typename T , bool LittleEndian = true> | |
| bool | readValue (T &value) |
| Read a trivially copyable value. | |
| template<typename T , bool LittleEndian = true> | |
| bool | writeValue (const T value) |
| Write a trivially copyable value. | |
Protected Member Functions | |
| RS485Component (const uint8_t addr) | |
| Base constructor (concrete subclasses pass their DEFAULT_ADDRESS) | |
| RS485Component (RS485Component &&other) noexcept | |
| Move constructor. | |
| RS485Component & | operator= (RS485Component &&other) noexcept |
| Move assignment. | |
| size_t | write_waiting (const uint8_t *buffer, const size_t size) |
| ISerial * | iserial () |
| void | install_serial (std::unique_ptr< ISerial > serial) |
| Installs a serial backend, taking over ownership and replacing the current one. | |
| virtual std::unique_ptr< ISerial > | make_serial (AdapterUART *ad) |
| Factory hook: build the concrete ISerial to be used by begin(). | |
Static Protected Member Functions | |
| template<typename T > | |
| static T | byteswap_if_needed (T v) |
| template<typename T > | |
| static T | byteswap_if_needed_impl (T v, byteswap_value_tag) |
| template<typename T > | |
| static T | byteswap_if_needed_impl (T v, byteswap_none_tag) |
Protected Attributes | |
| config_t | _cfg {} |
Non-instantiable base class for RS-485 transceiver units.
|
protectednoexcept |
Move constructor.
| other | Component to move from |
The serial backend is taken over and told about its new owner, so a backend that points back at the component it serves (UnitSIT3088 drives the DIR pin through the unit) follows the move. The moved-from component is left with the null-behavior backend, so its Serial-compatible methods keep answering.
|
inline |
Returns the number of available bytes to read.
|
inline |
Returns the number of bytes that can be written without blocking.
|
inline |
Returns the baud rate the serial port is running at.
|
overridevirtual |
Begin using the registered UART adapter.
Reimplemented in m5::unit::UnitSIT3088.
|
inline |
Gets the configuration.
|
inline |
Sets the configuration.
| cfg | Configuration settings |
|
inline |
Flushes the serial port.
| txOnly | If true, flush only TX |
|
protected |
Installs a serial backend, taking over ownership and replacing the current one.
| serial | Backend to install, typically the result of make_serial() |
|
protectedvirtual |
Factory hook: build the concrete ISerial to be used by begin().
| ad | AdapterUART obtained via asAdapter<AdapterUART>() (never null at call site) |
Reimplemented in m5::unit::UnitSIT3088.
|
protectednoexcept |
Move assignment.
| other | Component to move from |
Hands over the serial backend as the move constructor does, and releases the backend this component held.
|
inline |
Peeks the next incoming byte without removing it.
|
inline |
Reads one byte.
|
inline |
Reads up to size bytes into buffer.
| buffer | Destination buffer |
| size | Maximum number of bytes to read |
|
inline |
Reads up to size bytes into buffer.
| buffer | Destination buffer |
| size | Maximum number of bytes to read |
|
inline |
Reads bytes with timeout defined by underlying Serial.
| buffer | Destination buffer |
| length | Number of bytes to read |
|
inline |
Reads bytes with an explicit timeout.
| buffer | Destination buffer |
| length | Number of bytes to read |
| timeout_ms | Maximum time to wait for the requested bytes |
|
inline |
Reads bytes with timeout defined by underlying Serial.
| buffer | Destination buffer |
| length | Number of bytes to read |
|
inline |
Reads bytes with an explicit timeout.
| buffer | Destination buffer |
| length | Number of bytes to read |
| timeout_ms | Maximum time to wait for the requested bytes |
|
inline |
Read a trivially copyable value.
| T | Type (must be trivially copyable and standard-layout) |
| LittleEndian | Incoming data is little-endian if true |
| value | Receive variable |
|
delete |
Deleted: the second argument of write() is a byte count.
The same rule as write(const uint8_t *, const Size), except that bool is still accepted here: write(s, wait) is a released signature, so the deprecated overload below has to keep binding it. For a uint8_t buffer the wait form was always write(buffer, size, wait), so there bool is rejected.
| size_t m5::unit::RS485Component::write | ( | const char * | buffer, |
| const size_t | size ) |
Writes bytes from buffer.
| buffer | Source buffer |
| size | Number of bytes to write |
|
inline |
Writes bytes from buffer, optionally waiting for the transmission to complete.
| buffer | Source buffer |
| size | Number of bytes to write |
| wait | If true, wait for TX to drain before returning |
| size_t m5::unit::RS485Component::write | ( | const char * | s | ) |
Writes a null-terminated string.
| s | Null-terminated string |
|
inline |
Writes a null-terminated string, optionally waiting for the transmission to complete.
| s | Null-terminated string |
| wait | If true, wait for TX to drain before returning |
|
delete |
Deleted: the second argument of write() is a byte count.
Rejects what cannot be a count – char and signed char (write(buffer, 'a') would otherwise mean 97 bytes), bool, and any non-integral type, including the bool-convertible proxies of std::vector<bool> / std::bitset<N>, which used to slip through as a length. An integer length is filtered out by SFINAE and keeps resolving to write(const uint8_t *, size_t).
| size_t m5::unit::RS485Component::write | ( | const uint8_t * | buffer, |
| const size_t | size ) |
Writes bytes from buffer.
| buffer | Source buffer |
| size | Number of bytes to write |
|
inline |
Writes bytes from buffer, optionally waiting for the transmission to complete.
| buffer | Source buffer |
| size | Number of bytes to write |
| wait | If true, wait for TX to drain before returning |
| size_t m5::unit::RS485Component::write | ( | const uint8_t | d | ) |
Writes one byte.
| d | Byte to write |
|
inline |
Writes one byte, optionally waiting for the transmission to complete.
| d | Byte to write |
| wait | If true, wait for TX to drain before returning |
|
inline |
Write a trivially copyable value.
| T | Type (must be trivially copyable and standard-layout) |
| LittleEndian | Outgoing data is little-endian if true |
| value | Value to write |