BusBricks: arduinoMocking::SoftwareSerial Class Reference
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
arduinoMocking::SoftwareSerial Class Reference

Mock class to simulate the SoftwareSerial library for native builds. More...

Public Member Functions

 SoftwareSerial (int rx, int tx)
 Constructs a SoftwareSerial object with specified RX and TX pins.
 
void begin (long baud)
 Initializes the serial communication with the specified baud rate.
 
void println (const String &message)
 Prints a message followed by a newline.
 
void print (const String &message)
 Prints a message without a newline.
 
void write (const char *data, size_t size)
 Writes data to the internal queue.
 
void flush ()
 Empties the internal queue and prints the flushed data to the console.
 
int available ()
 Returns the number of available bytes in the internal queue.
 
int read ()
 Reads a character from the internal queue.
 
int peek ()
 Returns the next character in the queue without removing it.
 
void simulateInput ()
 Simulates user input by adding characters to the internal queue.
 
void simulateInput (std::string input)
 Simulates user input by adding a predefined string to the internal queue.
 

Detailed Description

Mock class to simulate the SoftwareSerial library for native builds.

This class is a mock implementation of the Arduino SoftwareSerial class, designed for testing and simulation in non-Arduino environments. It provides methods to simulate serial communication including reading, writing, and flushing data.

Methods

  • SoftwareSerial(int rx, int tx): Constructor to initialize the mock serial with RX and TX pins.
  • void begin(long baud): Initializes the serial communication with the specified baud rate. This method does nothing in the mock implementation.
  • void println(const String &message): Prints a message followed by a newline. This method does nothing in the mock implementation.
  • void print(const String &message): Prints a message without a newline. This method does nothing in the mock implementation.
  • void write(const char* data, size_t size): Writes data to the mock serial by adding each character to the internal queue.
  • void flush(): Empties the internal queue and prints the flushed data to the console.
  • int available(): Returns the number of available bytes in the internal queue (0 or 1).
  • int read(): Reads a character from the internal queue. Returns -1 if the queue is empty.
  • int peek(): Returns the next character in the queue without removing it. Returns -1 if the queue is empty.
  • void simulateInput(): Prompts the user to enter a string which is then added to the internal queue. Useful for interactive testing.
  • void simulateInput(std::string input): Adds the given string to the internal queue for simulation purposes.
  • int rxPin: The RX pin number.
  • int txPin: The TX pin number.
  • Content_stack<char, 512> dataQueue: Internal queue to store characters for simulation.

Constructor & Destructor Documentation

◆ SoftwareSerial()

arduinoMocking::SoftwareSerial::SoftwareSerial ( int rx,
int tx )

Constructs a SoftwareSerial object with specified RX and TX pins.

Parameters
rxThe RX pin number.
txThe TX pin number.

Member Function Documentation

◆ available()

int arduinoMocking::SoftwareSerial::available ( )

Returns the number of available bytes in the internal queue.

Returns
The number of available bytes (0 or 1).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

void arduinoMocking::SoftwareSerial::begin ( long baud)

Initializes the serial communication with the specified baud rate.

This method does not perform any actions in the mock implementation.

Parameters
baudThe baud rate for the serial communication.

◆ flush()

void arduinoMocking::SoftwareSerial::flush ( )

Empties the internal queue and prints the flushed data to the console.

This method is used to simulate flushing the serial buffer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ peek()

int arduinoMocking::SoftwareSerial::peek ( )

Returns the next character in the queue without removing it.

Returns
The next character in the queue, or -1 if the queue is empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print()

void arduinoMocking::SoftwareSerial::print ( const String & message)

Prints a message without a newline.

This method does not perform any actions in the mock implementation.

Parameters
messageThe message to be printed.

◆ println()

void arduinoMocking::SoftwareSerial::println ( const String & message)

Prints a message followed by a newline.

This method does not perform any actions in the mock implementation.

Parameters
messageThe message to be printed.

◆ read()

int arduinoMocking::SoftwareSerial::read ( )

Reads a character from the internal queue.

Returns
The character read from the queue, or -1 if the queue is empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ simulateInput() [1/2]

void arduinoMocking::SoftwareSerial::simulateInput ( )

Simulates user input by adding characters to the internal queue.

Prompts the user to enter a string, which is then added to the queue.

Here is the call graph for this function:

◆ simulateInput() [2/2]

void arduinoMocking::SoftwareSerial::simulateInput ( std::string input)

Simulates user input by adding a predefined string to the internal queue.

Parameters
inputThe string to be added to the queue.
Here is the call graph for this function:

◆ write()

void arduinoMocking::SoftwareSerial::write ( const char * data,
size_t size )

Writes data to the internal queue.

Adds each character of the provided data to the internal queue.

Parameters
dataPointer to the data to be written.
sizeThe number of bytes to write.
Here is the call graph for this function:
Here is the caller graph for this function:

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