arduino-emulator
Loading...
Searching...
No Matches
arduino::HardwareService Class Reference

Provides a virtualized hardware communication service for SPI, I2C, I2S, and GPIO over a stream. More...

#include <HardwareService.h>

Public Member Functions

void flush ()
 operator bool ()
uint16_t receive (void *data, int len)
uint16_t receive16 ()
uint32_t receive32 ()
uint64_t receive64 ()
uint8_t receive8 ()
void send (bool data)
void send (HWCalls call)
void send (int32_t dataIn)
void send (int64_t dataIn)
void send (uint16_t dataIn)
void send (uint32_t dataIn)
void send (uint64_t dataIn)
void send (uint8_t data)
void send (void *data, size_t len)
void setStream (Stream *str)

Protected Member Functions

uint16_t blockingRead (void *data, int len, int timeout=1000)
bool is_big_endian (void)
int16_t swap_int16 (int16_t val)
 Byte swap short.
int32_t swap_int32 (int32_t val)
 Byte swap int.
int64_t swap_int64 (int64_t val)
uint16_t swap_uint16 (uint16_t val)
 Byte swap unsigned short.
uint32_t swap_uint32 (uint32_t val)
 Byte swap unsigned int.
uint64_t swap_uint64 (uint64_t val)

Protected Attributes

Stream * io = nullptr
bool isLittleEndian = !is_big_endian()
int timeout_ms = 1000

Detailed Description

Provides a virtualized hardware communication service for SPI, I2C, I2S, and GPIO over a stream.

This class encapsulates the logic to tunnel hardware protocol messages (SPI, I2C, I2S, GPIO, Serial, etc.) over a generic stream interface. It handles serialization and deserialization of protocol calls and data, ensuring correct endianness (little endian by default for embedded devices). The class provides methods to send and receive various data types, manage the underlying stream, and perform byte-swapping as needed.

Key features:

  • Tunnels hardware protocol messages over a stream (e.g., network, serial).
  • Supports sending and receiving multiple data types with correct endianness.
  • Provides blocking read with timeout for reliable communication.
  • Handles byte order conversion for cross-platform compatibility.
  • Can be used as a base for remote hardware emulation or proxying.

Usage:

  • Set the stream using setStream().
  • Use send() methods to transmit protocol calls and data.
  • Use receive methods to read responses from the remote hardware.
  • Use flush() to ensure all data is sent.

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