blfwk::UartPeripheral Class Reference

Peripheral that talks to the target device over COM port hardware. More...

`#include <UartPeripheral.h>`

Inheritance diagram for blfwk::UartPeripheral:
[legend]
Collaboration diagram for blfwk::UartPeripheral:
[legend]

## Public Types

enum | _uart_peripheral_constants { kUartPeripheral_UnusedTimeout = 0, kUartPeripheral_DefaultReadTimeoutMs = 1000, kUartPeripheral_DefaultBaudRate = 9600 }
| Constants.
Public Types inherited from blfwk::Peripheral
enum | _host_peripheral_types { kHostPeripheralType_None, kHostPeripheralType_UART, kHostPeripheralType_BUSPAL_UART, kHostPeripheralType_USB_HID, kHostPeripheralType_SIM }

## Public Member Functions

| UartPeripheral (const char *port, long speed=kUartPeripheral_DefaultBaudRate)
| Parameterized constructor that opens the serial port. More...
virtual | ~UartPeripheral ()
| Destructor.
void | flushRX ()
| Flush. More...
virtual status_t | read (uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t unused_timeoutMs)
| Read bytes. More...
virtual status_t | write (const uint8_t *buffer, uint32_t byteCount)
| Write bytes. More...

## Protected Member Functions

bool | init (const char *port, long speed)
| Initialize. More...

## Protected Attributes

int | m_fileDescriptor
| Port file descriptor.
uint8_t | m_buffer [kDefaultMaxPacketSize]
| Buffer for bytes used to build read packet.

## Detailed Description

Peripheral that talks to the target device over COM port hardware.

## Constructor & Destructor Documentation

UartPeripheral::UartPeripheral | ( | const char * | port,
|  | long | speed = `kUartPeripheral_DefaultBaudRate`
| ) |  |

Parameterized constructor that opens the serial port.

Opens and configures the port. Throws exception if port configuration fails.

Note: following COM port configuration is assumed: 8 bits, 1 stop bit, no parity.

Parameters

  port | OS file path for COM port. For example "COM1" on Windows.
  speed | Port speed, e.g. 9600.

## Member Function Documentation

void UartPeripheral::flushRX | ( |  | ) |

Flush.

should be called on an open COM port in order to flush any remaining data in the UART RX buffer

bool UartPeripheral::init | ( | const char * | port,
|  | long | speed
| ) |  |

protected

Initialize.

Opens and configures the port.

Note: following COM port configuration is assumed: 8 bits, 1 stop bit, no parity.

Parameters

  port | OS file path for COM port. For example "COM1" on Windows.
  speed | Port speed, e.g. 9600.

status_t UartPeripheral::read | ( | uint8_t * | buffer,
|  | uint32_t | requestedBytes,
|  | uint32_t * | actualBytes,
|  | uint32_t | unused_timeoutMs
| ) |  |

virtual

Read bytes.

Parameters

  buffer | Pointer to buffer.
  requestedBytes | Number of bytes to read.
  actualBytes | Number of bytes actually read.
  timeoutMs | Time in milliseconds to wait for read to complete.

Implements blfwk::Peripheral.

Reimplemented in blfwk::BusPalUartPeripheral.

status_t UartPeripheral::write | ( | const uint8_t * | buffer,
|  | uint32_t | byteCount
| ) |  |

virtual

Write bytes.

Parameters

  buffer | Pointer to buffer to write
  byteCount | Number of bytes to write

Implements blfwk::Peripheral.

Reimplemented in blfwk::BusPalUartPeripheral.

The documentation for this class was generated from the following files:

- UartPeripheral.h
- UartPeripheral.cpp