Skip to content

Commit

Permalink
feat(openthread): README.md
Browse files Browse the repository at this point in the history
Initial documentation for ESP3 Arduino OpenThread CLI API.
  • Loading branch information
SuGlider authored Jun 21, 2024
1 parent 7fece86 commit 001ae42
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions libraries/OpenThread/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# ESP32 Arduino OpenThreadCLI

The `OpenThreadCLI` class is an Arduino API for interacting with the OpenThread Command Line Interface (CLI). It allows you to manage and configure the Thread stack using a command-line interface. Below are the details of the class:
The available OpenThread Commands are documented in the [OpenThread CLI Reference Page](https://openthread.io/reference/cli/commands)

There is one main class called `OpenThreadCLI` and a global object used to operate OpenThread CLI, called `OThreadCLI`
Some [helper functions](helper_functions.md) were made available for working with the OpenThread CLI environment.

It is important to note that the current implementation can only be used with Espressif SoC that has support to IEEE 802.15.4, such as **ESP32-C6** and **ESP32-H2**.

## Class Definition

```cpp
class OpenThreadCLI : public Stream {
private:
static size_t setBuffer(xQueueHandle &queue, size_t len);
bool otStarted = false;

public:
OpenThreadCLI();
~OpenThreadCLI();
operator bool() const;

// Starts a task to read/write otStream. Default prompt is "ot> ". Set it to NULL to make it invisible.
void startOpenThreadConsole(Stream& otStream, bool echoback = true, const char* prompt = "ot> ");
void stopOpenThreadConsole();
void setPrompt(char* prompt); // Changes the console prompt. NULL is an empty prompt.
void setEchoBack(bool echoback); // Changes the console echoback option
void setStream(Stream& otStream); // Changes the console Stream object
void onReceive(OnReceiveCb_t func); // Called on a complete line of output from OT CLI, as OT Response

void begin(bool OThreadAutoStart = true);
void end();

// Default size is 256 bytes
size_t setTxBufferSize(size_t tx_queue_len);
// Default size is 1024 bytes
size_t setRxBufferSize(size_t rx_queue_len);

size_t write(uint8_t);
int available();
int read();
int peek();
void flush();
};

extern OpenThreadCLI OThreadCLI;
```
## Class Overview
- The `OpenThreadCLI` class inherits from the `Stream` class, making it compatible with Arduino's standard I/O functions.
- It provides methods for managing the OpenThread CLI, including starting and stopping the console, setting prompts, and handling received data.
- You can customize the console behavior by adjusting parameters such as echoback and buffer sizes.
## Public Methods
- `startOpenThreadConsole(Stream& otStream, bool echoback = true, const char* prompt = "ot> ")`: Starts the OpenThread console with the specified stream, echoback option, and prompt.
- `stopOpenThreadConsole()`: Stops the OpenThread console.
- `setPrompt(char* prompt)`: Changes the console prompt (set to NULL for an empty prompt).
- `setEchoBack(bool echoback)`: Changes the console echoback option.
- `setStream(Stream& otStream)`: Changes the console Stream object.
- `onReceive(OnReceiveCb_t func)`: Sets a callback function to handle complete lines of output from the OT CLI.
- `begin(bool OThreadAutoStart = true)`: Initializes the OpenThread stack (optional auto-start).
- `end()`: Deinitializes the OpenThread stack.
- `setTxBufferSize(size_t tx_queue_len)`: Sets the transmit buffer size (default is 256 bytes).
- `setRxBufferSize(size_t rx_queue_len)`: Sets the receive buffer size (default is 1024 bytes).
- `write(uint8_t)`, `available()`, `read()`, `peek()`, `flush()`: Standard Stream methods implementation for OpenThread CLI object.

0 comments on commit 001ae42

Please sign in to comment.