|
| 1 | +# ESP32 Arduino OpenThreadCLI |
| 2 | + |
| 3 | +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: |
| 4 | +The available OpenThread Commands are documented in the [OpenThread CLI Reference Page](https://openthread.io/reference/cli/commands) |
| 5 | + |
| 6 | +There is one main class called `OpenThreadCLI` and a global object used to operate OpenThread CLI, called `OThreadCLI` |
| 7 | +Some [helper functions](helper_functions.md) were made available for working with the OpenThread CLI environment. |
| 8 | + |
| 9 | +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**. |
| 10 | + |
| 11 | +## Class Definition |
| 12 | + |
| 13 | +```cpp |
| 14 | +class OpenThreadCLI : public Stream { |
| 15 | +private: |
| 16 | + static size_t setBuffer(xQueueHandle &queue, size_t len); |
| 17 | + bool otStarted = false; |
| 18 | + |
| 19 | +public: |
| 20 | + OpenThreadCLI(); |
| 21 | + ~OpenThreadCLI(); |
| 22 | + operator bool() const; |
| 23 | + |
| 24 | + // Starts a task to read/write otStream. Default prompt is "ot> ". Set it to NULL to make it invisible. |
| 25 | + void startOpenThreadConsole(Stream& otStream, bool echoback = true, const char* prompt = "ot> "); |
| 26 | + void stopOpenThreadConsole(); |
| 27 | + void setPrompt(char* prompt); // Changes the console prompt. NULL is an empty prompt. |
| 28 | + void setEchoBack(bool echoback); // Changes the console echoback option |
| 29 | + void setStream(Stream& otStream); // Changes the console Stream object |
| 30 | + void onReceive(OnReceiveCb_t func); // Called on a complete line of output from OT CLI, as OT Response |
| 31 | + |
| 32 | + void begin(bool OThreadAutoStart = true); |
| 33 | + void end(); |
| 34 | + |
| 35 | + // Default size is 256 bytes |
| 36 | + size_t setTxBufferSize(size_t tx_queue_len); |
| 37 | + // Default size is 1024 bytes |
| 38 | + size_t setRxBufferSize(size_t rx_queue_len); |
| 39 | + |
| 40 | + size_t write(uint8_t); |
| 41 | + int available(); |
| 42 | + int read(); |
| 43 | + int peek(); |
| 44 | + void flush(); |
| 45 | +}; |
| 46 | + |
| 47 | +extern OpenThreadCLI OThreadCLI; |
| 48 | +``` |
| 49 | +
|
| 50 | +## Class Overview |
| 51 | +- The `OpenThreadCLI` class inherits from the `Stream` class, making it compatible with Arduino's standard I/O functions. |
| 52 | +- It provides methods for managing the OpenThread CLI, including starting and stopping the console, setting prompts, and handling received data. |
| 53 | +- You can customize the console behavior by adjusting parameters such as echoback and buffer sizes. |
| 54 | +
|
| 55 | +## Public Methods |
| 56 | +- `startOpenThreadConsole(Stream& otStream, bool echoback = true, const char* prompt = "ot> ")`: Starts the OpenThread console with the specified stream, echoback option, and prompt. |
| 57 | +- `stopOpenThreadConsole()`: Stops the OpenThread console. |
| 58 | +- `setPrompt(char* prompt)`: Changes the console prompt (set to NULL for an empty prompt). |
| 59 | +- `setEchoBack(bool echoback)`: Changes the console echoback option. |
| 60 | +- `setStream(Stream& otStream)`: Changes the console Stream object. |
| 61 | +- `onReceive(OnReceiveCb_t func)`: Sets a callback function to handle complete lines of output from the OT CLI. |
| 62 | +- `begin(bool OThreadAutoStart = true)`: Initializes the OpenThread stack (optional auto-start). |
| 63 | +- `end()`: Deinitializes the OpenThread stack. |
| 64 | +- `setTxBufferSize(size_t tx_queue_len)`: Sets the transmit buffer size (default is 256 bytes). |
| 65 | +- `setRxBufferSize(size_t rx_queue_len)`: Sets the receive buffer size (default is 1024 bytes). |
| 66 | +- `write(uint8_t)`, `available()`, `read()`, `peek()`, `flush()`: Standard Stream methods implementation for OpenThread CLI object. |
| 67 | +
|
| 68 | +
|
0 commit comments