HostEd

The hosted component allows Sming’s host emulator to run parts of the commands on an actual microcontroller. The communication is done via simplePRC and the microcontroller has to be flashed with a special application.

Overview

Sming’s host emulator allows easier debugging and development of embedded applications. This component named “Hosted” extends the host emulator and facilitates testing functionality that only a real microcontroller can provide as for example digital I/O operations or SPI operations.

For example in order to run the Basic_Blink application under the host emulator and run the actual blinking of a LED on a microcontroller we can compile the application using the following directives:

make SMING_ARCH=Host ENABLE_HOSTED=tcp HOSTED_SERVER_IP=192.168.4.1
  • SMING_ARCH=Host instructs the build system to build the application for the Host architecture.

  • ENABLE_HOSTED=tcp instructs the host emulator to communicate with the real microcontroller using TCP.

  • HOSTED_SERVER_IP=192.168.4.1 tells the host emulator where the server is running.

We need to compile and flash also a special application on the desired microcontroller. This application will act as an RPC Server and will execute the commands from the host emulator on the microcontroller.

In the samples directory you will find the sample applications that will turn your microcontroller into an RPC server.

The compilation and flashing for ESP32, for example, can be done using the following commands:

cd samples/tcp
make SMING_ARCH=Esp32 WIFI_SSID=YourSSID WIFI_PWD=YourPassword
make flash

If you replace SMING_ARCH=Esp32 with SMING_ARCH=Esp8266 then the hosted application will be compiled and flashed on a ESP8266 microcontroller. Make sure to replace the values of WIFI_SSID and WIFI_PWD with the actual name and password for the Access Point (AP).

Communication

At the moment the communication between an application running on the Host and the RCP server running on a microcontroller can be done using TCP or serial interface.

The transport classes are located under include/Hosted/Transport.

Configuration

ENABLE_HOSTED

Default: empty (disabled)

Enables the hosted component. Valid values for the moment are: - tcp for communication over TCP network. - serial for communication over serial interface

HOSTED_SERVER_IP

Default: 192.168.13.1

Used only when ENABLE_HOSTED=tcp is specified. Specifies the IP address of the remote RPC server.

HOSTED_COM_PORT

Default: COM_PORT

Used only when ENABLE_HOSTED=serial is specified. Specifies which local communication port should be used to connect to the remote RPC server.

HOSTED_COM_SPEED

Default: 115200

Used only when ENABLE_HOSTED=serial is specified. Specifies the communication baud rate.

API Documentation

namespace Hosted

Functions

char convertType(const String &type)

Convert C type to format character See: https://docs.python.org/3.5/library/struct.html#format-strings

String convertFQN(const String &name)

Converts a name as given from PRETTY_FUNCTION to internal format. Examples: void a::sub(int) -> a::sub(: i) void TwoWire::pins(uint8_t,uint8_t) -> TwoWire::pins(: B B) uint8_t digitalRead(uint16_t) -> digitalRead(B: H)

Parameters:

name – source name

Return values:

converted – name

Variables

constexpr int COMMAND_NOT_FOUND = -1
class Client : private simpleRPC::ParserCallbacks
#include <Client.h>

Public Functions

template<typename ...Args>
inline bool send(const String &functionName, Args... args)

Method to send commands to the remote server.

If the command is overloaded, one command name with two or more different signatures then the name has to be containing the full function signature. Example: “void digitalWrite(uint16_t, uint8_t)”. The name with the signature MUST be the same as the one produced from PRETTY_FUNCTION -> https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

Parameters:
  • functionName – Either the name or the name with the signature. Example: “digitalWrite” - will try to call the default digitalWrite function on the server

  • variable – arguments

Return values:

true – on success, false if the command is not available

template<typename R>
inline R wait()

This method will block the execution until a message is detected.

Return values:

HostedCommand

inline int getFunctionId(String name)

Fetches a list of commands supported on the RPC server and gives back the id of the desired command.

Parameters:

name – command name to query

Return values:

-1 – if not found. Otherwise the id of the function

inline bool getRemoteCommands()

Gets list of remote command names and their ids.

Return values:

true – on success, false otherwise

class Serial : public Stream
#include <Serial.h>

Public Functions

inline bool begin(uint32_t baud = 9600)

Initialise the serial port.

Parameters:

baud – BAUD rate of the serial port (Default: 9600)

inline virtual size_t write(uint8_t c) override

Writes a single character to output stream.

Parameters:

c – Character to write to output stream

Return values:

size_t – Quantity of characters written to output stream

inline virtual size_t readBytes(char *buffer, size_t length) override

Read chars from stream into buffer.

Terminates if length characters have been read or timeout (see setTimeout). Returns the number of characters placed in the buffer (0 means no valid data found).

Note

Inherited classes may provide more efficient implementations without timeout.

inline virtual size_t write(const uint8_t *buffer, size_t size)

Writes characters from a buffer to output stream.

Parameters:
  • buffer – Pointer to character buffer

  • size – Quantity of characters to write

Return values:

size_t – Quantity of characters written to stream

namespace Transport
class BaseTransport
#include <BaseTransport.h>

Subclassed by Hosted::Transport::SerialTransport, Hosted::Transport::TcpTransport

class SerialTransport : public Hosted::Transport::BaseTransport
#include <SerialTransport.h>
class TcpClientStream : public Stream
#include <TcpClientStream.h>

Public Functions

inline virtual size_t readBytes(char *buffer, size_t length) override

Read chars from stream into buffer.

Terminates if length characters have been read or timeout (see setTimeout). Returns the number of characters placed in the buffer (0 means no valid data found).

Note

Inherited classes may provide more efficient implementations without timeout.

inline virtual size_t write(const uint8_t *buffer, size_t size) override

Writes characters from a buffer to output stream.

Parameters:
  • buffer – Pointer to character buffer

  • size – Quantity of characters to write

Return values:

size_t – Quantity of characters written to stream

inline virtual size_t write(uint8_t c) override

Writes a single character to output stream.

Parameters:

c – Character to write to output stream

Return values:

size_t – Quantity of characters written to output stream

class TcpClientTransport : public Hosted::Transport::TcpTransport
#include <TcpClientTransport.h>
class TcpServerTransport : public Hosted::Transport::TcpTransport
#include <TcpServerTransport.h>
class TcpTransport : public Hosted::Transport::BaseTransport
#include <TcpTransport.h>

Subclassed by Hosted::Transport::TcpClientTransport, Hosted::Transport::TcpServerTransport

References

Used by

Environment Variables

SoC support

  • esp32

  • esp32c2

  • esp32c3

  • esp32s2

  • esp32s3

  • esp8266

  • host

  • rp2040

  • rp2350