22#include "ArduinoLogger.h"
23#include "GPIOWrapper.h"
24#include "I2CWrapper.h"
25#include "RemoteGPIO.h"
28#include "SPIWrapper.h"
71 bool begin(
Stream* s,
bool asDefault =
true,
bool doHandShake =
true) {
80 Logger.warning(
"GPIO, I2C, SPI set up for Remote");
89 return i2c && spi && gpio;
93 void begin(
int port,
bool asDefault) {
99 void begin(
bool asDefault =
true) {
100 is_default_objects_active = asDefault;
101 if (p_stream ==
nullptr) {
102 default_stream.begin(port);
103 handShake(&default_stream);
104 IPAddress ip = default_stream.remoteIP();
105 int remote_port = default_stream.remotePort();
106 default_stream.setTarget(ip, remote_port);
107 default_stream.write((
const uint8_t*)
"OK", 2);
108 default_stream.flush();
109 begin(&default_stream, asDefault,
false);
111 begin(p_stream, asDefault,
true);
116 if (is_default_objects_active) {
117 GPIO.setGPIO(
nullptr);
119 Wire.setI2C(
nullptr);
121 if (p_stream == &default_stream) {
122 default_stream.stop();
126 HardwareGPIO* getGPIO() {
return &gpio; }
127 HardwareI2C* getI2C() {
return &i2c; }
128 HardwareSPI* getSPI() {
return &spi; }
131 arduino::UDPStream default_stream;
132 Stream* p_stream =
nullptr;
137 bool is_default_objects_active =
false;
139 void handShake(Stream* s) {
141 Logger.warning(
"HardwareSetup",
"waiting for device...");
144 if (s->available() >= 16) {
146 int len = s->readBytes(buffer, 18);
148 if (strncmp(buffer,
"Arduino-Emulator", 16)==0) {
149 Logger.info(
"UDPStream",
"device found!");
152 Logger.info(
"UDPStream",
"unknown command", buffer);
156 }
catch (
const std::exception& ex) {
157 Logger.error(
"UDPStream", ex.what());
163#if !defined(SKIP_HARDWARE_SETUP)
Abstract interface for providing GPIO hardware implementations.
Definition Sources.h:66
Configures and manages remote hardware interfaces for Arduino emulation.
Definition HardwareSetupRemote.h:59
void begin(int port, bool asDefault)
start with udp on the indicatd port
Definition HardwareSetupRemote.h:93
HardwareSetupRemote()=default
default constructor: you need to call begin() afterwards
HardwareSetupRemote(Stream &stream)
HardwareSetup uses the indicated stream.
Definition HardwareSetupRemote.h:65
void begin(bool asDefault=true)
start with the default udp stream.
Definition HardwareSetupRemote.h:99
bool begin(Stream *s, bool asDefault=true, bool doHandShake=true)
assigns the different protocols to the stream
Definition HardwareSetupRemote.h:71
HardwareSetupRemote(int port)
HardwareSetup that uses udp.
Definition HardwareSetupRemote.h:68
Abstract interface for providing I2C hardware implementations.
Definition Sources.h:36
Definition IPAddress.h:43
Abstract interface for providing SPI hardware implementations.
Definition Sources.h:51
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31
I2CWrapper Wire
Global Wire instance used by Arduino API functions and direct access.
Definition I2CWrapper.cpp:24
SPIWrapper SPI
Global SPI instance used by Arduino API and direct access.
Definition SPIWrapper.cpp:27
GPIOWrapper GPIO
Global GPIO instance used by Arduino API functions and direct access.
Definition GPIOWrapper.cpp:35