ESPHome  2024.12.2
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::weikai::WeikaiChannel Class Reference

The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class. More...

#include <weikai.h>

Inheritance diagram for esphome::weikai::WeikaiChannel:
esphome::uart::UARTComponent

Public Member Functions

void set_parent (WeikaiComponent *parent)
 We belongs to this WeikaiComponent. More...
 
void set_channel (uint8_t channel)
 Sets the channel number. More...
 
void set_channel_name (std::string &&name)
 The name as generated by the Python code generator. More...
 
const char * get_channel_name ()
 Get the channel name. More...
 
virtual void setup_channel ()
 Setup the channel. More...
 
virtual void dump_channel ()
 dump channel information More...
 
WeikaiRegisterreg (uint8_t reg)
 Factory method to create a WeikaiRegister proxy object. More...
 
void write_array (const uint8_t *buffer, size_t length) override
 Writes a specified number of bytes to a serial port. More...
 
bool read_array (uint8_t *buffer, size_t length) override
 Reads a specified number of bytes from a serial port. More...
 
bool peek_byte (uint8_t *buffer) override
 Reads the first byte in FIFO without removing it. More...
 
int available () override
 Returns the number of bytes in the receive buffer. More...
 
void flush () override
 Flush the output fifo. More...
 
- Public Member Functions inherited from esphome::uart::UARTComponent
void write_array (const std::vector< uint8_t > &data)
 
void write_byte (uint8_t data)
 
void write_str (const char *str)
 
bool read_byte (uint8_t *data)
 
void set_tx_pin (InternalGPIOPin *tx_pin)
 
void set_rx_pin (InternalGPIOPin *rx_pin)
 
void set_rx_buffer_size (size_t rx_buffer_size)
 
size_t get_rx_buffer_size ()
 
void set_stop_bits (uint8_t stop_bits)
 
uint8_t get_stop_bits () const
 
void set_data_bits (uint8_t data_bits)
 
uint8_t get_data_bits () const
 
void set_parity (UARTParityOptions parity)
 
UARTParityOptions get_parity () const
 
void set_baud_rate (uint32_t baud_rate)
 
uint32_t get_baud_rate () const
 
virtual void load_settings (bool dump_config)
 Load the UART settings. More...
 
virtual void load_settings ()
 Load the UART settings. More...
 
void add_debug_callback (std::function< void(UARTDirection, uint8_t)> &&callback)
 

Protected Member Functions

void check_logger_conflict () override
 this cannot happen with external uart therefore we do nothing More...
 
void reset_fifo_ ()
 reset the weikai internal FIFO More...
 
void set_line_param_ ()
 set the line parameters More...
 
void set_baudrate_ ()
 set the baud rate More...
 
size_t rx_in_fifo_ ()
 Returns the number of bytes in the receive fifo. More...
 
size_t tx_in_fifo_ ()
 Returns the number of bytes in the transmit fifo. More...
 
bool tx_fifo_is_not_empty_ ()
 test if transmit buffer is not empty in the status register (optimization) More...
 
size_t xfer_fifo_to_buffer_ ()
 transfer bytes from the weikai internal FIFO to the buffer (if any) More...
 
virtual bool check_channel_down ()
 check if channel is alive More...
 
void uart_send_test_ (char *message)
 Test the write_array() method. More...
 
bool uart_receive_test_ (char *message)
 Test the read_array() method. More...
 
- Protected Member Functions inherited from esphome::uart::UARTComponent
bool check_read_timeout_ (size_t len=1)
 

Protected Attributes

WKRingBuffer< uint8_t, RING_BUFFER_SIZEreceive_buffer_
 the buffer where we store temporarily the bytes received More...
 
WeikaiComponentparent_
 our WK2168component parent More...
 
uint8_t channel_
 our Channel number More...
 
uint8_t data_
 a one byte buffer for register read storage More...
 
std::string name_
 name of the entity More...
 
- Protected Attributes inherited from esphome::uart::UARTComponent
InternalGPIOPintx_pin_
 
InternalGPIOPinrx_pin_
 
size_t rx_buffer_size_
 
uint32_t baud_rate_
 
uint8_t stop_bits_
 
uint8_t data_bits_
 
UARTParityOptions parity_
 
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_ {}
 

Detailed Description

The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class.

This class is common to the different members of the Weikai components family and therefore avoid code duplication.

Definition at line 296 of file weikai.h.

Member Function Documentation

◆ available()

int esphome::weikai::WeikaiChannel::available ( )
overridevirtual

Returns the number of bytes in the receive buffer.

Returns
the number of bytes available in the receiver fifo

Implements esphome::uart::UARTComponent.

Definition at line 451 of file weikai.cpp.

◆ check_channel_down()

bool esphome::weikai::WeikaiChannel::check_channel_down ( )
protectedvirtual

check if channel is alive

Returns
true if OK

Definition at line 425 of file weikai.cpp.

◆ check_logger_conflict()

void esphome::weikai::WeikaiChannel::check_logger_conflict ( )
inlineoverrideprotectedvirtual

this cannot happen with external uart therefore we do nothing

Implements esphome::uart::UARTComponent.

Definition at line 388 of file weikai.h.

◆ dump_channel()

void esphome::weikai::WeikaiChannel::dump_channel ( )
virtual

dump channel information

Definition at line 321 of file weikai.cpp.

◆ flush()

void esphome::weikai::WeikaiChannel::flush ( )
overridevirtual

Flush the output fifo.

If we refer to Serial.flush() in Arduino it says: ** Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this the method was removing any buffered incoming serial data.). ** Therefore we wait until all bytes are gone with a timeout of 100 ms

Implements esphome::uart::UARTComponent.

Definition at line 483 of file weikai.cpp.

◆ get_channel_name()

const char* esphome::weikai::WeikaiChannel::get_channel_name ( )
inline

Get the channel name.

Returns
the name

Definition at line 315 of file weikai.h.

◆ peek_byte()

bool esphome::weikai::WeikaiChannel::peek_byte ( uint8_t *  buffer)
overridevirtual

Reads the first byte in FIFO without removing it.

Parameters
bufferpointer to the byte
Returns
true if succeed reading one byte, false if no character available

This method returns the next byte from receiving buffer without removing it from the internal fifo. It returns true if a character is available and has been read, false otherwise.

Implements esphome::uart::UARTComponent.

Definition at line 444 of file weikai.cpp.

◆ read_array()

bool esphome::weikai::WeikaiChannel::read_array ( uint8_t *  buffer,
size_t  length 
)
overridevirtual

Reads a specified number of bytes from a serial port.

Parameters
bufferbuffer to store the bytes
lengthnumber of bytes to read
Returns
true if succeed, false otherwise

Typical usage:

// ...
auto length = available();
uint8_t buffer[128];
if (length > 0) {
auto status = read_array(&buffer, length)
// test status ...
}

Implements esphome::uart::UARTComponent.

Definition at line 458 of file weikai.cpp.

◆ reg()

WeikaiRegister& esphome::weikai::WeikaiChannel::reg ( uint8_t  reg)
inline

Factory method to create a WeikaiRegister proxy object.

Parameters
regaddress of the register
Returns
a reference to WeikaiRegister

Definition at line 326 of file weikai.h.

◆ reset_fifo_()

void esphome::weikai::WeikaiChannel::reset_fifo_ ( )
protected

reset the weikai internal FIFO

Definition at line 329 of file weikai.cpp.

◆ rx_in_fifo_()

size_t esphome::weikai::WeikaiChannel::rx_in_fifo_ ( )
protected

Returns the number of bytes in the receive fifo.

Returns
the number of bytes in the fifo

Definition at line 397 of file weikai.cpp.

◆ set_baudrate_()

void esphome::weikai::WeikaiChannel::set_baudrate_ ( )
protected

set the baud rate

Definition at line 356 of file weikai.cpp.

◆ set_channel()

void esphome::weikai::WeikaiChannel::set_channel ( uint8_t  channel)
inline

Sets the channel number.

Parameters
channelnumber

Definition at line 307 of file weikai.h.

◆ set_channel_name()

void esphome::weikai::WeikaiChannel::set_channel_name ( std::string &&  name)
inline

The name as generated by the Python code generator.

Parameters
nameof the channel

Definition at line 311 of file weikai.h.

◆ set_line_param_()

void esphome::weikai::WeikaiChannel::set_line_param_ ( )
protected

set the line parameters

Definition at line 336 of file weikai.cpp.

◆ set_parent()

void esphome::weikai::WeikaiChannel::set_parent ( WeikaiComponent parent)
inline

We belongs to this WeikaiComponent.

Parameters
parentpointer to the component we belongs to

Definition at line 300 of file weikai.h.

◆ setup_channel()

void esphome::weikai::WeikaiChannel::setup_channel ( )
virtual

Setup the channel.

Definition at line 309 of file weikai.cpp.

◆ tx_fifo_is_not_empty_()

bool esphome::weikai::WeikaiChannel::tx_fifo_is_not_empty_ ( )
inlineprotected

test if transmit buffer is not empty in the status register (optimization)

Returns
true if not emptygroup test_

Definition at line 382 of file weikai.cpp.

◆ tx_in_fifo_()

size_t esphome::weikai::WeikaiChannel::tx_in_fifo_ ( )
protected

Returns the number of bytes in the transmit fifo.

Returns
the number of bytes in the fifo

Definition at line 384 of file weikai.cpp.

◆ write_array()

void esphome::weikai::WeikaiChannel::write_array ( const uint8_t *  buffer,
size_t  length 
)
overridevirtual

Writes a specified number of bytes to a serial port.

Parameters
bufferpointer to the buffer
lengthnumber of bytes to write

This method sends 'length' characters from the buffer to the serial line. Unfortunately (unlike the Arduino equivalent) this method does not return any flag and therefore it is not possible to know if any/all bytes have been transmitted correctly. Another problem is that it is not possible to know ahead of time how many bytes we can safely send as there is no tx_available() method provided! To avoid overrun when using the write method you can use the flush() method to wait until the transmit fifo is empty.
Typical usage could be:

// ...
uint8_t buffer[128];
// ...
write_array(&buffer, length);
// ...

Implements esphome::uart::UARTComponent.

Definition at line 475 of file weikai.cpp.

◆ xfer_fifo_to_buffer_()

size_t esphome::weikai::WeikaiChannel::xfer_fifo_to_buffer_ ( )
protected

transfer bytes from the weikai internal FIFO to the buffer (if any)

Returns
number of bytes transferred

Definition at line 494 of file weikai.cpp.

Field Documentation

◆ channel_

uint8_t esphome::weikai::WeikaiChannel::channel_
protected

our Channel number

Definition at line 437 of file weikai.h.

◆ data_

uint8_t esphome::weikai::WeikaiChannel::data_
protected

a one byte buffer for register read storage

Definition at line 438 of file weikai.h.

◆ name_

std::string esphome::weikai::WeikaiChannel::name_
protected

name of the entity

Definition at line 439 of file weikai.h.

◆ parent_

WeikaiComponent* esphome::weikai::WeikaiChannel::parent_
protected

our WK2168component parent

Definition at line 436 of file weikai.h.

◆ receive_buffer_

WKRingBuffer<uint8_t, RING_BUFFER_SIZE> esphome::weikai::WeikaiChannel::receive_buffer_
protected

the buffer where we store temporarily the bytes received

Definition at line 435 of file weikai.h.


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