COSA
An Object-Oriented Platform for Arduino Programming
|
#include <RS485.hh>
Classes | |
struct | header_t |
Public Types | |
enum | { DATA5 = 0, DATA6 = _BV(UCSZ00), DATA7 = _BV(UCSZ01), DATA8 = _BV(UCSZ01) | _BV(UCSZ00), NO_PARITY = 0, EVEN_PARITY = _BV(UPM01), ODD_PARITY = _BV(UPM01) | _BV(UPM00), STOP1 = 0, STOP2 = _BV(USBS0) } |
Public Member Functions | |
RS485 (uint8_t port, IOStream::Device *ibuf, IOStream::Device *obuf, uint16_t size, Board::DigitalPin de, uint8_t addr=MASTER) | |
virtual int | putchar (char c) |
void | address (uint8_t addr=MASTER) |
int | send (const void *buf, size_t len, uint8_t dest=MASTER) |
int | broadcast (const void *buf, size_t len) |
int | recv (void *buf, size_t len, uint32_t ms=0L) |
virtual int | available () |
virtual int | room () |
virtual int | peekchar () |
virtual int | peekchar (char c) |
virtual int | getchar () |
virtual int | flush () |
virtual void | empty () |
virtual bool | begin (uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT) |
virtual bool | end () |
virtual void | powerup () |
virtual void | powerdown () |
void | non_blocking () |
void | blocking () |
bool | is_blocking () const |
void | eol (Mode mode) |
Mode | eol () const |
virtual int | puts (const char *s) |
virtual int | puts (str_P s) |
virtual int | write (const void *buf, size_t size) |
virtual int | write (const iovec_t *vec) |
virtual int | write_P (const void *buf, size_t size) |
virtual char * | gets (char *s, size_t count) |
virtual int | read (void *buf, size_t size) |
virtual int | read (iovec_t *vec) |
Static Public Attributes | |
static const uint8_t | SOT = 0x01 |
static const uint8_t | FRAME_MAX = sizeof(header_t) + sizeof(uint16_t) + 1 |
static const uint16_t | BUFFER_MAX = COSA_RS485_BUFFER_MAX |
static const uint8_t | BROADCAST = 0 |
static const uint8_t | MASTER = 255 |
static const uint16_t | RX_BUFFER_MAX = COSA_UART_RX_BUFFER_MAX |
static const uint16_t | TX_BUFFER_MAX = COSA_UART_TX_BUFFER_MAX |
static const uint32_t | DEFAULT_BAUDRATE = 9600L |
static const uint8_t | DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2 |
Protected Member Functions | |
virtual void | on_udre_interrupt () |
virtual void | on_tx_interrupt () |
virtual void | on_transmit_completed () |
volatile uint8_t * | UCSRnA () const |
volatile uint8_t * | UCSRnB () const |
volatile uint8_t * | UCSRnC () const |
volatile uint16_t * | UBRRn () const |
volatile uint8_t * | UDRn () const |
virtual void | on_rx_interrupt () |
Protected Attributes | |
const uint16_t | PAYLOAD_MAX |
header_t | m_header |
OutputPin | m_de |
uint8_t | m_addr |
uint8_t | m_state |
uint8_t | m_port |
UART port index. More... | |
volatile uint8_t *const | m_sfr |
Special Function Register Pointer. More... | |
IOStream::Device * | m_ibuf |
Input Buffer/Device. More... | |
IOStream::Device * | m_obuf |
Output Buffer/Device. More... | |
bool | m_idle |
Flag idle mode. More... | |
bool | m_blocking |
Mode | m_eol |
Static Protected Attributes | |
static UART * | uart [Board::UART_MAX] = { NULL } |
RS485 link handler; Master-Slave protocol. Master always initiates communication with request message to Slave who responds. The Master may also broadcast messages to all slave devices. The message format is; <header,payload,crc> where header contains the length of the payload, the destination and source device address or the broadcast address(0x00), the source device address and a 8-bit CRC7 check-sum for the header. The payload is the message data and a 16-bit payload CCITT/XMODEM check-sum.
|
inherited |
|
inline |
|
inline |
|
inlinevirtualinherited |
|
virtualinherited |
|
inlineinherited |
Set blocking mode.
Definition at line 85 of file IOStream.hh.
|
inline |
|
inlinevirtualinherited |
Empty output device buffers.
Reimplemented from IOStream::Device.
|
virtualinherited |
|
inlineinherited |
Set end of line mode.
[in] | mode | for end of line. |
Definition at line 103 of file IOStream.hh.
|
inlineinherited |
|
virtualinherited |
Flush device output buffer and wait for device to become idle and all character transmitted.
Reimplemented from IOStream::Device.
|
inlinevirtualinherited |
Read character from serial port input buffer. Returns character if successful otherwise a negative error code (EOF(-1)).
Reimplemented from IOStream::Device.
|
virtualinherited |
Read string terminated by new-line or until size into given string buffer. Returns pointer to string or NULL if empty line.
[in] | s | string buffer to read into. |
[in] | count | max number of bytes to read. |
Definition at line 118 of file IOStream_Device.cpp.
|
inlineinherited |
|
inlineinherited |
Set non-blocking mode.
Definition at line 77 of file IOStream.hh.
|
protectedvirtualinherited |
|
inlineprotectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
inlinevirtualinherited |
Peek at next character from serial port input buffer. Returns character if successful otherwise a negative error code (EOF(-1)).
Reimplemented from IOStream::Device.
|
inlinevirtualinherited |
Peek for given character from serial port input buffer.
[in] | c | character to peek for. |
Reimplemented from IOStream::Device.
|
virtualinherited |
|
virtualinherited |
|
virtual |
|
virtualinherited |
Write null terminated string to device. Terminating null is not written.
[in] | s | string to write. |
Definition at line 43 of file IOStream_Device.cpp.
|
virtualinherited |
Write null terminated string from program memory to device. Terminating null is not written.
[in] | s | string in program memory to write. |
Definition at line 54 of file IOStream_Device.cpp.
|
virtualinherited |
Read data to given buffer with given size from device.
[in] | buf | buffer to read into. |
[in] | size | number of bytes to read. |
Reimplemented in FAT16::File, W5200::Driver, W5500::Driver, W5100::Driver, CFFS::File, Socket, and CC3000::Driver.
Definition at line 144 of file IOStream_Device.cpp.
|
virtualinherited |
Read data to given buffers in null terminated io vector.
[in] | vec | io vector with buffers to read into. |
Definition at line 157 of file IOStream_Device.cpp.
int RS485::recv | ( | void * | buf, |
size_t | len, | ||
uint32_t | ms = 0L |
||
) |
Attempt within given time-limit in milli-seconds receive a message. If received the message is stored in the given buffer with given max length. Returns the number of bytes received or negative error code.
[in] | buf | pointer to message buffer. |
[in] | len | number of bytes. |
[in] | ms | number of milli-seconds timeout (Default BLOCK). |
|
inlinevirtualinherited |
int RS485::send | ( | const void * | buf, |
size_t | len, | ||
uint8_t | dest = MASTER |
||
) |
Send message in given buffer and number of bytes to given destination device. Return number of bytes sent or negative error code.
[in] | buf | pointer to message buffer. |
[in] | len | number of bytes. |
[in] | dest | destination node (Default MASTER). |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
virtualinherited |
Write data from buffer with given size to device.
[in] | buf | buffer to write. |
[in] | size | number of bytes to write. |
Reimplemented in FAT16::File, HD44780, CFFS::File, VLCD, Socket, and CC3000::Driver.
Definition at line 65 of file IOStream_Device.cpp.
|
virtualinherited |
Write data from buffers in null terminated io vector.
[in] | vec | io vector with buffers to write. |
Definition at line 87 of file IOStream_Device.cpp.
|
virtualinherited |
Write data from buffer in program memory with given size to device.
[in] | buf | buffer to write. |
[in] | size | number of bytes to write. |
Reimplemented in CFFS::File, Socket, and CC3000::Driver.
Definition at line 76 of file IOStream_Device.cpp.
|
static |
|
static |
|
staticinherited |
|
static |
|
protected |
|
protectedinherited |
Blocking state
Definition at line 248 of file IOStream.hh.
|
protected |
|
protectedinherited |
End of line mode
Definition at line 251 of file IOStream.hh.
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
static |
|
protected |
|
staticinherited |
|
static |
|
staticinherited |