mirror of
https://github.com/espressif/openthread.git
synced 2026-09-11 11:40:06 +00:00
[api] remove UART from in cli/ncp API (#6243)
This commit removes application library CLI/NCP dependency on platform layer UART APIs. Instead, application layer provides callbacks sending CLI/NCP data. With this change, platforms with native support for formatted output can simply implement the CLI output callback with something like `vprintf()`.
This commit is contained in:
+2
-89
@@ -340,6 +340,7 @@ LOCAL_SRC_FILES := \
|
|||||||
src/lib/url/url.cpp \
|
src/lib/url/url.cpp \
|
||||||
src/posix/platform/alarm.cpp \
|
src/posix/platform/alarm.cpp \
|
||||||
src/posix/platform/backbone.cpp \
|
src/posix/platform/backbone.cpp \
|
||||||
|
src/posix/platform/daemon.cpp \
|
||||||
src/posix/platform/entropy.cpp \
|
src/posix/platform/entropy.cpp \
|
||||||
src/posix/platform/hdlc_interface.cpp \
|
src/posix/platform/hdlc_interface.cpp \
|
||||||
src/posix/platform/infra_if.cpp \
|
src/posix/platform/infra_if.cpp \
|
||||||
@@ -353,7 +354,6 @@ LOCAL_SRC_FILES := \
|
|||||||
src/posix/platform/settings.cpp \
|
src/posix/platform/settings.cpp \
|
||||||
src/posix/platform/spi_interface.cpp \
|
src/posix/platform/spi_interface.cpp \
|
||||||
src/posix/platform/system.cpp \
|
src/posix/platform/system.cpp \
|
||||||
src/posix/platform/uart.cpp \
|
|
||||||
src/posix/platform/udp.cpp \
|
src/posix/platform/udp.cpp \
|
||||||
third_party/mbedtls/repo/library/aes.c \
|
third_party/mbedtls/repo/library/aes.c \
|
||||||
third_party/mbedtls/repo/library/asn1parse.c \
|
third_party/mbedtls/repo/library/asn1parse.c \
|
||||||
@@ -420,7 +420,6 @@ LOCAL_C_INCLUDES := \
|
|||||||
LOCAL_CFLAGS := \
|
LOCAL_CFLAGS := \
|
||||||
$(OPENTHREAD_PUBLIC_CFLAGS) \
|
$(OPENTHREAD_PUBLIC_CFLAGS) \
|
||||||
$(OPENTHREAD_PRIVATE_CFLAGS) \
|
$(OPENTHREAD_PRIVATE_CFLAGS) \
|
||||||
-DOPENTHREAD_CONFIG_UART_CLI_RAW=1 \
|
|
||||||
$(OPENTHREAD_PROJECT_CFLAGS) \
|
$(OPENTHREAD_PROJECT_CFLAGS) \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
@@ -434,13 +433,11 @@ LOCAL_SRC_FILES := \
|
|||||||
src/cli/cli_coap.cpp \
|
src/cli/cli_coap.cpp \
|
||||||
src/cli/cli_coap_secure.cpp \
|
src/cli/cli_coap_secure.cpp \
|
||||||
src/cli/cli_commissioner.cpp \
|
src/cli/cli_commissioner.cpp \
|
||||||
src/cli/cli_console.cpp \
|
|
||||||
src/cli/cli_dataset.cpp \
|
src/cli/cli_dataset.cpp \
|
||||||
src/cli/cli_joiner.cpp \
|
src/cli/cli_joiner.cpp \
|
||||||
src/cli/cli_network_data.cpp \
|
src/cli/cli_network_data.cpp \
|
||||||
src/cli/cli_srp_client.cpp \
|
src/cli/cli_srp_client.cpp \
|
||||||
src/cli/cli_srp_server.cpp \
|
src/cli/cli_srp_server.cpp \
|
||||||
src/cli/cli_uart.cpp \
|
|
||||||
src/cli/cli_udp.cpp \
|
src/cli/cli_udp.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
@@ -484,97 +481,13 @@ LOCAL_LDLIBS := \
|
|||||||
-lutil
|
-lutil
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
|
src/posix/cli.cpp \
|
||||||
src/posix/main.c \
|
src/posix/main.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES = libopenthread-cli ot-core
|
LOCAL_STATIC_LIBRARIES = libopenthread-cli ot-core
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libopenthread-ncp
|
|
||||||
LOCAL_MODULE_TAGS := eng
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := \
|
|
||||||
$(OPENTHREAD_PROJECT_INCLUDES) \
|
|
||||||
$(LOCAL_PATH)/include \
|
|
||||||
$(LOCAL_PATH)/src \
|
|
||||||
$(LOCAL_PATH)/src/core \
|
|
||||||
$(LOCAL_PATH)/src/ncp \
|
|
||||||
$(LOCAL_PATH)/src/posix/platform \
|
|
||||||
$(LOCAL_PATH)/src/posix/platform/include \
|
|
||||||
$(LOCAL_PATH)/third_party/mbedtls \
|
|
||||||
$(LOCAL_PATH)/third_party/mbedtls/repo/include \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_CFLAGS := \
|
|
||||||
$(OPENTHREAD_PUBLIC_CFLAGS) \
|
|
||||||
$(OPENTHREAD_PRIVATE_CFLAGS) \
|
|
||||||
$(OPENTHREAD_PROJECT_CFLAGS) \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_CPPFLAGS := \
|
|
||||||
-std=c++11 \
|
|
||||||
-pedantic-errors \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
|
||||||
src/lib/spinel/spinel_buffer.cpp \
|
|
||||||
src/ncp/changed_props_set.cpp \
|
|
||||||
src/ncp/ncp_base.cpp \
|
|
||||||
src/ncp/ncp_base_mtd.cpp \
|
|
||||||
src/ncp/ncp_base_ftd.cpp \
|
|
||||||
src/ncp/ncp_base_dispatcher.cpp \
|
|
||||||
src/ncp/ncp_uart.cpp \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := ot-ncp
|
|
||||||
LOCAL_MODULE_TAGS := eng
|
|
||||||
|
|
||||||
ifneq ($(ANDROID_NDK),1)
|
|
||||||
LOCAL_SHARED_LIBRARIES := libcutils
|
|
||||||
endif
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := \
|
|
||||||
$(OPENTHREAD_PROJECT_INCLUDES) \
|
|
||||||
$(LOCAL_PATH)/include \
|
|
||||||
$(LOCAL_PATH)/src \
|
|
||||||
$(LOCAL_PATH)/src/core \
|
|
||||||
$(LOCAL_PATH)/src/ncp \
|
|
||||||
$(LOCAL_PATH)/src/posix/platform \
|
|
||||||
$(LOCAL_PATH)/src/posix/platform/include \
|
|
||||||
$(LOCAL_PATH)/third_party/mbedtls \
|
|
||||||
$(LOCAL_PATH)/third_party/mbedtls/repo/include \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_CFLAGS := \
|
|
||||||
$(OPENTHREAD_PUBLIC_CFLAGS) \
|
|
||||||
$(OPENTHREAD_PRIVATE_CFLAGS) \
|
|
||||||
-DOPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_NCP \
|
|
||||||
$(OPENTHREAD_PROJECT_CFLAGS) \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_CPPFLAGS := \
|
|
||||||
-std=c++11 \
|
|
||||||
-pedantic-errors \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
|
||||||
src/posix/main.c \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LOCAL_LDLIBS := \
|
|
||||||
-lrt \
|
|
||||||
-lutil
|
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES = libopenthread-ncp ot-core
|
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
|
||||||
|
|
||||||
ifeq ($(USE_OTBR_DAEMON), 1)
|
ifeq ($(USE_OTBR_DAEMON), 1)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ There are two alarm service types,
|
|||||||
and [microsecond](https://github.com/openthread/openthread/blob/main/include/openthread/platform/alarm-micro.h).
|
and [microsecond](https://github.com/openthread/openthread/blob/main/include/openthread/platform/alarm-micro.h).
|
||||||
Millisecond is required for a new hardware platform. Microsecond is optional.
|
Millisecond is required for a new hardware platform. Microsecond is optional.
|
||||||
|
|
||||||
## Step 2: UART
|
## Step 2: UART
|
||||||
|
|
||||||
> Note: This API is optional.
|
> Note: This API is optional.
|
||||||
|
|
||||||
API declaration:
|
API declaration:
|
||||||
|
|
||||||
[`/openthread/include/openthread/platform/uart.h`](https://github.com/openthread/openthread/blob/main/include/openthread/platform/uart.h)
|
[`/openthread/examples/platforms/utils/uart.h`](https://github.com/openthread/openthread/blob/main/examples/platforms/utils/uart.h)
|
||||||
|
|
||||||
The UART API implements fundamental serial port communication via the UART
|
The UART API implements fundamental serial port communication via the UART
|
||||||
interface.
|
interface.
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ if (openthread_enable_core_config_args) {
|
|||||||
# Enable NCP SPI support
|
# Enable NCP SPI support
|
||||||
openthread_config_ncp_spi_enable = false
|
openthread_config_ncp_spi_enable = false
|
||||||
|
|
||||||
# Enable NCP UART support
|
# Enable NCP HDLC support
|
||||||
openthread_config_ncp_uart_enable = false
|
openthread_config_ncp_hdlc_enable = false
|
||||||
|
|
||||||
# Enable builtin mbedtls management
|
# Enable builtin mbedtls management
|
||||||
openthread_config_enable_builtin_mbedtls_management =
|
openthread_config_enable_builtin_mbedtls_management =
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ COMMONCFLAGS += -DSPIS_AS_SERIAL_TRANSPORT=1
|
|||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
||||||
else
|
else
|
||||||
COMMONCFLAGS += -DUART_AS_SERIAL_TRANSPORT=1
|
COMMONCFLAGS += -DUART_AS_SERIAL_TRANSPORT=1
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
configure_OPTIONS += --enable-cli
|
configure_OPTIONS += --enable-cli
|
||||||
endif # NCP_SPI == 1
|
endif # NCP_SPI == 1
|
||||||
endif # DISABLE_TRANSPORTS
|
endif # DISABLE_TRANSPORTS
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ ifeq ($(NCP_SPI),1)
|
|||||||
COMMONCFLAGS += -DSPIS_AS_SERIAL_TRANSPORT=1
|
COMMONCFLAGS += -DSPIS_AS_SERIAL_TRANSPORT=1
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
||||||
else
|
else
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
configure_OPTIONS += --enable-cli
|
configure_OPTIONS += --enable-cli
|
||||||
ifeq ($(USB),1)
|
ifeq ($(USB),1)
|
||||||
COMMONCFLAGS += -DUSB_CDC_AS_SERIAL_TRANSPORT=1
|
COMMONCFLAGS += -DUSB_CDC_AS_SERIAL_TRANSPORT=1
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ ifeq ($(NCP_SPI),1)
|
|||||||
COMMONCFLAGS += -DSPIS_AS_SERIAL_TRANSPORT=1
|
COMMONCFLAGS += -DSPIS_AS_SERIAL_TRANSPORT=1
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
||||||
else
|
else
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
configure_OPTIONS += --enable-cli
|
configure_OPTIONS += --enable-cli
|
||||||
ifeq ($(USB),1)
|
ifeq ($(USB),1)
|
||||||
COMMONCFLAGS += -DUSB_CDC_AS_SERIAL_TRANSPORT=1
|
COMMONCFLAGS += -DUSB_CDC_AS_SERIAL_TRANSPORT=1
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ endif
|
|||||||
ifeq ($(NCP_SPI),1)
|
ifeq ($(NCP_SPI),1)
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1
|
||||||
else
|
else
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
endif # NCP_SPI == 1
|
endif # NCP_SPI == 1
|
||||||
|
|
||||||
ifeq ($(OTNS),1)
|
ifeq ($(OTNS),1)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ This page lists the available common switches with description. Unless stated ot
|
|||||||
| CHANNEL_MANAGER | OT_CHANNEL_MANAGER | Enables support for channel manager. Enable this switch on devices that are supposed to request a Thread network channel change. This switch should be used only with an FTD build. |
|
| CHANNEL_MANAGER | OT_CHANNEL_MANAGER | Enables support for channel manager. Enable this switch on devices that are supposed to request a Thread network channel change. This switch should be used only with an FTD build. |
|
||||||
| CHANNEL_MONITOR | OT_CHANNEL_MONITOR | Enables support for channel monitor. Enable this switch on devices that are supposed to determine the cleaner channels. |
|
| CHANNEL_MONITOR | OT_CHANNEL_MONITOR | Enables support for channel monitor. Enable this switch on devices that are supposed to determine the cleaner channels. |
|
||||||
| CHILD_SUPERVISION | OT_CHILD_SUPERVISION | Enables support for [child supervision](https://openthread.io/guides/build/features/child-supervision). Enable this switch on a parent or child node with custom OpenThread application that manages the supervision, checks timeout intervals, and verifies connectivity between parent and child. |
|
| CHILD_SUPERVISION | OT_CHILD_SUPERVISION | Enables support for [child supervision](https://openthread.io/guides/build/features/child-supervision). Enable this switch on a parent or child node with custom OpenThread application that manages the supervision, checks timeout intervals, and verifies connectivity between parent and child. |
|
||||||
| CLI_TRANSPORT | not implemented | Selects the transport of CLI. You can set this switch to UART (default) or CONSOLE. |
|
|
||||||
| COAP | OT_COAP | Enables support for the CoAP API. Enable this switch if you want to control Constrained Application Protocol communication. |
|
| COAP | OT_COAP | Enables support for the CoAP API. Enable this switch if you want to control Constrained Application Protocol communication. |
|
||||||
| COAP_OBSERVE | OT_COAP_OBSERVE | Enables support for CoAP Observe (RFC7641) API. |
|
| COAP_OBSERVE | OT_COAP_OBSERVE | Enables support for CoAP Observe (RFC7641) API. |
|
||||||
| COAPS | OT_COAPS | Enables support for the secure CoAP API. Enable this switch if you want to control Constrained Application Protocol Secure (CoAP over DTLS) communication. |
|
| COAPS | OT_COAPS | Enables support for the secure CoAP API. Enable this switch if you want to control Constrained Application Protocol Secure (CoAP over DTLS) communication. |
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ LIBTOOLFLAGS_COMMON += \
|
|||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
SOURCES_COMMON += \
|
SOURCES_COMMON += \
|
||||||
|
cli_uart.cpp \
|
||||||
main.c \
|
main.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|||||||
@@ -25,37 +25,77 @@
|
|||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include "openthread-core-config.h"
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This file implements the CLI interpreter on the UART service.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "cli_uart.hpp"
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <openthread-system.h>
|
||||||
|
#include <openthread/cli.h>
|
||||||
|
|
||||||
|
#include "cli/cli_config.h"
|
||||||
|
#include "common/code_utils.hpp"
|
||||||
|
#include "common/debug.hpp"
|
||||||
|
#include "common/logging.hpp"
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
#if OPENTHREAD_POSIX
|
#if OPENTHREAD_POSIX
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openthread/cli.h>
|
/**
|
||||||
#include <openthread/platform/logging.h>
|
* @def OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
||||||
#include <openthread/platform/uart.h>
|
*
|
||||||
#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART
|
* The size of CLI UART RX buffer in bytes.
|
||||||
#include <openthread/platform/debug_uart.h>
|
*
|
||||||
|
*/
|
||||||
|
#ifndef OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
||||||
|
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||||
|
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 640
|
||||||
|
#else
|
||||||
|
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 512
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cli/cli.hpp"
|
/**
|
||||||
#include "common/code_utils.hpp"
|
* @def OPENTHREAD_CONFIG_CLI_TX_BUFFER_SIZE
|
||||||
#include "common/encoding.hpp"
|
*
|
||||||
#include "common/logging.hpp"
|
* The size of CLI message buffer in bytes.
|
||||||
#include "common/new.hpp"
|
*
|
||||||
#include "common/tasklet.hpp"
|
*/
|
||||||
|
#ifndef OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE
|
||||||
|
#define OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||||
|
#if OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE > OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE
|
||||||
|
#error "diag output buffer should be smaller than CLI UART tx buffer"
|
||||||
|
#endif
|
||||||
|
#if OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE > OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
||||||
|
#error "diag command line should be smaller than CLI UART rx buffer"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH > OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
||||||
|
#error "command line should be should be smaller than CLI rx buffer"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kRxBufferSize = OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
|
||||||
|
kTxBufferSize = OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
|
char sRxBuffer[kRxBufferSize];
|
||||||
|
uint16_t sRxLength;
|
||||||
|
|
||||||
|
char sTxBuffer[kTxBufferSize];
|
||||||
|
uint16_t sTxHead;
|
||||||
|
uint16_t sTxLength;
|
||||||
|
|
||||||
|
uint16_t sSendLength;
|
||||||
|
|
||||||
#ifdef OT_CLI_UART_LOCK_HDR_FILE
|
#ifdef OT_CLI_UART_LOCK_HDR_FILE
|
||||||
|
|
||||||
@@ -89,44 +129,13 @@
|
|||||||
|
|
||||||
#endif // OT_CLI_UART_LOCK_HDR_FILE
|
#endif // OT_CLI_UART_LOCK_HDR_FILE
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
static int Output(const char *aBuf, uint16_t aBufLength);
|
||||||
static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE,
|
static otError ProcessCommand(void);
|
||||||
"diag output buffer should be smaller than CLI UART tx buffer");
|
|
||||||
static_assert(OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE <= OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
|
|
||||||
"diag command line should be smaller than CLI UART rx buffer");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static_assert(OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH <= OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
|
static void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
"command line should be should be smaller than CLI rx buffer");
|
|
||||||
|
|
||||||
namespace ot {
|
|
||||||
namespace Cli {
|
|
||||||
|
|
||||||
static OT_DEFINE_ALIGNED_VAR(sCliUartRaw, sizeof(Uart), uint64_t);
|
|
||||||
|
|
||||||
void Uart::Initialize(otInstance *aInstance)
|
|
||||||
{
|
{
|
||||||
Instance *instance = static_cast<Instance *>(aInstance);
|
static const char sEraseString[] = {'\b', ' ', '\b'};
|
||||||
Interpreter::sInterpreter = new (&sCliUartRaw) Uart(instance);
|
static const char CRNL[] = {'\r', '\n'};
|
||||||
}
|
|
||||||
|
|
||||||
Uart::Uart(Instance *aInstance)
|
|
||||||
: Interpreter(aInstance)
|
|
||||||
{
|
|
||||||
mRxLength = 0;
|
|
||||||
mTxHead = 0;
|
|
||||||
mTxLength = 0;
|
|
||||||
mSendLength = 0;
|
|
||||||
|
|
||||||
IgnoreError(otPlatUartEnable());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
|
||||||
{
|
|
||||||
#if !OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
static const char sEraseString[] = {'\b', ' ', '\b'};
|
|
||||||
static const char CRNL[] = {'\r', '\n'};
|
|
||||||
#endif
|
|
||||||
static const char sCommandPrompt[] = {'>', ' '};
|
static const char sCommandPrompt[] = {'>', ' '};
|
||||||
const uint8_t * end;
|
const uint8_t * end;
|
||||||
|
|
||||||
@@ -138,12 +147,10 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
|||||||
{
|
{
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
#if !OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
Output(CRNL, sizeof(CRNL));
|
Output(CRNL, sizeof(CRNL));
|
||||||
#endif
|
if (sRxLength > 0)
|
||||||
if (mRxLength > 0)
|
|
||||||
{
|
{
|
||||||
mRxBuffer[mRxLength] = '\0';
|
sRxBuffer[sRxLength] = '\0';
|
||||||
IgnoreError(ProcessCommand());
|
IgnoreError(ProcessCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,9 +158,7 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if !OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||||
|
|
||||||
case 0x03: // ASCII for Ctrl-C
|
case 0x03: // ASCII for Ctrl-C
|
||||||
kill(0, SIGINT);
|
kill(0, SIGINT);
|
||||||
break;
|
break;
|
||||||
@@ -165,22 +170,19 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
|||||||
|
|
||||||
case '\b':
|
case '\b':
|
||||||
case 127:
|
case 127:
|
||||||
if (mRxLength > 0)
|
if (sRxLength > 0)
|
||||||
{
|
{
|
||||||
Output(sEraseString, sizeof(sEraseString));
|
Output(sEraseString, sizeof(sEraseString));
|
||||||
mRxBuffer[--mRxLength] = '\0';
|
sRxBuffer[--sRxLength] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#endif // !OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (mRxLength < kRxBufferSize - 1)
|
if (sRxLength < kRxBufferSize - 1)
|
||||||
{
|
{
|
||||||
#if !OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
Output(reinterpret_cast<const char *>(aBuf), 1);
|
Output(reinterpret_cast<const char *>(aBuf), 1);
|
||||||
#endif
|
sRxBuffer[sRxLength++] = static_cast<char>(*aBuf);
|
||||||
mRxBuffer[mRxLength++] = static_cast<char>(*aBuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -188,13 +190,13 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Uart::ProcessCommand(void)
|
static otError ProcessCommand(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
otError error = OT_ERROR_NONE;
|
||||||
|
|
||||||
while (mRxBuffer[mRxLength - 1] == '\n' || mRxBuffer[mRxLength - 1] == '\r')
|
while (sRxBuffer[sRxLength - 1] == '\n' || sRxBuffer[sRxLength - 1] == '\r')
|
||||||
{
|
{
|
||||||
mRxBuffer[--mRxLength] = '\0';
|
sRxBuffer[--sRxLength] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT != OPENTHREAD_CONFIG_LOG_OUTPUT_NONE
|
#if OPENTHREAD_CONFIG_LOG_OUTPUT != OPENTHREAD_CONFIG_LOG_OUTPUT_NONE
|
||||||
@@ -222,32 +224,62 @@ otError Uart::ProcessCommand(void)
|
|||||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||||
/* TODO: how exactly do we get the instance here? */
|
/* TODO: how exactly do we get the instance here? */
|
||||||
#else
|
#else
|
||||||
otLogInfoCli("execute command: %s", mRxBuffer);
|
otLogInfoCli("execute command: %s", sRxBuffer);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
if (mRxLength > 0)
|
if (sRxLength > 0)
|
||||||
{
|
{
|
||||||
ProcessLine(mRxBuffer);
|
otCliInputLine(sRxBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
mRxLength = 0;
|
sRxLength = 0;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Interpreter::Output(const char *aBuf, uint16_t aBufLength)
|
static void Send(void)
|
||||||
{
|
{
|
||||||
return static_cast<Uart *>(this)->Output(aBuf, aBufLength);
|
VerifyOrExit(sSendLength == 0);
|
||||||
|
|
||||||
|
if (sTxLength > kTxBufferSize - sTxHead)
|
||||||
|
{
|
||||||
|
sSendLength = kTxBufferSize - sTxHead;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sSendLength = sTxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sSendLength > 0)
|
||||||
|
{
|
||||||
|
#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART
|
||||||
|
/* duplicate the output to the debug uart */
|
||||||
|
otSysDebugUart_write_bytes(reinterpret_cast<uint8_t *>(sTxBuffer + sTxHead), sSendLength);
|
||||||
|
#endif
|
||||||
|
IgnoreError(otPlatUartSend(reinterpret_cast<uint8_t *>(sTxBuffer + sTxHead), sSendLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Uart::Output(const char *aBuf, uint16_t aBufLength)
|
static void SendDoneTask(void)
|
||||||
|
{
|
||||||
|
sTxHead = (sTxHead + sSendLength) % kTxBufferSize;
|
||||||
|
sTxLength -= sSendLength;
|
||||||
|
sSendLength = 0;
|
||||||
|
|
||||||
|
Send();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Output(const char *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
OT_CLI_UART_OUTPUT_LOCK();
|
OT_CLI_UART_OUTPUT_LOCK();
|
||||||
uint16_t sent = 0;
|
uint16_t sent = 0;
|
||||||
|
|
||||||
while (aBufLength > 0)
|
while (aBufLength > 0)
|
||||||
{
|
{
|
||||||
uint16_t remaining = kTxBufferSize - mTxLength;
|
uint16_t remaining = kTxBufferSize - sTxLength;
|
||||||
uint16_t tail;
|
uint16_t tail;
|
||||||
uint16_t sendLength = aBufLength;
|
uint16_t sendLength = aBufLength;
|
||||||
|
|
||||||
@@ -258,10 +290,10 @@ int Uart::Output(const char *aBuf, uint16_t aBufLength)
|
|||||||
|
|
||||||
for (uint16_t i = 0; i < sendLength; i++)
|
for (uint16_t i = 0; i < sendLength; i++)
|
||||||
{
|
{
|
||||||
tail = (mTxHead + mTxLength) % kTxBufferSize;
|
tail = (sTxHead + sTxLength) % kTxBufferSize;
|
||||||
mTxBuffer[tail] = *aBuf++;
|
sTxBuffer[tail] = *aBuf++;
|
||||||
aBufLength--;
|
aBufLength--;
|
||||||
mTxLength++;
|
sTxLength++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Send();
|
Send();
|
||||||
@@ -291,57 +323,98 @@ int Uart::Output(const char *aBuf, uint16_t aBufLength)
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uart::Send(void)
|
static int CliUartOutput(void *aContext, const char *aFormat, va_list aArguments)
|
||||||
{
|
{
|
||||||
VerifyOrExit(mSendLength == 0);
|
OT_UNUSED_VARIABLE(aContext);
|
||||||
|
|
||||||
if (mTxLength > kTxBufferSize - mTxHead)
|
int rval;
|
||||||
|
|
||||||
|
if (sTxLength == 0)
|
||||||
{
|
{
|
||||||
mSendLength = kTxBufferSize - mTxHead;
|
rval = vsnprintf(sTxBuffer, kTxBufferSize, aFormat, aArguments);
|
||||||
|
VerifyOrExit(rval > 0 && rval < kTxBufferSize, otLogWarnPlat("Failed to format CLI output `%s`", aFormat));
|
||||||
|
sTxHead = 0;
|
||||||
|
sTxLength = static_cast<uint16_t>(rval);
|
||||||
|
sSendLength = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSendLength = mTxLength;
|
va_list retryArguments;
|
||||||
|
uint16_t tail = (sTxHead + sTxLength) % kTxBufferSize;
|
||||||
|
uint16_t remaining = (sTxHead > tail ? (sTxHead - tail) : (kTxBufferSize - tail));
|
||||||
|
|
||||||
|
va_copy(retryArguments, aArguments);
|
||||||
|
|
||||||
|
rval = vsnprintf(&sTxBuffer[tail], remaining, aFormat, aArguments);
|
||||||
|
|
||||||
|
if (rval < 0)
|
||||||
|
{
|
||||||
|
otLogWarnPlat("Failed to format CLI output `%s`", aFormat);
|
||||||
|
}
|
||||||
|
else if (rval < remaining)
|
||||||
|
{
|
||||||
|
sTxLength += rval;
|
||||||
|
}
|
||||||
|
else if (rval < kTxBufferSize)
|
||||||
|
{
|
||||||
|
while (sTxLength != 0)
|
||||||
|
{
|
||||||
|
otError error;
|
||||||
|
|
||||||
|
Send();
|
||||||
|
|
||||||
|
error = otPlatUartFlush();
|
||||||
|
|
||||||
|
if (error == OT_ERROR_NONE)
|
||||||
|
{
|
||||||
|
// Flush successful, reset the pointers
|
||||||
|
SendDoneTask();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Flush did not succeed, so abort here.
|
||||||
|
otLogWarnPlat("Failed to output CLI: %s", otThreadErrorToString(error));
|
||||||
|
ExitNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rval = vsnprintf(sTxBuffer, kTxBufferSize, aFormat, retryArguments);
|
||||||
|
OT_ASSERT(rval > 0);
|
||||||
|
sTxLength = static_cast<uint16_t>(rval);
|
||||||
|
sTxHead = 0;
|
||||||
|
sSendLength = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
otLogWarnPlat("CLI output `%s` truncated", aFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(retryArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSendLength > 0)
|
|
||||||
{
|
|
||||||
#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART
|
|
||||||
/* duplicate the output to the debug uart */
|
|
||||||
otPlatDebugUart_write_bytes(reinterpret_cast<uint8_t *>(mTxBuffer + mTxHead), mSendLength);
|
|
||||||
#endif
|
|
||||||
IgnoreError(otPlatUartSend(reinterpret_cast<uint8_t *>(mTxBuffer + mTxHead), mSendLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Uart::SendDoneTask(void)
|
|
||||||
{
|
|
||||||
mTxHead = (mTxHead + mSendLength) % kTxBufferSize;
|
|
||||||
mTxLength -= mSendLength;
|
|
||||||
mSendLength = 0;
|
|
||||||
|
|
||||||
Send();
|
Send();
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otCliUartInit(otInstance *aInstance)
|
void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
Uart::Initialize(aInstance);
|
ReceiveTask(aBuf, aBufLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
void otPlatUartSendDone(void)
|
||||||
{
|
{
|
||||||
static_cast<Uart &>(Interpreter::GetInterpreter()).ReceiveTask(aBuf, aBufLength);
|
SendDoneTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otPlatUartSendDone(void)
|
extern "C" void otAppCliInit(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
static_cast<Uart &>(Interpreter::GetInterpreter()).SendDoneTask();
|
sRxLength = 0;
|
||||||
|
sTxHead = 0;
|
||||||
|
sTxLength = 0;
|
||||||
|
sSendLength = 0;
|
||||||
|
|
||||||
|
IgnoreError(otPlatUartEnable());
|
||||||
|
|
||||||
|
otCliInit(aInstance, CliUartOutput, aInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Cli
|
|
||||||
} // namespace ot
|
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART
|
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
add_executable(ot-cli-ftd
|
add_executable(ot-cli-ftd
|
||||||
|
cli_uart.cpp
|
||||||
main.c
|
main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ target_link_libraries(ot-cli-ftd PRIVATE
|
|||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
|
openthread-cli-ftd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,6 +38,14 @@
|
|||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
#include "cli/cli_config.h"
|
#include "cli/cli_config.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function initializes the CLI app.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern void otAppCliInit(otInstance *aInstance);
|
||||||
|
|
||||||
#if OPENTHREAD_EXAMPLES_SIMULATION
|
#if OPENTHREAD_EXAMPLES_SIMULATION
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -107,9 +115,7 @@ pseudo_reset:
|
|||||||
#endif
|
#endif
|
||||||
assert(instance);
|
assert(instance);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_UART
|
otAppCliInit(instance);
|
||||||
otCliUartInit(instance);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (!otSysPseudoResetWasRequested())
|
while (!otSysPseudoResetWasRequested())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
add_executable(ot-cli-mtd
|
add_executable(ot-cli-mtd
|
||||||
|
cli_uart.cpp
|
||||||
main.c
|
main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ target_link_libraries(ot-cli-mtd PRIVATE
|
|||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
openthread-mtd
|
openthread-mtd
|
||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
|
openthread-cli-mtd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
|
|||||||
|
|
||||||
CPPFLAGS_COMMON += \
|
CPPFLAGS_COMMON += \
|
||||||
-I$(top_srcdir)/include \
|
-I$(top_srcdir)/include \
|
||||||
|
-I$(top_srcdir)/src \
|
||||||
-I$(top_srcdir)/src/core \
|
-I$(top_srcdir)/src/core \
|
||||||
-I$(top_srcdir)/examples/platforms \
|
-I$(top_srcdir)/examples/platforms \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
@@ -49,6 +50,7 @@ LIBTOOLFLAGS_COMMON += \
|
|||||||
|
|
||||||
SOURCES_COMMON += \
|
SOURCES_COMMON += \
|
||||||
main.c \
|
main.c \
|
||||||
|
ncp.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
LDADD_MBEDTLS = \
|
LDADD_MBEDTLS = \
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
add_executable(ot-ncp-ftd
|
add_executable(ot-ncp-ftd
|
||||||
main.c
|
main.c
|
||||||
|
ncp.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ot-ncp-ftd PRIVATE ${COMMON_INCLUDES})
|
target_include_directories(ot-ncp-ftd PRIVATE ${COMMON_INCLUDES})
|
||||||
@@ -37,6 +38,7 @@ target_link_libraries(ot-ncp-ftd PRIVATE
|
|||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
openthread-ftd
|
openthread-ftd
|
||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
|
openthread-ncp-ftd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -36,6 +36,14 @@
|
|||||||
|
|
||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function initializes the NCP app.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern void otAppNcpInit(otInstance *aInstance);
|
||||||
|
|
||||||
#if OPENTHREAD_EXAMPLES_SIMULATION
|
#if OPENTHREAD_EXAMPLES_SIMULATION
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -105,7 +113,7 @@ pseudo_reset:
|
|||||||
#endif
|
#endif
|
||||||
assert(instance);
|
assert(instance);
|
||||||
|
|
||||||
otNcpInit(instance);
|
otAppNcpInit(instance);
|
||||||
|
|
||||||
while (!otSysPseudoResetWasRequested())
|
while (!otSysPseudoResetWasRequested())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
add_executable(ot-ncp-mtd
|
add_executable(ot-ncp-mtd
|
||||||
main.c
|
main.c
|
||||||
|
ncp.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ot-ncp-mtd PRIVATE ${COMMON_INCLUDES})
|
target_include_directories(ot-ncp-mtd PRIVATE ${COMMON_INCLUDES})
|
||||||
@@ -37,6 +38,7 @@ target_link_libraries(ot-ncp-mtd PRIVATE
|
|||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
openthread-mtd
|
openthread-mtd
|
||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
|
openthread-ncp-mtd
|
||||||
${OT_MBEDTLS}
|
${OT_MBEDTLS}
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, The OpenThread Authors.
|
* Copyright (c) 2021, The OpenThread Authors.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -26,69 +26,45 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OPENTHREAD_CONSOLE_CLI_H_
|
#include "openthread-core-config.h"
|
||||||
#define OPENTHREAD_CONSOLE_CLI_H_
|
|
||||||
|
|
||||||
#include "platform/openthread-posix-config.h"
|
#include <openthread/ncp.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "common/code_utils.hpp"
|
||||||
|
|
||||||
#include <openthread/openthread-system.h>
|
#include "ncp/ncp_config.h"
|
||||||
|
|
||||||
#include "cli/cli_config.h"
|
#if !OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
#ifndef HAVE_LIBEDIT
|
void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
#define HAVE_LIBEDIT 0
|
{
|
||||||
#endif
|
otNcpHdlcReceive(aBuf, aBufLength);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAVE_LIBREADLINE
|
void otPlatUartSendDone(void)
|
||||||
#define HAVE_LIBREADLINE 0
|
{
|
||||||
#endif
|
otNcpHdlcSendDone();
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE
|
|
||||||
#define OPENTHREAD_USE_CONSOLE 1
|
|
||||||
#if !(HAVE_LIBEDIT || HAVE_LIBREADLINE) || OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
|
||||||
#error \
|
|
||||||
"When OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_CONSOLE, HAVE_LIBEDIT or HAVE_LIBREADLINE MUST be defined and OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE MUST be 0"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function initializes CLI console.
|
|
||||||
*
|
|
||||||
* @param[in] aInstance A pointer to the OpenThread instance.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otxConsoleInit(otInstance *aInstance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function deinitializes CLI console
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otxConsoleDeinit(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function updates the file descriptor sets with file descriptors used by console.
|
|
||||||
*
|
|
||||||
* @param[inout] aMainloop A pointer to the mainloop context.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otxConsoleUpdate(otSysMainloopContext *aMainloop);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function performs console driver processing.
|
|
||||||
*
|
|
||||||
* @param[in] aMainloop A pointer to the mainloop context.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otxConsoleProcess(const otSysMainloopContext *aMainloop);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONSOLE_CLI_H_
|
#if !OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
|
||||||
|
#if !OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||||
|
static int NcpSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
|
{
|
||||||
|
IgnoreError(otPlatUartSend(aBuf, aBufLength));
|
||||||
|
return aBufLength;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void otAppNcpInit(otInstance *aInstance)
|
||||||
|
{
|
||||||
|
#if OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||||
|
otNcpSpiInit(aInstance);
|
||||||
|
#else
|
||||||
|
IgnoreError(otPlatUartEnable());
|
||||||
|
|
||||||
|
otNcpHdlcInit(aInstance, NcpSend);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif // !OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
add_executable(ot-rcp
|
add_executable(ot-rcp
|
||||||
main.c
|
main.c
|
||||||
|
ncp.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ot-rcp PRIVATE ${COMMON_INCLUDES})
|
target_include_directories(ot-rcp PRIVATE ${COMMON_INCLUDES})
|
||||||
@@ -37,6 +38,7 @@ target_link_libraries(ot-rcp PRIVATE
|
|||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
openthread-radio
|
openthread-radio
|
||||||
${OT_PLATFORM_LIB}
|
${OT_PLATFORM_LIB}
|
||||||
|
openthread-rcp
|
||||||
ot-config
|
ot-config
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ COVERAGE ?= 0
|
|||||||
CHANNEL_MANAGER ?= 0
|
CHANNEL_MANAGER ?= 0
|
||||||
CHANNEL_MONITOR ?= 0
|
CHANNEL_MONITOR ?= 0
|
||||||
CHILD_SUPERVISION ?= 0
|
CHILD_SUPERVISION ?= 0
|
||||||
CLI_TRANSPORT ?= UART
|
|
||||||
DATASET_UPDATER ?= 0
|
DATASET_UPDATER ?= 0
|
||||||
DEBUG ?= 0
|
DEBUG ?= 0
|
||||||
DHCP6_CLIENT ?= 0
|
DHCP6_CLIENT ?= 0
|
||||||
@@ -143,10 +142,6 @@ ifeq ($(CHILD_SUPERVISION),1)
|
|||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(CLI_TRANSPORT),)
|
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_$(CLI_TRANSPORT)
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CSL_RECEIVER),1)
|
ifeq ($(CSL_RECEIVER),1)
|
||||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1
|
COMMONCFLAGS += -DOPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -48,11 +48,11 @@
|
|||||||
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1
|
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
#endif /* OPENTHREAD_CORE_CC1352_CONFIG_H_ */
|
#endif /* OPENTHREAD_CORE_CC1352_CONFIG_H_ */
|
||||||
|
|||||||
@@ -41,11 +41,9 @@
|
|||||||
|
|
||||||
#include <openthread/platform/debug_uart.h>
|
#include <openthread/platform/debug_uart.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
#include <utils/code_utils.h>
|
|
||||||
|
|
||||||
#include <driverlib/ioc.h>
|
#include <driverlib/ioc.h>
|
||||||
#include <driverlib/prcm.h>
|
#include <driverlib/prcm.h>
|
||||||
@@ -116,7 +114,7 @@ static void uart_power_control(uint32_t who_base, int turnon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartEnable(void)
|
otError otPlatUartEnable(void)
|
||||||
{
|
{
|
||||||
@@ -138,7 +136,7 @@ otError otPlatUartEnable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartDisable(void)
|
otError otPlatUartDisable(void)
|
||||||
{
|
{
|
||||||
@@ -154,7 +152,7 @@ otError otPlatUartDisable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ endif()
|
|||||||
|
|
||||||
list(APPEND OT_PLATFORM_DEFINES
|
list(APPEND OT_PLATFORM_DEFINES
|
||||||
"OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\""
|
"OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\""
|
||||||
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
)
|
)
|
||||||
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
|
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
|
||||||
|
|
||||||
|
|||||||
@@ -83,12 +83,12 @@
|
|||||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 1
|
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT
|
* @def OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT
|
||||||
|
|||||||
@@ -41,10 +41,10 @@
|
|||||||
|
|
||||||
#include <openthread/platform/debug_uart.h>
|
#include <openthread/platform/debug_uart.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "platform-cc2538.h"
|
#include "platform-cc2538.h"
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,12 +45,12 @@
|
|||||||
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 32
|
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 32
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_SETTINGS_RAM
|
* @def OPENTHREAD_SETTINGS_RAM
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
#include <driverlib/uart.h>
|
#include <driverlib/uart.h>
|
||||||
|
|
||||||
#include <utils/code_utils.h>
|
#include <utils/code_utils.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \note this will configure the uart for 115200 baud 8-N-1, no HW flow control
|
* \note this will configure the uart for 115200 baud 8-N-1, no HW flow control
|
||||||
@@ -58,7 +59,7 @@ static uint16_t sReceiveTailIdx = 0;
|
|||||||
void UART0_intHandler(void);
|
void UART0_intHandler(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartEnable(void)
|
otError otPlatUartEnable(void)
|
||||||
{
|
{
|
||||||
@@ -86,7 +87,7 @@ otError otPlatUartEnable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartDisable(void)
|
otError otPlatUartDisable(void)
|
||||||
{
|
{
|
||||||
@@ -109,7 +110,7 @@ otError otPlatUartDisable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,11 +48,11 @@
|
|||||||
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1
|
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
#endif /* OPENTHREAD_CORE_CC2650_CONFIG_H_ */
|
#endif /* OPENTHREAD_CORE_CC2650_CONFIG_H_ */
|
||||||
|
|||||||
@@ -41,11 +41,9 @@
|
|||||||
|
|
||||||
#include <openthread/platform/debug_uart.h>
|
#include <openthread/platform/debug_uart.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
#include <utils/code_utils.h>
|
|
||||||
|
|
||||||
#include <driverlib/ioc.h>
|
#include <driverlib/ioc.h>
|
||||||
#include <driverlib/prcm.h>
|
#include <driverlib/prcm.h>
|
||||||
@@ -116,7 +114,7 @@ static void uart_power_control(uint32_t who_base, int turnon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartEnable(void)
|
otError otPlatUartEnable(void)
|
||||||
{
|
{
|
||||||
@@ -138,7 +136,7 @@ otError otPlatUartEnable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartDisable(void)
|
otError otPlatUartDisable(void)
|
||||||
{
|
{
|
||||||
@@ -154,7 +152,7 @@ otError otPlatUartDisable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function documented in platform/uart.h
|
* Function documented in utils/uart.h
|
||||||
*/
|
*/
|
||||||
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -141,12 +141,12 @@
|
|||||||
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 0
|
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS
|
* @def OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "common/logging.hpp"
|
#include "common/logging.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -36,9 +36,9 @@
|
|||||||
|
|
||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
#include <openthread-core-config.h>
|
#include <openthread-core-config.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
#include "ecode.h"
|
#include "ecode.h"
|
||||||
#include "em_core.h"
|
#include "em_core.h"
|
||||||
|
|||||||
@@ -124,13 +124,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define as 1 to enable UART NCP interface.
|
* Define as 1 to enable UART NCP interface.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // OPENTHREAD_CORE_GP712_CONFIG_H_
|
#endif // OPENTHREAD_CORE_GP712_CONFIG_H_
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
#include <openthread/tasklet.h>
|
#include <openthread/tasklet.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "alarm_qorvo.h"
|
#include "alarm_qorvo.h"
|
||||||
#include "platform_qorvo.h"
|
#include "platform_qorvo.h"
|
||||||
|
|||||||
@@ -40,9 +40,8 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
|||||||
@@ -102,12 +102,12 @@
|
|||||||
/* TODO */
|
/* TODO */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_SETTINGS_RAM
|
* @def OPENTHREAD_SETTINGS_RAM
|
||||||
|
|||||||
@@ -102,12 +102,12 @@
|
|||||||
/* TODO */
|
/* TODO */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_SETTINGS_RAM
|
* @def OPENTHREAD_SETTINGS_RAM
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
#include <openthread/config.h>
|
#include <openthread/config.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#include <openthread/platform/toolchain.h>
|
#include <openthread/platform/toolchain.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include "clock_config.h"
|
#include "clock_config.h"
|
||||||
#include "pin_mux.h"
|
#include "pin_mux.h"
|
||||||
#include "platform-k32w.h"
|
#include "platform-k32w.h"
|
||||||
#include "openthread/platform/uart.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
/* Openthread general includes */
|
/* Openthread general includes */
|
||||||
#include <utils/code_utils.h>
|
#include <utils/code_utils.h>
|
||||||
#include "openthread/platform/uart.h"
|
#include <utils/uart.h>
|
||||||
|
|
||||||
#if USE_RTOS
|
#if USE_RTOS
|
||||||
#include "UART_Serial_Adapter.h"
|
#include "UART_Serial_Adapter.h"
|
||||||
|
|||||||
@@ -95,11 +95,11 @@
|
|||||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 0
|
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
#endif // OPENTHREAD_CORE_KW41Z_CONFIG_H_
|
#endif // OPENTHREAD_CORE_KW41Z_CONFIG_H_
|
||||||
|
|||||||
@@ -38,7 +38,8 @@
|
|||||||
#include "fsl_port.h"
|
#include "fsl_port.h"
|
||||||
#include "platform-kw41z.h"
|
#include "platform-kw41z.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "openthread/platform/uart.h"
|
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
otInstance *sInstance;
|
otInstance *sInstance;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <utils/code_utils.h>
|
#include <utils/code_utils.h>
|
||||||
#include "openthread/platform/uart.h"
|
#include <utils/uart.h>
|
||||||
|
|
||||||
#include "fsl_clock.h"
|
#include "fsl_clock.h"
|
||||||
#include "fsl_lpuart.h"
|
#include "fsl_lpuart.h"
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <utils/code_utils.h>
|
#include <utils/code_utils.h>
|
||||||
|
#include <utils/uart.h>
|
||||||
#include <openthread/platform/toolchain.h>
|
#include <openthread/platform/toolchain.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@
|
|||||||
#include <common/logging.hpp>
|
#include <common/logging.hpp>
|
||||||
#include <openthread-system.h>
|
#include <openthread-system.h>
|
||||||
#include <utils/code_utils.h>
|
#include <utils/code_utils.h>
|
||||||
|
#include <utils/uart.h>
|
||||||
#include <openthread/platform/alarm-milli.h>
|
#include <openthread/platform/alarm-milli.h>
|
||||||
#include <openthread/platform/diag.h>
|
#include <openthread/platform/diag.h>
|
||||||
#include <openthread/platform/misc.h>
|
#include <openthread/platform/misc.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "platform-nrf5-transport.h"
|
#include "platform-nrf5-transport.h"
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "random_qorvo.h"
|
#include "random_qorvo.h"
|
||||||
#include "uart_qorvo.h"
|
#include "uart_qorvo.h"
|
||||||
#include <openthread/tasklet.h>
|
#include <openthread/tasklet.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|||||||
@@ -41,7 +41,8 @@
|
|||||||
#define HAVE__BOOL 1
|
#define HAVE__BOOL 1
|
||||||
|
|
||||||
#include <common/code_utils.hpp>
|
#include <common/code_utils.hpp>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
otError otPlatUartEnable(void)
|
otError otPlatUartEnable(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,13 +124,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define as 1 to enable UART NCP interface.
|
* Define as 1 to enable UART NCP interface.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // OPENTHREAD_CORE_QPG7015M_CONFIG_H_
|
#endif // OPENTHREAD_CORE_QPG7015M_CONFIG_H_
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ extern uint32_t __d_nv_mem_end;
|
|||||||
#define OPENTHREAD_CONFIG_DEFAULT_TRANSMIT_POWER 5
|
#define OPENTHREAD_CONFIG_DEFAULT_TRANSMIT_POWER 5
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
#endif // OPENTHREAD_CORE_SAMR21_CONFIG_H_
|
#endif // OPENTHREAD_CORE_SAMR21_CONFIG_H_
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#include "asf.h"
|
#include "asf.h"
|
||||||
|
|
||||||
#include <openthread/platform/uart.h>
|
#include "utils/uart.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ list(APPEND OT_PLATFORM_DEFINES
|
|||||||
"_BSD_SOURCE=1"
|
"_BSD_SOURCE=1"
|
||||||
"_DEFAULT_SOURCE=1"
|
"_DEFAULT_SOURCE=1"
|
||||||
"OPENTHREAD_EXAMPLES_SIMULATION=1"
|
"OPENTHREAD_EXAMPLES_SIMULATION=1"
|
||||||
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
)
|
)
|
||||||
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
|
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include <openthread/config.h>
|
#include <openthread/config.h>
|
||||||
#include <openthread/platform/spi-slave.h>
|
#include <openthread/platform/spi-slave.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
#if OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <openthread/platform/debug_uart.h>
|
#include <openthread/platform/debug_uart.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "utils/code_utils.h"
|
#include "utils/code_utils.h"
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
#if OPENTHREAD_SIMULATION_VIRTUAL_TIME_UART == 0
|
#if OPENTHREAD_SIMULATION_VIRTUAL_TIME_UART == 0
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@
|
|||||||
|
|
||||||
#include <openthread/tasklet.h>
|
#include <openthread/tasklet.h>
|
||||||
#include <openthread/platform/alarm-milli.h>
|
#include <openthread/platform/alarm-milli.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
#include "utils/uart.h"
|
||||||
|
|
||||||
uint32_t gNodeId = 1;
|
uint32_t gNodeId = 1;
|
||||||
|
|
||||||
@@ -168,7 +169,7 @@ otError otPlatUartSend(const uint8_t *aData, uint16_t aLength)
|
|||||||
|
|
||||||
otError otPlatUartFlush(void)
|
otError otPlatUartFlush(void)
|
||||||
{
|
{
|
||||||
return OT_ERROR_NOT_IMPLEMENTED;
|
return OT_ERROR_NONE;
|
||||||
}
|
}
|
||||||
#endif // OPENTHREAD_SIMULATION_VIRTUAL_TIME_UART
|
#endif // OPENTHREAD_SIMULATION_VIRTUAL_TIME_UART
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ libopenthread_platform_utils_a_SOURCES = \
|
|||||||
settings_ram.c \
|
settings_ram.c \
|
||||||
soft_source_match_table.c \
|
soft_source_match_table.c \
|
||||||
soft_source_match_table.h \
|
soft_source_match_table.h \
|
||||||
|
uart.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
libopenthread_platform_utils_a_LIBADD = \
|
libopenthread_platform_utils_a_LIBADD = \
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ ot_platform_headers = \
|
|||||||
openthread/platform/time.h \
|
openthread/platform/time.h \
|
||||||
openthread/platform/toolchain.h \
|
openthread/platform/toolchain.h \
|
||||||
openthread/platform/trel-udp6.h \
|
openthread/platform/trel-udp6.h \
|
||||||
openthread/platform/uart.h \
|
|
||||||
openthread/platform/udp.h \
|
openthread/platform/udp.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,8 @@
|
|||||||
/* Define to 1 if you want to use legacy network support */
|
/* Define to 1 if you want to use legacy network support */
|
||||||
#define OPENTHREAD_CONFIG_LEGACY_ENABLE 1
|
#define OPENTHREAD_CONFIG_LEGACY_ENABLE 1
|
||||||
|
|
||||||
/* Define to 1 to enable the NCP UART interface. */
|
/* Define to 1 to enable the NCP HDLC interface. */
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||||
|
|
||||||
/* Define to 1 to enable posix platform. */
|
/* Define to 1 to enable posix platform. */
|
||||||
#define OPENTHREAD_PLATFORM_POSIX 1
|
#define OPENTHREAD_PLATFORM_POSIX 1
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ source_set("openthread") {
|
|||||||
"platform/time.h",
|
"platform/time.h",
|
||||||
"platform/toolchain.h",
|
"platform/toolchain.h",
|
||||||
"platform/trel-udp6.h",
|
"platform/trel-udp6.h",
|
||||||
"platform/uart.h",
|
|
||||||
"platform/udp.h",
|
"platform/udp.h",
|
||||||
"random_crypto.h",
|
"random_crypto.h",
|
||||||
"random_noncrypto.h",
|
"random_noncrypto.h",
|
||||||
|
|||||||
@@ -74,20 +74,20 @@ typedef struct otCliCommand
|
|||||||
* @param[in] aBufLength A length of the output data stored in the buffer.
|
* @param[in] aBufLength A length of the output data stored in the buffer.
|
||||||
* @param[out] aContext A user context pointer.
|
* @param[out] aContext A user context pointer.
|
||||||
*
|
*
|
||||||
* @returns Number of bytes processed by the callback.
|
* @returns Number of bytes written by the callback.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef int (*otCliConsoleOutputCallback)(const char *aBuf, uint16_t aBufLength, void *aContext);
|
typedef int (*otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the CLI CONSOLE module.
|
* Initialize the CLI module.
|
||||||
*
|
*
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
* @param[in] aCallback A callback method called to process console output.
|
* @param[in] aCallback A callback method called to process CLI output.
|
||||||
* @param[in] aContext A user context pointer.
|
* @param[in] aContext A user context pointer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext);
|
void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called to feed in a console input line.
|
* This method is called to feed in a console input line.
|
||||||
@@ -95,15 +95,7 @@ void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallbac
|
|||||||
* @param[in] aBuf A pointer to a null-terminated string.
|
* @param[in] aBuf A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void otCliConsoleInputLine(char *aBuf);
|
void otCliInputLine(char *aBuf);
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the CLI UART module.
|
|
||||||
*
|
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otCliUartInit(otInstance *aInstance);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a user command table.
|
* Set a user command table.
|
||||||
@@ -133,15 +125,6 @@ void otCliOutputBytes(const uint8_t *aBytes, uint8_t aLength);
|
|||||||
*/
|
*/
|
||||||
void otCliOutputFormat(const char *aFmt, ...);
|
void otCliOutputFormat(const char *aFmt, ...);
|
||||||
|
|
||||||
/**
|
|
||||||
* Write string to the CLI console
|
|
||||||
*
|
|
||||||
* @param[in] aString A pointer to the string, which may not be null-terminated.
|
|
||||||
* @param[in] aLength Number of bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void otCliOutput(const char *aString, uint16_t aLength);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write error code to the CLI console
|
* Write error code to the CLI console
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ extern "C" {
|
|||||||
* @note This number versions both OpenThread platform and user APIs.
|
* @note This number versions both OpenThread platform and user APIs.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_API_VERSION (84)
|
#define OPENTHREAD_API_VERSION (85)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup api-instance
|
* @addtogroup api-instance
|
||||||
|
|||||||
@@ -55,12 +55,47 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the NCP.
|
* This function pointer is called to send HDLC encoded NCP data.
|
||||||
|
*
|
||||||
|
* @param[in] aBuf A pointer to a buffer with an output.
|
||||||
|
* @param[in] aBufLength A length of the output data stored in the buffer.
|
||||||
|
*
|
||||||
|
* @returns Number of bytes processed by the callback.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef int (*otNcpHdlcSendCallback)(const uint8_t *aBuf, uint16_t aBufLength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called after NCP send finished.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otNcpHdlcSendDone(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called after HDLC encoded NCP data received.
|
||||||
|
*
|
||||||
|
* @param[in] aBuf A pointer to a buffer.
|
||||||
|
* @param[in] aBufLength The length of the data stored in the buffer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otNcpHdlcReceive(const uint8_t *aBuf, uint16_t aBufLength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the NCP based on HDLC framing.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
* @param[in] aSendCallback The function pointer used to send NCP data.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSendCallback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the NCP based on SPI framing.
|
||||||
*
|
*
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void otNcpInit(otInstance *aInstance);
|
void otNcpSpiInit(otInstance *aInstance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send data to the host via a specific stream.
|
* @brief Send data to the host via a specific stream.
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ check_targets()
|
|||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 USE_OTBR_DAEMON=1 check_targets ot-cli ot-ctl ot-ncp
|
OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 USE_OTBR_DAEMON=1 check_targets ot-cli ot-ctl
|
||||||
OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 check_targets ot-cli ot-ncp spi-hdlc-adapter
|
OPENTHREAD_ENABLE_ANDROID_MK=1 ANDROID_NDK=1 check_targets ot-cli spi-hdlc-adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ do_scan_build()
|
|||||||
scan-build-9 ./configure "${configure_options[@]}"
|
scan-build-9 ./configure "${configure_options[@]}"
|
||||||
scan-build-9 --status-bugs -analyze-headers -v make -j"${OT_BUILD_JOBS}"
|
scan-build-9 --status-bugs -analyze-headers -v make -j"${OT_BUILD_JOBS}"
|
||||||
|
|
||||||
export CPPFLAGS="${options[*]} -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
export CPPFLAGS="${options[*]} -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
scan-build-9 ./configure "${configure_options[@]}"
|
scan-build-9 ./configure "${configure_options[@]}"
|
||||||
scan-build-9 --status-bugs -analyze-headers -v make -j"${OT_BUILD_JOBS}"
|
scan-build-9 --status-bugs -analyze-headers -v make -j"${OT_BUILD_JOBS}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ build_all_features()
|
|||||||
"-DOPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_MPL_DYNAMIC_INTERVAL_ENABLE"
|
"-DOPENTHREAD_CONFIG_MPL_DYNAMIC_INTERVAL_ENABLE"
|
||||||
|
"-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1"
|
||||||
@@ -154,7 +154,7 @@ build_nest_common()
|
|||||||
"-DOPENTHREAD_CONFIG_ANOUNCE_SENDER_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_ANOUNCE_SENDER_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_TIME_SYNC_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_TIME_SYNC_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
)
|
)
|
||||||
export CPPFLAGS="${options[*]}"
|
export CPPFLAGS="${options[*]}"
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ build_nest_common()
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
options=(
|
options=(
|
||||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||||
)
|
)
|
||||||
export CPPFLAGS="${options[*]}"
|
export CPPFLAGS="${options[*]}"
|
||||||
@@ -197,7 +197,7 @@ build_multi_radio_links()
|
|||||||
{
|
{
|
||||||
# TREL radio link only.
|
# TREL radio link only.
|
||||||
local options=(
|
local options=(
|
||||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG"
|
"-DOPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG"
|
||||||
"-DOPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE=0"
|
"-DOPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE=0"
|
||||||
@@ -221,7 +221,7 @@ build_multi_radio_links()
|
|||||||
|
|
||||||
# Multi radio link - 15.4 and TREL.
|
# Multi radio link - 15.4 and TREL.
|
||||||
options=(
|
options=(
|
||||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"
|
||||||
"-DOPENTHREAD_CONFIG_LINK_RAW_ENABLE=1"
|
"-DOPENTHREAD_CONFIG_LINK_RAW_ENABLE=1"
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ openthread_cli_sources = [
|
|||||||
"cli_commissioner.cpp",
|
"cli_commissioner.cpp",
|
||||||
"cli_commissioner.hpp",
|
"cli_commissioner.hpp",
|
||||||
"cli_config.h",
|
"cli_config.h",
|
||||||
"cli_console.cpp",
|
|
||||||
"cli_console.hpp",
|
|
||||||
"cli_dataset.cpp",
|
"cli_dataset.cpp",
|
||||||
"cli_dataset.hpp",
|
"cli_dataset.hpp",
|
||||||
"cli_joiner.cpp",
|
"cli_joiner.cpp",
|
||||||
@@ -49,8 +47,6 @@ openthread_cli_sources = [
|
|||||||
"cli_srp_client.hpp",
|
"cli_srp_client.hpp",
|
||||||
"cli_srp_server.cpp",
|
"cli_srp_server.cpp",
|
||||||
"cli_srp_server.hpp",
|
"cli_srp_server.hpp",
|
||||||
"cli_uart.cpp",
|
|
||||||
"cli_uart.hpp",
|
|
||||||
"cli_udp.cpp",
|
"cli_udp.cpp",
|
||||||
"cli_udp.hpp",
|
"cli_udp.hpp",
|
||||||
"x509_cert_key.hpp",
|
"x509_cert_key.hpp",
|
||||||
|
|||||||
@@ -26,13 +26,6 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
|
||||||
set(OT_CLI_TRANSPORT "UART" CACHE STRING "set the CLI transport")
|
|
||||||
set(OT_CLI_TRANSPORT_VALUES
|
|
||||||
"UART"
|
|
||||||
"CONSOLE"
|
|
||||||
)
|
|
||||||
set_property(CACHE OT_CLI_TRANSPORT PROPERTY STRINGS ${OT_CLI_TRANSPORT_VALUES})
|
|
||||||
|
|
||||||
set(COMMON_INCLUDES
|
set(COMMON_INCLUDES
|
||||||
${PROJECT_SOURCE_DIR}/src
|
${PROJECT_SOURCE_DIR}/src
|
||||||
${PROJECT_SOURCE_DIR}/src/core
|
${PROJECT_SOURCE_DIR}/src/core
|
||||||
@@ -43,13 +36,11 @@ set(COMMON_SOURCES
|
|||||||
cli_coap.cpp
|
cli_coap.cpp
|
||||||
cli_coap_secure.cpp
|
cli_coap_secure.cpp
|
||||||
cli_commissioner.cpp
|
cli_commissioner.cpp
|
||||||
cli_console.cpp
|
|
||||||
cli_dataset.cpp
|
cli_dataset.cpp
|
||||||
cli_joiner.cpp
|
cli_joiner.cpp
|
||||||
cli_network_data.cpp
|
cli_network_data.cpp
|
||||||
cli_srp_client.cpp
|
cli_srp_client.cpp
|
||||||
cli_srp_server.cpp
|
cli_srp_server.cpp
|
||||||
cli_uart.cpp
|
|
||||||
cli_udp.cpp
|
cli_udp.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -144,13 +144,11 @@ SOURCES_COMMON = \
|
|||||||
cli_coap.cpp \
|
cli_coap.cpp \
|
||||||
cli_coap_secure.cpp \
|
cli_coap_secure.cpp \
|
||||||
cli_commissioner.cpp \
|
cli_commissioner.cpp \
|
||||||
cli_console.cpp \
|
|
||||||
cli_dataset.cpp \
|
cli_dataset.cpp \
|
||||||
cli_joiner.cpp \
|
cli_joiner.cpp \
|
||||||
cli_network_data.cpp \
|
cli_network_data.cpp \
|
||||||
cli_srp_client.cpp \
|
cli_srp_client.cpp \
|
||||||
cli_srp_server.cpp \
|
cli_srp_server.cpp \
|
||||||
cli_uart.cpp \
|
|
||||||
cli_udp.cpp \
|
cli_udp.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
@@ -168,13 +166,11 @@ noinst_HEADERS = \
|
|||||||
cli_coap_secure.hpp \
|
cli_coap_secure.hpp \
|
||||||
cli_commissioner.hpp \
|
cli_commissioner.hpp \
|
||||||
cli_config.h \
|
cli_config.h \
|
||||||
cli_console.hpp \
|
|
||||||
cli_dataset.hpp \
|
cli_dataset.hpp \
|
||||||
cli_joiner.hpp \
|
cli_joiner.hpp \
|
||||||
cli_network_data.hpp \
|
cli_network_data.hpp \
|
||||||
cli_srp_client.hpp \
|
cli_srp_client.hpp \
|
||||||
cli_srp_server.hpp \
|
cli_srp_server.hpp \
|
||||||
cli_uart.hpp \
|
|
||||||
cli_udp.hpp \
|
cli_udp.hpp \
|
||||||
x509_cert_key.hpp \
|
x509_cert_key.hpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|||||||
+24
-18
@@ -44,7 +44,6 @@
|
|||||||
#include <openthread/logging.h>
|
#include <openthread/logging.h>
|
||||||
#include <openthread/ncp.h>
|
#include <openthread/ncp.h>
|
||||||
#include <openthread/thread.h>
|
#include <openthread/thread.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||||
#include <openthread/network_time.h>
|
#include <openthread/network_time.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -110,9 +109,12 @@ namespace Cli {
|
|||||||
constexpr Interpreter::Command Interpreter::sCommands[];
|
constexpr Interpreter::Command Interpreter::sCommands[];
|
||||||
|
|
||||||
Interpreter *Interpreter::sInterpreter = nullptr;
|
Interpreter *Interpreter::sInterpreter = nullptr;
|
||||||
|
static OT_DEFINE_ALIGNED_VAR(sInterpreterRaw, sizeof(Interpreter), uint64_t);
|
||||||
|
|
||||||
Interpreter::Interpreter(Instance *aInstance)
|
Interpreter::Interpreter(Instance *aInstance, otCliOutputCallback aCallback, void *aContext)
|
||||||
: mInstance(aInstance)
|
: mInstance(aInstance)
|
||||||
|
, mOutputCallback(aCallback)
|
||||||
|
, mOutputContext(aContext)
|
||||||
, mUserCommands(nullptr)
|
, mUserCommands(nullptr)
|
||||||
, mUserCommandsLength(0)
|
, mUserCommandsLength(0)
|
||||||
, mPingLength(kDefaultPingLength)
|
, mPingLength(kDefaultPingLength)
|
||||||
@@ -4777,7 +4779,7 @@ otError Interpreter::ProcessDiag(uint8_t aArgsLength, char *aArgs[])
|
|||||||
output[sizeof(output) - 1] = '\0';
|
output[sizeof(output) - 1] = '\0';
|
||||||
|
|
||||||
error = otDiagProcessCmd(mInstance, aArgsLength, aArgs, output, sizeof(output) - 1);
|
error = otDiagProcessCmd(mInstance, aArgsLength, aArgs, output, sizeof(output) - 1);
|
||||||
Output(output, static_cast<uint16_t>(strlen(output)));
|
OutputFormat("%s", output);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -5161,24 +5163,33 @@ void Interpreter::OutputLine(uint8_t aIndentSize, const char *aFormat, ...)
|
|||||||
|
|
||||||
void Interpreter::OutputSpaces(uint8_t aCount)
|
void Interpreter::OutputSpaces(uint8_t aCount)
|
||||||
{
|
{
|
||||||
static const char kSpaces[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
|
char format[sizeof("%256s")];
|
||||||
|
|
||||||
while (aCount > 0)
|
snprintf(format, sizeof(format), "%%%us", aCount);
|
||||||
{
|
|
||||||
uint8_t len = OT_MIN(aCount, sizeof(kSpaces));
|
|
||||||
|
|
||||||
Output(kSpaces, len);
|
OutputFormat(format, "");
|
||||||
aCount -= len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Interpreter::OutputFormatV(const char *aFormat, va_list aArguments)
|
int Interpreter::OutputFormatV(const char *aFormat, va_list aArguments)
|
||||||
{
|
{
|
||||||
char buf[kMaxLineLength];
|
return mOutputCallback(mOutputContext, aFormat, aArguments);
|
||||||
|
}
|
||||||
|
|
||||||
vsnprintf(buf, sizeof(buf), aFormat, aArguments);
|
void Interpreter::Initialize(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
|
||||||
|
{
|
||||||
|
Instance *instance = static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
return Output(buf, static_cast<uint16_t>(strlen(buf)));
|
Interpreter::sInterpreter = new (&sInterpreterRaw) Interpreter(instance, aCallback, aContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
|
||||||
|
{
|
||||||
|
Interpreter::Initialize(aInstance, aCallback, aContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void otCliInputLine(char *aBuf)
|
||||||
|
{
|
||||||
|
Interpreter::GetInterpreter().ProcessLine(aBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength, void *aContext)
|
extern "C" void otCliSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength, void *aContext)
|
||||||
@@ -5199,11 +5210,6 @@ extern "C" void otCliOutputFormat(const char *aFmt, ...)
|
|||||||
va_end(aAp);
|
va_end(aAp);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otCliOutput(const char *aString, uint16_t aLength)
|
|
||||||
{
|
|
||||||
Interpreter::GetInterpreter().Output(aString, aLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void otCliAppendResult(otError aError)
|
extern "C" void otCliAppendResult(otError aError)
|
||||||
{
|
{
|
||||||
Interpreter::GetInterpreter().OutputResult(aError);
|
Interpreter::GetInterpreter().OutputResult(aError);
|
||||||
|
|||||||
+17
-2
@@ -96,9 +96,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
* @param[in] aCallback A callback method called to process CLI output.
|
||||||
|
* @param[in] aContext A user context pointer.
|
||||||
*/
|
*/
|
||||||
explicit Interpreter(Instance *aInstance);
|
explicit Interpreter(Instance *aInstance, otCliOutputCallback aCallback, void *aContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a reference to the interpreter object.
|
* This method returns a reference to the interpreter object.
|
||||||
@@ -113,6 +115,16 @@ public:
|
|||||||
return *sInterpreter;
|
return *sInterpreter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method initializes the Console interpreter.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
* @param[in] aCallback A pointer to a callback method.
|
||||||
|
* @param[in] aContext A pointer to a user context.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void Initialize(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns whether the interpreter is initialized.
|
* This method returns whether the interpreter is initialized.
|
||||||
*
|
*
|
||||||
@@ -792,6 +804,9 @@ private:
|
|||||||
static_assert(Utils::LookupTable::IsSorted(sCommands), "Command Table is not sorted");
|
static_assert(Utils::LookupTable::IsSorted(sCommands), "Command Table is not sorted");
|
||||||
|
|
||||||
Instance * mInstance;
|
Instance * mInstance;
|
||||||
|
otCliOutputCallback mOutputCallback;
|
||||||
|
void * mOutputContext;
|
||||||
|
|
||||||
const otCliCommand *mUserCommands;
|
const otCliCommand *mUserCommands;
|
||||||
uint8_t mUserCommandsLength;
|
uint8_t mUserCommandsLength;
|
||||||
void * mUserCommandsContext;
|
void * mUserCommandsContext;
|
||||||
|
|||||||
@@ -56,58 +56,6 @@
|
|||||||
#define OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH 384
|
#define OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH 384
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* @def OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
|
||||||
*
|
|
||||||
* The size of CLI UART RX buffer in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE
|
|
||||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
|
||||||
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 640
|
|
||||||
#else
|
|
||||||
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 512
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def OPENTHREAD_CONFIG_CLI_TX_BUFFER_SIZE
|
|
||||||
*
|
|
||||||
* The size of CLI message buffer in bytes.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE
|
|
||||||
#define OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE 1024
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
*
|
|
||||||
* TODO: complete.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef OPENTHREAD_CONFIG_UART_CLI_RAW
|
|
||||||
#define OPENTHREAD_CONFIG_UART_CLI_RAW 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OT_CLI_TRANSPORT_UART (1)
|
|
||||||
#define OT_CLI_TRANSPORT_CONSOLE (2)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def OPENTHREAD_CONFIG_CLI_TRANSPORT
|
|
||||||
*
|
|
||||||
* The transport of the CLI.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef OPENTHREAD_CONFIG_CLI_TRANSPORT
|
|
||||||
#define OPENTHREAD_CONFIG_CLI_TRANSPORT OT_CLI_TRANSPORT_UART
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT != OT_CLI_TRANSPORT_UART && \
|
|
||||||
OPENTHREAD_CONFIG_CLI_TRANSPORT != OT_CLI_TRANSPORT_CONSOLE
|
|
||||||
#error "Unsupported CLI transport!"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_CLI_SRP_CLIENT_MAX_SERVICES
|
* @def OPENTHREAD_CONFIG_CLI_SRP_CLIENT_MAX_SERVICES
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, The OpenThread Authors.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the copyright holder nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This file implements the CLI interpreter on the CONSOLE service.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "cli_console.hpp"
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "cli/cli.hpp"
|
|
||||||
#include "common/instance.hpp"
|
|
||||||
#include "common/new.hpp"
|
|
||||||
|
|
||||||
namespace ot {
|
|
||||||
namespace Cli {
|
|
||||||
|
|
||||||
static OT_DEFINE_ALIGNED_VAR(sCliConsoleRaw, sizeof(Console), uint64_t);
|
|
||||||
|
|
||||||
extern "C" void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)
|
|
||||||
{
|
|
||||||
Console::Initialize(aInstance, aCallback, aContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void otCliConsoleInputLine(char *aBuf)
|
|
||||||
{
|
|
||||||
Interpreter::GetInterpreter().ProcessLine(aBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add stubs for simulation
|
|
||||||
extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
|
||||||
{
|
|
||||||
OT_UNUSED_VARIABLE(aBuf);
|
|
||||||
OT_UNUSED_VARIABLE(aBufLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void otPlatUartSendDone(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Console::Initialize(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)
|
|
||||||
{
|
|
||||||
Instance *instance = static_cast<Instance *>(aInstance);
|
|
||||||
|
|
||||||
Interpreter::sInterpreter = new (&sCliConsoleRaw) Console(instance, aCallback, aContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console::Console(Instance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)
|
|
||||||
: Interpreter(aInstance)
|
|
||||||
, mCallback(aCallback)
|
|
||||||
, mContext(aContext)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int Interpreter::Output(const char *aBuf, uint16_t aBufLength)
|
|
||||||
{
|
|
||||||
return static_cast<Console *>(this)->Output(aBuf, aBufLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Console::Output(const char *aBuf, uint16_t aBufLength)
|
|
||||||
{
|
|
||||||
return mCallback(aBuf, aBufLength, mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Cli
|
|
||||||
} // namespace ot
|
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, The OpenThread Authors.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the copyright holder nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This file contains definitions for a CLI interpreter on the CONSOLE service.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLI_CONSOLE_HPP_
|
|
||||||
#define CLI_CONSOLE_HPP_
|
|
||||||
|
|
||||||
#include "cli_config.h"
|
|
||||||
|
|
||||||
#include <openthread/cli.h>
|
|
||||||
|
|
||||||
#include "cli/cli.hpp"
|
|
||||||
|
|
||||||
namespace ot {
|
|
||||||
namespace Cli {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class implements the CLI interpreter on top of the CONSOLE platform abstraction.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Console : public Interpreter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* This method initializes the Console interpreter.
|
|
||||||
*
|
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
|
||||||
* @param[in] aCallback A pointer to a callback method.
|
|
||||||
* @param[in] aContext A pointer to a user context.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static void Initialize(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method delivers raw characters to the client.
|
|
||||||
*
|
|
||||||
* @param[in] aBuf A pointer to a buffer.
|
|
||||||
* @param[in] aBufLength Number of bytes in the buffer.
|
|
||||||
*
|
|
||||||
* @returns The number of bytes placed in the output queue.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int Output(const char *aBuf, uint16_t aBufLength);
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit Console(Instance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext);
|
|
||||||
|
|
||||||
otCliConsoleOutputCallback mCallback;
|
|
||||||
void * mContext;
|
|
||||||
|
|
||||||
static Console *sConsole;
|
|
||||||
|
|
||||||
friend class Interpreter;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Cli
|
|
||||||
} // namespace ot
|
|
||||||
|
|
||||||
#endif // CLI_CONSOLE_HPP_
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, The OpenThread Authors.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the copyright holder nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This file contains definitions for a CLI interpreter on the UART service.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLI_UART_HPP_
|
|
||||||
#define CLI_UART_HPP_
|
|
||||||
|
|
||||||
#include "openthread-core-config.h"
|
|
||||||
|
|
||||||
#include "cli/cli.hpp"
|
|
||||||
#include "common/instance.hpp"
|
|
||||||
#include "common/tasklet.hpp"
|
|
||||||
|
|
||||||
namespace ot {
|
|
||||||
namespace Cli {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class implements the CLI interpreter on top of the UART platform abstraction.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Uart : public Interpreter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void Initialize(otInstance *aInstance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method delivers raw characters to the client.
|
|
||||||
*
|
|
||||||
* @param[in] aBuf A pointer to a buffer.
|
|
||||||
* @param[in] aBufLength Number of bytes in the buffer.
|
|
||||||
*
|
|
||||||
* @returns The number of bytes placed in the output queue.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int Output(const char *aBuf, uint16_t aBufLength);
|
|
||||||
|
|
||||||
void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength);
|
|
||||||
void SendDoneTask(void);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param[in] aInstance The OpenThread instance structure.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
explicit Uart(Instance *aInstance);
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
kRxBufferSize = OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE,
|
|
||||||
kTxBufferSize = OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE,
|
|
||||||
};
|
|
||||||
|
|
||||||
otError ProcessCommand(void);
|
|
||||||
void Send(void);
|
|
||||||
|
|
||||||
char mRxBuffer[kRxBufferSize];
|
|
||||||
uint16_t mRxLength;
|
|
||||||
|
|
||||||
char mTxBuffer[kTxBufferSize];
|
|
||||||
uint16_t mTxHead;
|
|
||||||
uint16_t mTxLength;
|
|
||||||
|
|
||||||
uint16_t mSendLength;
|
|
||||||
static Uart *sUart;
|
|
||||||
|
|
||||||
friend class Interpreter;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Cli
|
|
||||||
} // namespace ot
|
|
||||||
|
|
||||||
#endif // CLI_UART_HPP_
|
|
||||||
@@ -38,8 +38,6 @@ set_target_properties(
|
|||||||
target_compile_definitions(openthread-cli-ftd
|
target_compile_definitions(openthread-cli-ftd
|
||||||
PRIVATE
|
PRIVATE
|
||||||
OPENTHREAD_FTD=1
|
OPENTHREAD_FTD=1
|
||||||
PUBLIC
|
|
||||||
"OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_${OT_CLI_TRANSPORT}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-cli-ftd PRIVATE
|
target_compile_options(openthread-cli-ftd PRIVATE
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ set_target_properties(
|
|||||||
target_compile_definitions(openthread-cli-mtd
|
target_compile_definitions(openthread-cli-mtd
|
||||||
PRIVATE
|
PRIVATE
|
||||||
OPENTHREAD_MTD=1
|
OPENTHREAD_MTD=1
|
||||||
PUBLIC
|
|
||||||
"OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_${OT_CLI_TRANSPORT}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-cli-mtd PRIVATE
|
target_compile_options(openthread-cli-mtd PRIVATE
|
||||||
|
|||||||
@@ -73,8 +73,12 @@
|
|||||||
#error "OPENTHREAD_ENABLE_MULTIPLE_INSTANCES was replaced by OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE."
|
#error "OPENTHREAD_ENABLE_MULTIPLE_INSTANCES was replaced by OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
||||||
|
#error "OPENTHREAD_ENABLE_NCP_UART_ENABLE was replaced by OPENTHREAD_CONFIG_NCP_HDLC_ENABLE."
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef OPENTHREAD_ENABLE_NCP_UART
|
#ifdef OPENTHREAD_ENABLE_NCP_UART
|
||||||
#error "OPENTHREAD_ENABLE_NCP_UART was replaced by OPENTHREAD_CONFIG_NCP_UART_ENABLE."
|
#error "OPENTHREAD_ENABLE_NCP_UART was replaced by OPENTHREAD_CONFIG_NCP_HDLC_ENABLE."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OPENTHREAD_ENABLE_NCP_SPI
|
#ifdef OPENTHREAD_ENABLE_NCP_SPI
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ set_target_properties(
|
|||||||
|
|
||||||
target_compile_definitions(openthread-spinel-ncp PRIVATE
|
target_compile_definitions(openthread-spinel-ncp PRIVATE
|
||||||
OPENTHREAD_FTD=1
|
OPENTHREAD_FTD=1
|
||||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1
|
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(openthread-spinel-rcp PRIVATE
|
target_compile_definitions(openthread-spinel-rcp PRIVATE
|
||||||
OPENTHREAD_RADIO=1
|
OPENTHREAD_RADIO=1
|
||||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0
|
PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -38,10 +38,10 @@ openthread_ncp_sources = [
|
|||||||
"ncp_base_mtd.cpp",
|
"ncp_base_mtd.cpp",
|
||||||
"ncp_base_radio.cpp",
|
"ncp_base_radio.cpp",
|
||||||
"ncp_config.h",
|
"ncp_config.h",
|
||||||
|
"ncp_hdlc.cpp",
|
||||||
|
"ncp_hdlc.hpp",
|
||||||
"ncp_spi.cpp",
|
"ncp_spi.cpp",
|
||||||
"ncp_spi.hpp",
|
"ncp_spi.hpp",
|
||||||
"ncp_uart.cpp",
|
|
||||||
"ncp_uart.hpp",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
config("ncp_config") {
|
config("ncp_config") {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ set(COMMON_SOURCES
|
|||||||
ncp_base_dispatcher.cpp
|
ncp_base_dispatcher.cpp
|
||||||
ncp_base_radio.cpp
|
ncp_base_radio.cpp
|
||||||
ncp_spi.cpp
|
ncp_spi.cpp
|
||||||
ncp_uart.cpp
|
ncp_hdlc.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(OT_NCP_VENDOR_HOOK_SOURCE "" CACHE STRING "set vendor hook source file for NCP")
|
set(OT_NCP_VENDOR_HOOK_SOURCE "" CACHE STRING "set vendor hook source file for NCP")
|
||||||
@@ -55,7 +55,7 @@ option(OT_NCP_SPI "enable NCP SPI support")
|
|||||||
if(OT_NCP_SPI)
|
if(OT_NCP_SPI)
|
||||||
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_SPI_ENABLE=1")
|
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_SPI_ENABLE=1")
|
||||||
else()
|
else()
|
||||||
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_UART_ENABLE=1")
|
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OT_FTD)
|
if(OT_FTD)
|
||||||
|
|||||||
+2
-2
@@ -112,8 +112,8 @@ COMMON_SOURCES = \
|
|||||||
ncp_config.h \
|
ncp_config.h \
|
||||||
ncp_spi.cpp \
|
ncp_spi.cpp \
|
||||||
ncp_spi.hpp \
|
ncp_spi.hpp \
|
||||||
ncp_uart.cpp \
|
ncp_hdlc.cpp \
|
||||||
ncp_uart.hpp \
|
ncp_hdlc.hpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
|
if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
|
||||||
|
|||||||
@@ -118,20 +118,27 @@ otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey)
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
// When OPENTHREAD_ENABLE_NCP_VENDOR_HOOK is enabled, vendor code is
|
// When OPENTHREAD_ENABLE_NCP_VENDOR_HOOK is enabled, vendor code is
|
||||||
// expected to provide the `otNcpInit()` function. The reason behind
|
// expected to provide the `otAppNcpInit()` function. The reason behind
|
||||||
// this is to enable vendor code to define its own sub-class of
|
// this is to enable vendor code to define its own sub-class of
|
||||||
// `NcpBase` or `NcpUart`/`NcpSpi`.
|
// `NcpBase` or `NcpHdlc`/`NcpSpi`.
|
||||||
//
|
//
|
||||||
// Example below show how to add a vendor sub-class over `NcpUart`.
|
// Example below show how to add a vendor sub-class over `NcpHdlc`.
|
||||||
|
|
||||||
#include "ncp_uart.hpp"
|
#include "ncp_hdlc.hpp"
|
||||||
#include "common/new.hpp"
|
#include "common/new.hpp"
|
||||||
|
|
||||||
class NcpVendorUart : public ot::Ncp::NcpUart
|
class NcpVendorUart : public ot::Ncp::NcpHdlc
|
||||||
{
|
{
|
||||||
|
static int SendHdlc(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(aBuf);
|
||||||
|
OT_UNUSED_VARIABLE(aBufLength);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NcpVendorUart(ot::Instance *aInstance)
|
NcpVendorUart(ot::Instance *aInstance)
|
||||||
: ot::Ncp::NcpUart(aInstance)
|
: ot::Ncp::NcpHdlc(aInstance, &NcpVendorUart::SendHdlc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +147,7 @@ public:
|
|||||||
|
|
||||||
static OT_DEFINE_ALIGNED_VAR(sNcpVendorRaw, sizeof(NcpVendorUart), uint64_t);
|
static OT_DEFINE_ALIGNED_VAR(sNcpVendorRaw, sizeof(NcpVendorUart), uint64_t);
|
||||||
|
|
||||||
extern "C" void otNcpInit(otInstance *aInstance)
|
extern "C" void otAppNcpInit(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
NcpVendorUart *ncpVendor = nullptr;
|
NcpVendorUart *ncpVendor = nullptr;
|
||||||
ot::Instance * instance = static_cast<ot::Instance *>(aInstance);
|
ot::Instance * instance = static_cast<ot::Instance *>(aInstance);
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ set_target_properties(
|
|||||||
|
|
||||||
target_compile_definitions(openthread-ncp-ftd PRIVATE
|
target_compile_definitions(openthread-ncp-ftd PRIVATE
|
||||||
OPENTHREAD_FTD=1
|
OPENTHREAD_FTD=1
|
||||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-ncp-ftd PRIVATE
|
target_compile_options(openthread-ncp-ftd PRIVATE
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ set_target_properties(
|
|||||||
|
|
||||||
target_compile_definitions(openthread-ncp-mtd PRIVATE
|
target_compile_definitions(openthread-ncp-mtd PRIVATE
|
||||||
OPENTHREAD_MTD=1
|
OPENTHREAD_MTD=1
|
||||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-ncp-mtd PRIVATE
|
target_compile_options(openthread-ncp-mtd PRIVATE
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ protected:
|
|||||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||||
static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <=
|
static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <=
|
||||||
OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE - kSpinelCmdHeaderSize - kSpinelPropIdSize,
|
OPENTHREAD_CONFIG_NCP_TX_BUFFER_SIZE - kSpinelCmdHeaderSize - kSpinelPropIdSize,
|
||||||
"diag output buffer should be smaller than NCP UART tx buffer");
|
"diag output buffer should be smaller than NCP HDLC tx buffer");
|
||||||
|
|
||||||
otError HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader);
|
otError HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-14
@@ -50,13 +50,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
*
|
*
|
||||||
* Define to 1 to enable NCP UART support.
|
* Define to 1 to enable NCP HDLC support.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 0
|
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,28 +70,28 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_TX_CHUNK_SIZE
|
||||||
*
|
*
|
||||||
* The size of NCP UART TX chunk in bytes.
|
* The size of NCP HDLC TX chunk in bytes.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE
|
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_TX_CHUNK_SIZE
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE 2048
|
#define OPENTHREAD_CONFIG_NCP_HDLC_TX_CHUNK_SIZE 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE
|
* @def OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE
|
||||||
*
|
*
|
||||||
* The size of NCP UART RX buffer in bytes.
|
* The size of NCP HDLC RX buffer in bytes.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE
|
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE
|
||||||
#if OPENTHREAD_RADIO
|
#if OPENTHREAD_RADIO
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE 512
|
#define OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE 512
|
||||||
#else
|
#else
|
||||||
#define OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE 1300
|
#define OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE 1300
|
||||||
#endif
|
#endif
|
||||||
#endif // OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE
|
#endif // OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NCP_SPI_BUFFER_SIZE
|
* @def OPENTHREAD_CONFIG_NCP_SPI_BUFFER_SIZE
|
||||||
|
|||||||
@@ -27,17 +27,16 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* This file contains definitions for a UART based NCP interface to the OpenThread stack.
|
* This file contains definitions for a HDLC based NCP interface to the OpenThread stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ncp_uart.hpp"
|
#include "ncp_hdlc.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <openthread/ncp.h>
|
#include <openthread/ncp.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#include <openthread/platform/misc.h>
|
#include <openthread/platform/misc.h>
|
||||||
#include <openthread/platform/uart.h>
|
|
||||||
|
|
||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
#include "common/code_utils.hpp"
|
#include "common/code_utils.hpp"
|
||||||
@@ -46,16 +45,16 @@
|
|||||||
#include "common/new.hpp"
|
#include "common/new.hpp"
|
||||||
#include "net/ip6.hpp"
|
#include "net/ip6.hpp"
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
#if OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||||
static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE -
|
static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE -
|
||||||
ot::Ncp::NcpBase::kSpinelCmdHeaderSize -
|
ot::Ncp::NcpBase::kSpinelCmdHeaderSize -
|
||||||
ot::Ncp::NcpBase::kSpinelPropIdSize,
|
ot::Ncp::NcpBase::kSpinelPropIdSize,
|
||||||
"diag output should be smaller than NCP UART rx buffer");
|
"diag output should be smaller than NCP HDLC rx buffer");
|
||||||
|
|
||||||
static_assert(OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE,
|
static_assert(OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE <= OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE,
|
||||||
"diag command line should be smaller than NCP UART rx buffer");
|
"diag command line should be smaller than NCP HDLC rx buffer");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -63,16 +62,16 @@ namespace Ncp {
|
|||||||
|
|
||||||
#if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK == 0
|
#if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK == 0
|
||||||
|
|
||||||
static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpUart), uint64_t);
|
static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpHdlc), uint64_t);
|
||||||
|
|
||||||
extern "C" void otNcpInit(otInstance *aInstance)
|
extern "C" void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSendCallback)
|
||||||
{
|
{
|
||||||
NcpUart * ncpUart = nullptr;
|
NcpHdlc * ncpHdlc = nullptr;
|
||||||
Instance *instance = static_cast<Instance *>(aInstance);
|
Instance *instance = static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
ncpUart = new (&sNcpRaw) NcpUart(instance);
|
ncpHdlc = new (&sNcpRaw) NcpHdlc(instance, aSendCallback);
|
||||||
|
|
||||||
if (ncpUart == nullptr || ncpUart != NcpBase::GetNcpInstance())
|
if (ncpHdlc == nullptr || ncpHdlc != NcpBase::GetNcpInstance())
|
||||||
{
|
{
|
||||||
OT_ASSERT(false);
|
OT_ASSERT(false);
|
||||||
}
|
}
|
||||||
@@ -80,24 +79,23 @@ extern "C" void otNcpInit(otInstance *aInstance)
|
|||||||
|
|
||||||
#endif // OPENTHREAD_ENABLE_NCP_VENDOR_HOOK == 0
|
#endif // OPENTHREAD_ENABLE_NCP_VENDOR_HOOK == 0
|
||||||
|
|
||||||
NcpUart::NcpUart(Instance *aInstance)
|
NcpHdlc::NcpHdlc(Instance *aInstance, otNcpHdlcSendCallback aSendCallback)
|
||||||
: NcpBase(aInstance)
|
: NcpBase(aInstance)
|
||||||
, mFrameEncoder(mUartBuffer)
|
, mSendCallback(aSendCallback)
|
||||||
, mFrameDecoder(mRxBuffer, &NcpUart::HandleFrame, this)
|
, mFrameEncoder(mHdlcBuffer)
|
||||||
|
, mFrameDecoder(mRxBuffer, &NcpHdlc::HandleFrame, this)
|
||||||
, mState(kStartingFrame)
|
, mState(kStartingFrame)
|
||||||
, mByte(0)
|
, mByte(0)
|
||||||
, mUartSendImmediate(false)
|
, mHdlcSendImmediate(false)
|
||||||
, mUartSendTask(*aInstance, EncodeAndSendToUart)
|
, mHdlcSendTask(*aInstance, EncodeAndSend)
|
||||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||||
, mTxFrameBufferEncrypterReader(mTxFrameBuffer)
|
, mTxFrameBufferEncrypterReader(mTxFrameBuffer)
|
||||||
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||||
{
|
{
|
||||||
mTxFrameBuffer.SetFrameAddedCallback(HandleFrameAddedToNcpBuffer, this);
|
mTxFrameBuffer.SetFrameAddedCallback(HandleFrameAddedToNcpBuffer, this);
|
||||||
|
|
||||||
IgnoreError(otPlatUartEnable());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleFrameAddedToNcpBuffer(void * aContext,
|
void NcpHdlc::HandleFrameAddedToNcpBuffer(void * aContext,
|
||||||
Spinel::Buffer::FrameTag aTag,
|
Spinel::Buffer::FrameTag aTag,
|
||||||
Spinel::Buffer::Priority aPriority,
|
Spinel::Buffer::Priority aPriority,
|
||||||
Spinel::Buffer * aBuffer)
|
Spinel::Buffer * aBuffer)
|
||||||
@@ -106,27 +104,27 @@ void NcpUart::HandleFrameAddedToNcpBuffer(void * aContext,
|
|||||||
OT_UNUSED_VARIABLE(aTag);
|
OT_UNUSED_VARIABLE(aTag);
|
||||||
OT_UNUSED_VARIABLE(aPriority);
|
OT_UNUSED_VARIABLE(aPriority);
|
||||||
|
|
||||||
static_cast<NcpUart *>(aContext)->HandleFrameAddedToNcpBuffer();
|
static_cast<NcpHdlc *>(aContext)->HandleFrameAddedToNcpBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleFrameAddedToNcpBuffer(void)
|
void NcpHdlc::HandleFrameAddedToNcpBuffer(void)
|
||||||
{
|
{
|
||||||
if (mUartBuffer.IsEmpty())
|
if (mHdlcBuffer.IsEmpty())
|
||||||
{
|
{
|
||||||
mUartSendTask.Post();
|
mHdlcSendTask.Post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::EncodeAndSendToUart(Tasklet &aTasklet)
|
void NcpHdlc::EncodeAndSend(Tasklet &aTasklet)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aTasklet);
|
OT_UNUSED_VARIABLE(aTasklet);
|
||||||
static_cast<NcpUart *>(GetNcpInstance())->EncodeAndSendToUart();
|
static_cast<NcpHdlc *>(GetNcpInstance())->EncodeAndSend();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method encodes a frame from the tx frame buffer (mTxFrameBuffer) into the uart buffer and sends it over uart.
|
// This method encodes a frame from the tx frame buffer (mTxFrameBuffer) into the uart buffer and sends it over uart.
|
||||||
// If the uart buffer gets full, it sends the current encoded portion. This method remembers current state, so on
|
// If the uart buffer gets full, it sends the current encoded portion. This method remembers current state, so on
|
||||||
// sub-sequent calls, it restarts encoding the bytes from where it left of in the frame .
|
// sub-sequent calls, it restarts encoding the bytes from where it left of in the frame .
|
||||||
void NcpUart::EncodeAndSendToUart(void)
|
void NcpHdlc::EncodeAndSend(void)
|
||||||
{
|
{
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
bool prevHostPowerState;
|
bool prevHostPowerState;
|
||||||
@@ -175,10 +173,10 @@ void NcpUart::EncodeAndSendToUart(void)
|
|||||||
{
|
{
|
||||||
// If mHostPowerStateInProgress transitioned from true -> false
|
// If mHostPowerStateInProgress transitioned from true -> false
|
||||||
// in the call to OutFrameRemove, then the frame should be sent
|
// in the call to OutFrameRemove, then the frame should be sent
|
||||||
// out the UART without attempting to push any new frames into
|
// out without attempting to push any new frames into the
|
||||||
// the mUartBuffer. This is necessary to avoid prematurely calling
|
// mHdlcBuffer. This is necessary to avoid prematurely calling
|
||||||
// otPlatWakeHost.
|
// otPlatWakeHost.
|
||||||
mUartSendImmediate = true;
|
mHdlcSendImmediate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mState = kFinalizingFrame;
|
mState = kFinalizingFrame;
|
||||||
@@ -191,64 +189,63 @@ void NcpUart::EncodeAndSendToUart(void)
|
|||||||
|
|
||||||
mState = kStartingFrame;
|
mState = kStartingFrame;
|
||||||
|
|
||||||
if (mUartSendImmediate)
|
if (mHdlcSendImmediate)
|
||||||
{
|
{
|
||||||
// clear state and break;
|
// clear state and break;
|
||||||
mUartSendImmediate = false;
|
mHdlcSendImmediate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
len = mUartBuffer.GetLength();
|
len = mHdlcBuffer.GetLength();
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
if (otPlatUartSend(mUartBuffer.GetFrame(), len) != OT_ERROR_NONE)
|
int rval = mSendCallback(mHdlcBuffer.GetFrame(), len);
|
||||||
{
|
OT_UNUSED_VARIABLE(rval);
|
||||||
OT_ASSERT(false);
|
OT_ASSERT(rval == static_cast<int>(len));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otPlatUartSendDone(void)
|
extern "C" void otNcpHdlcSendDone(void)
|
||||||
{
|
{
|
||||||
NcpUart *ncpUart = static_cast<NcpUart *>(NcpBase::GetNcpInstance());
|
NcpHdlc *ncpHdlc = static_cast<NcpHdlc *>(NcpBase::GetNcpInstance());
|
||||||
|
|
||||||
if (ncpUart != nullptr)
|
if (ncpHdlc != nullptr)
|
||||||
{
|
{
|
||||||
ncpUart->HandleUartSendDone();
|
ncpHdlc->HandleHdlcSendDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleUartSendDone(void)
|
void NcpHdlc::HandleHdlcSendDone(void)
|
||||||
{
|
{
|
||||||
mUartBuffer.Clear();
|
mHdlcBuffer.Clear();
|
||||||
mUartSendTask.Post();
|
mHdlcSendTask.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
extern "C" void otNcpHdlcReceive(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
NcpUart *ncpUart = static_cast<NcpUart *>(NcpBase::GetNcpInstance());
|
NcpHdlc *ncpHdlc = static_cast<NcpHdlc *>(NcpBase::GetNcpInstance());
|
||||||
|
|
||||||
if (ncpUart != nullptr)
|
if (ncpHdlc != nullptr)
|
||||||
{
|
{
|
||||||
ncpUart->HandleUartReceiveDone(aBuf, aBufLength);
|
ncpHdlc->HandleHdlcReceiveDone(aBuf, aBufLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleUartReceiveDone(const uint8_t *aBuf, uint16_t aBufLength)
|
void NcpHdlc::HandleHdlcReceiveDone(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
mFrameDecoder.Decode(aBuf, aBufLength);
|
mFrameDecoder.Decode(aBuf, aBufLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleFrame(void *aContext, otError aError)
|
void NcpHdlc::HandleFrame(void *aContext, otError aError)
|
||||||
{
|
{
|
||||||
static_cast<NcpUart *>(aContext)->HandleFrame(aError);
|
static_cast<NcpHdlc *>(aContext)->HandleFrame(aError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleFrame(otError aError)
|
void NcpHdlc::HandleFrame(otError aError)
|
||||||
{
|
{
|
||||||
uint8_t *buf = mRxBuffer.GetFrame();
|
uint8_t *buf = mRxBuffer.GetFrame();
|
||||||
uint16_t bufLength = mRxBuffer.GetLength();
|
uint16_t bufLength = mRxBuffer.GetLength();
|
||||||
@@ -273,7 +270,7 @@ void NcpUart::HandleFrame(otError aError)
|
|||||||
mRxBuffer.Clear();
|
mRxBuffer.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength)
|
void NcpHdlc::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
char hexbuf[128];
|
char hexbuf[128];
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
@@ -308,19 +305,19 @@ void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength)
|
|||||||
|
|
||||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||||
|
|
||||||
NcpUart::BufferEncrypterReader::BufferEncrypterReader(Spinel::Buffer &aTxFrameBuffer)
|
NcpHdlc::BufferEncrypterReader::BufferEncrypterReader(Spinel::Buffer &aTxFrameBuffer)
|
||||||
: mTxFrameBuffer(aTxFrameBuffer)
|
: mTxFrameBuffer(aTxFrameBuffer)
|
||||||
, mDataBufferReadIndex(0)
|
, mDataBufferReadIndex(0)
|
||||||
, mOutputDataLength(0)
|
, mOutputDataLength(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NcpUart::BufferEncrypterReader::IsEmpty(void) const
|
bool NcpHdlc::BufferEncrypterReader::IsEmpty(void) const
|
||||||
{
|
{
|
||||||
return mTxFrameBuffer.IsEmpty() && !mOutputDataLength;
|
return mTxFrameBuffer.IsEmpty() && !mOutputDataLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError NcpUart::BufferEncrypterReader::OutFrameBegin(void)
|
otError NcpHdlc::BufferEncrypterReader::OutFrameBegin(void)
|
||||||
{
|
{
|
||||||
otError status = OT_ERROR_FAILED;
|
otError status = OT_ERROR_FAILED;
|
||||||
|
|
||||||
@@ -350,22 +347,22 @@ otError NcpUart::BufferEncrypterReader::OutFrameBegin(void)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NcpUart::BufferEncrypterReader::OutFrameHasEnded(void)
|
bool NcpHdlc::BufferEncrypterReader::OutFrameHasEnded(void)
|
||||||
{
|
{
|
||||||
return (mDataBufferReadIndex >= mOutputDataLength);
|
return (mDataBufferReadIndex >= mOutputDataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t NcpUart::BufferEncrypterReader::OutFrameReadByte(void)
|
uint8_t NcpHdlc::BufferEncrypterReader::OutFrameReadByte(void)
|
||||||
{
|
{
|
||||||
return mDataBuffer[mDataBufferReadIndex++];
|
return mDataBuffer[mDataBufferReadIndex++];
|
||||||
}
|
}
|
||||||
|
|
||||||
otError NcpUart::BufferEncrypterReader::OutFrameRemove(void)
|
otError NcpHdlc::BufferEncrypterReader::OutFrameRemove(void)
|
||||||
{
|
{
|
||||||
return mTxFrameBuffer.OutFrameRemove();
|
return mTxFrameBuffer.OutFrameRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcpUart::BufferEncrypterReader::Reset(void)
|
void NcpHdlc::BufferEncrypterReader::Reset(void)
|
||||||
{
|
{
|
||||||
mOutputDataLength = 0;
|
mOutputDataLength = 0;
|
||||||
mDataBufferReadIndex = 0;
|
mDataBufferReadIndex = 0;
|
||||||
@@ -376,4 +373,4 @@ void NcpUart::BufferEncrypterReader::Reset(void)
|
|||||||
} // namespace Ncp
|
} // namespace Ncp
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_NCP_UART_ENABLE
|
#endif // OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||||
@@ -27,11 +27,11 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* This file contains definitions for a UART based NCP interface to the OpenThread stack.
|
* This file contains definitions for a HDLC based NCP interface to the OpenThread stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NCP_UART_HPP_
|
#ifndef NCP_HDLC_HPP_
|
||||||
#define NCP_UART_HPP_
|
#define NCP_HDLC_HPP_
|
||||||
|
|
||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
namespace ot {
|
namespace ot {
|
||||||
namespace Ncp {
|
namespace Ncp {
|
||||||
|
|
||||||
class NcpUart : public NcpBase
|
class NcpHdlc : public NcpBase
|
||||||
{
|
{
|
||||||
typedef NcpBase super_t;
|
typedef NcpBase super_t;
|
||||||
|
|
||||||
@@ -56,29 +56,29 @@ public:
|
|||||||
* @param[in] aInstance The OpenThread instance structure.
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
explicit NcpUart(Instance *aInstance);
|
explicit NcpHdlc(Instance *aInstance, otNcpHdlcSendCallback aSendCallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called when uart tx is finished. It prepares and sends the next data chunk (if any) to uart.
|
* This method is called when uart tx is finished. It prepares and sends the next data chunk (if any) to uart.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void HandleUartSendDone(void);
|
void HandleHdlcSendDone(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called when uart received a data buffer.
|
* This method is called when uart received a data buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void HandleUartReceiveDone(const uint8_t *aBuf, uint16_t aBufLength);
|
void HandleHdlcReceiveDone(const uint8_t *aBuf, uint16_t aBufLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kUartTxBufferSize = OPENTHREAD_CONFIG_NCP_UART_TX_CHUNK_SIZE, // Uart tx buffer size.
|
kHdlcTxBufferSize = OPENTHREAD_CONFIG_NCP_HDLC_TX_CHUNK_SIZE, // HDLC tx buffer size.
|
||||||
kRxBufferSize = OPENTHREAD_CONFIG_NCP_UART_RX_BUFFER_SIZE + // Rx buffer size (should be large enough to fit
|
kRxBufferSize = OPENTHREAD_CONFIG_NCP_HDLC_RX_BUFFER_SIZE + // Rx buffer size (should be large enough to fit
|
||||||
OPENTHREAD_CONFIG_NCP_SPINEL_ENCRYPTER_EXTRA_DATA_SIZE, // one whole (decoded) received frame).
|
OPENTHREAD_CONFIG_NCP_SPINEL_ENCRYPTER_EXTRA_DATA_SIZE, // one whole (decoded) received frame).
|
||||||
};
|
};
|
||||||
|
|
||||||
enum UartTxState
|
enum HdlcTxState
|
||||||
{
|
{
|
||||||
kStartingFrame, // Starting a new frame.
|
kStartingFrame, // Starting a new frame.
|
||||||
kEncodingFrame, // In middle of encoding a frame.
|
kEncodingFrame, // In middle of encoding a frame.
|
||||||
@@ -114,27 +114,28 @@ private:
|
|||||||
};
|
};
|
||||||
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
#endif // OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||||
|
|
||||||
void EncodeAndSendToUart(void);
|
void EncodeAndSend(void);
|
||||||
void HandleFrame(otError aError);
|
void HandleFrame(otError aError);
|
||||||
void HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength);
|
void HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength);
|
||||||
void TxFrameBufferHasData(void);
|
void TxFrameBufferHasData(void);
|
||||||
void HandleFrameAddedToNcpBuffer(void);
|
void HandleFrameAddedToNcpBuffer(void);
|
||||||
|
|
||||||
static void EncodeAndSendToUart(Tasklet &aTasklet);
|
static void EncodeAndSend(Tasklet &aTasklet);
|
||||||
static void HandleFrame(void *aContext, otError aError);
|
static void HandleFrame(void *aContext, otError aError);
|
||||||
static void HandleFrameAddedToNcpBuffer(void * aContext,
|
static void HandleFrameAddedToNcpBuffer(void * aContext,
|
||||||
Spinel::Buffer::FrameTag aTag,
|
Spinel::Buffer::FrameTag aTag,
|
||||||
Spinel::Buffer::Priority aPriority,
|
Spinel::Buffer::Priority aPriority,
|
||||||
Spinel::Buffer * aBuffer);
|
Spinel::Buffer * aBuffer);
|
||||||
|
otNcpHdlcSendCallback mSendCallback;
|
||||||
|
|
||||||
Hdlc::Encoder mFrameEncoder;
|
Hdlc::Encoder mFrameEncoder;
|
||||||
Hdlc::Decoder mFrameDecoder;
|
Hdlc::Decoder mFrameDecoder;
|
||||||
Hdlc::FrameBuffer<kUartTxBufferSize> mUartBuffer;
|
Hdlc::FrameBuffer<kHdlcTxBufferSize> mHdlcBuffer;
|
||||||
UartTxState mState;
|
HdlcTxState mState;
|
||||||
uint8_t mByte;
|
uint8_t mByte;
|
||||||
Hdlc::FrameBuffer<kRxBufferSize> mRxBuffer;
|
Hdlc::FrameBuffer<kRxBufferSize> mRxBuffer;
|
||||||
bool mUartSendImmediate;
|
bool mHdlcSendImmediate;
|
||||||
Tasklet mUartSendTask;
|
Tasklet mHdlcSendTask;
|
||||||
|
|
||||||
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
#if OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER
|
||||||
BufferEncrypterReader mTxFrameBufferEncrypterReader;
|
BufferEncrypterReader mTxFrameBufferEncrypterReader;
|
||||||
@@ -144,4 +145,4 @@ private:
|
|||||||
} // namespace Ncp
|
} // namespace Ncp
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|
||||||
#endif // NCP_UART_HPP_
|
#endif // NCP_HDLC_HPP_
|
||||||
+1
-1
@@ -62,7 +62,7 @@ namespace Ncp {
|
|||||||
|
|
||||||
static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpSpi), uint64_t);
|
static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpSpi), uint64_t);
|
||||||
|
|
||||||
extern "C" void otNcpInit(otInstance *aInstance)
|
extern "C" void otNcpSpiInit(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
NcpSpi * ncpSpi = nullptr;
|
NcpSpi * ncpSpi = nullptr;
|
||||||
Instance *instance = static_cast<Instance *>(aInstance);
|
Instance *instance = static_cast<Instance *>(aInstance);
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ set_target_properties(
|
|||||||
|
|
||||||
target_compile_definitions(openthread-rcp PRIVATE
|
target_compile_definitions(openthread-rcp PRIVATE
|
||||||
OPENTHREAD_RADIO=1
|
OPENTHREAD_RADIO=1
|
||||||
OPENTHREAD_CONFIG_NCP_UART_ENABLE=1
|
OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(openthread-rcp PRIVATE
|
target_compile_options(openthread-rcp PRIVATE
|
||||||
|
|||||||
@@ -26,10 +26,6 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
|
||||||
target_compile_definitions(ot-config INTERFACE
|
|
||||||
OPENTHREAD_CONFIG_UART_CLI_RAW=1
|
|
||||||
)
|
|
||||||
|
|
||||||
set(COMMON_INCLUDES
|
set(COMMON_INCLUDES
|
||||||
${OT_PUBLIC_INCLUDES}
|
${OT_PUBLIC_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/src
|
${PROJECT_SOURCE_DIR}/src
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ endif
|
|||||||
|
|
||||||
COMMONCFLAGS := \
|
COMMONCFLAGS := \
|
||||||
-g \
|
-g \
|
||||||
-DOPENTHREAD_CONFIG_UART_CLI_RAW=1 \
|
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
# If the user has asserted COVERAGE, alter the configuration options
|
# If the user has asserted COVERAGE, alter the configuration options
|
||||||
@@ -113,7 +112,6 @@ endif
|
|||||||
|
|
||||||
ifneq ($(READLINE),)
|
ifneq ($(READLINE),)
|
||||||
configure_OPTIONS += --with-readline=$(READLINE)
|
configure_OPTIONS += --with-readline=$(READLINE)
|
||||||
CLI_TRANSPORT = $(if $(and $(filter-out no,$(READLINE)),$(filter 0,$(DAEMON))),CONSOLE,UART)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(RCP_BUS),spi)
|
ifeq ($(RCP_BUS),spi)
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ ot_ncp_CPPFLAGS = \
|
|||||||
|
|
||||||
ot_ncp_SOURCES = \
|
ot_ncp_SOURCES = \
|
||||||
main.c \
|
main.c \
|
||||||
|
ncp.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ot_ncp_LDADD = \
|
ot_ncp_LDADD = \
|
||||||
@@ -162,7 +163,7 @@ ot_cli_CPPFLAGS = \
|
|||||||
|
|
||||||
ot_cli_SOURCES = \
|
ot_cli_SOURCES = \
|
||||||
main.c \
|
main.c \
|
||||||
console_cli.cpp \
|
cli.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ot_cli_LDADD = \
|
ot_cli_LDADD = \
|
||||||
@@ -198,8 +199,4 @@ CLEANFILES = $(wildc
|
|||||||
endif # OPENTHREAD_BUILD_COVERAGE
|
endif # OPENTHREAD_BUILD_COVERAGE
|
||||||
endif # OPENTHREAD_ENABLE_EXECUTABLE
|
endif # OPENTHREAD_ENABLE_EXECUTABLE
|
||||||
|
|
||||||
noinst_HEADERS = \
|
|
||||||
console_cli.h \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||||
|
|||||||
+1
-5
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
add_executable(ot-cli
|
add_executable(ot-cli
|
||||||
main.c
|
main.c
|
||||||
$<$<BOOL:${READLINE}>:console_cli.cpp>
|
cli.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
@@ -40,10 +40,6 @@ set_target_properties(
|
|||||||
|
|
||||||
target_include_directories(ot-cli PRIVATE ${COMMON_INCLUDES})
|
target_include_directories(ot-cli PRIVATE ${COMMON_INCLUDES})
|
||||||
|
|
||||||
if(OT_READLINE)
|
|
||||||
set(OT_CLI_TRANSPORT "CONSOLE" CACHE STRING "set CLI to use console interpreter" FORCE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_compile_definitions(ot-cli PRIVATE
|
target_compile_definitions(ot-cli PRIVATE
|
||||||
$<$<BOOL:${READLINE}>:HAVE_LIB$<UPPER_CASE:${OT_READLINE}>=1>
|
$<$<BOOL:${READLINE}>:HAVE_LIB$<UPPER_CASE:${OT_READLINE}>=1>
|
||||||
OPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_CLI
|
OPENTHREAD_POSIX_APP_TYPE=OT_POSIX_APP_TYPE_CLI
|
||||||
|
|||||||
@@ -26,13 +26,15 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "console_cli.h"
|
#include "platform/openthread-posix-config.h"
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
|
||||||
#include <openthread/config.h>
|
#include <openthread/config.h>
|
||||||
|
#include <openthread/openthread-system.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -46,17 +48,20 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_LIBEDIT || HAVE_LIBREADLINE
|
#if HAVE_LIBEDIT || HAVE_LIBREADLINE
|
||||||
|
#define OPENTHREAD_USE_READLINE 1
|
||||||
#if HAVE_LIBEDIT
|
#if HAVE_LIBEDIT
|
||||||
#include <editline/readline.h>
|
#include <editline/readline.h>
|
||||||
#elif HAVE_LIBREADLINE
|
#elif HAVE_LIBREADLINE
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#error "Missing readline library"
|
#define OPENTHREAD_USE_READLINE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openthread/cli.h>
|
#include <openthread/cli.h>
|
||||||
|
|
||||||
|
#include "cli/cli_config.h"
|
||||||
#include "common/code_utils.hpp"
|
#include "common/code_utils.hpp"
|
||||||
|
|
||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
@@ -64,8 +69,7 @@
|
|||||||
|
|
||||||
static const char sPrompt[] = "> ";
|
static const char sPrompt[] = "> ";
|
||||||
|
|
||||||
static int sReadFd;
|
#if OPENTHREAD_USE_READLINE
|
||||||
|
|
||||||
static void InputCallback(char *aLine)
|
static void InputCallback(char *aLine)
|
||||||
{
|
{
|
||||||
if (aLine != nullptr)
|
if (aLine != nullptr)
|
||||||
@@ -73,7 +77,7 @@ static void InputCallback(char *aLine)
|
|||||||
if (aLine[0] != '\0')
|
if (aLine[0] != '\0')
|
||||||
{
|
{
|
||||||
add_history(aLine);
|
add_history(aLine);
|
||||||
otCliConsoleInputLine(aLine);
|
otCliInputLine(aLine);
|
||||||
}
|
}
|
||||||
free(aLine);
|
free(aLine);
|
||||||
}
|
}
|
||||||
@@ -82,57 +86,72 @@ static void InputCallback(char *aLine)
|
|||||||
exit(OT_EXIT_SUCCESS);
|
exit(OT_EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int OutputCallback(const char *aBuffer, uint16_t aLength, void *aContext)
|
static int OutputCallback(void *aContext, const char *aFormat, va_list aArguments)
|
||||||
{
|
{
|
||||||
(void)aContext;
|
OT_UNUSED_VARIABLE(aContext);
|
||||||
|
|
||||||
return (int)write(STDOUT_FILENO, aBuffer, aLength);
|
return vdprintf(STDOUT_FILENO, aFormat, aArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
void otxConsoleInit(otInstance *aInstance)
|
extern "C" void otAppCliInit(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
|
#if OPENTHREAD_USE_READLINE
|
||||||
rl_instream = stdin;
|
rl_instream = stdin;
|
||||||
rl_outstream = stdout;
|
rl_outstream = stdout;
|
||||||
rl_inhibit_completion = true;
|
rl_inhibit_completion = true;
|
||||||
|
|
||||||
rl_set_screen_size(0, OT_MAX(OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH, OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE));
|
rl_set_screen_size(0, OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH);
|
||||||
|
|
||||||
sReadFd = fileno(rl_instream);
|
|
||||||
rl_callback_handler_install(sPrompt, InputCallback);
|
rl_callback_handler_install(sPrompt, InputCallback);
|
||||||
otCliConsoleInit(aInstance, OutputCallback, nullptr);
|
#endif
|
||||||
|
otCliInit(aInstance, OutputCallback, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void otxConsoleDeinit(void)
|
extern "C" void otAppCliDeinit(void)
|
||||||
{
|
{
|
||||||
|
#if OPENTHREAD_USE_READLINE
|
||||||
rl_callback_handler_remove();
|
rl_callback_handler_remove();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void otxConsoleUpdate(otSysMainloopContext *aMainloop)
|
extern "C" void otAppCliUpdate(otSysMainloopContext *aMainloop)
|
||||||
{
|
{
|
||||||
FD_SET(sReadFd, &aMainloop->mReadFdSet);
|
FD_SET(STDIN_FILENO, &aMainloop->mReadFdSet);
|
||||||
FD_SET(sReadFd, &aMainloop->mErrorFdSet);
|
FD_SET(STDIN_FILENO, &aMainloop->mErrorFdSet);
|
||||||
|
|
||||||
if (aMainloop->mMaxFd < sReadFd)
|
if (aMainloop->mMaxFd < STDIN_FILENO)
|
||||||
{
|
{
|
||||||
aMainloop->mMaxFd = sReadFd;
|
aMainloop->mMaxFd = STDIN_FILENO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void otxConsoleProcess(const otSysMainloopContext *aMainloop)
|
extern "C" void otAppCliProcess(const otSysMainloopContext *aMainloop)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(sReadFd, &aMainloop->mErrorFdSet))
|
if (FD_ISSET(STDIN_FILENO, &aMainloop->mErrorFdSet))
|
||||||
{
|
{
|
||||||
perror("console error");
|
|
||||||
exit(OT_EXIT_FAILURE);
|
exit(OT_EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(sReadFd, &aMainloop->mReadFdSet))
|
if (FD_ISSET(STDIN_FILENO, &aMainloop->mReadFdSet))
|
||||||
{
|
{
|
||||||
|
#if OPENTHREAD_USE_READLINE
|
||||||
rl_callback_read_char();
|
rl_callback_read_char();
|
||||||
|
#else
|
||||||
|
char buffer[OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH];
|
||||||
|
|
||||||
|
if (fgets(buffer, sizeof(buffer), stdin) != nullptr)
|
||||||
|
{
|
||||||
|
otCliInputLine(buffer);
|
||||||
|
dprintf(STDOUT_FILENO, "%s", sPrompt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exit(OT_EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_LIBEDIT || HAVE_LIBREADLINE
|
#endif // !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_CLI_TRANSPORT == OT_CLI_TRANSPORT_CONSOLE
|
|
||||||
+73
-12
@@ -67,7 +67,6 @@
|
|||||||
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
||||||
#include <openthread/cli.h>
|
#include <openthread/cli.h>
|
||||||
|
|
||||||
#include "console_cli.h"
|
|
||||||
#include "cli/cli_config.h"
|
#include "cli/cli_config.h"
|
||||||
#else
|
#else
|
||||||
#error "Unknown posix app type!"
|
#error "Unknown posix app type!"
|
||||||
@@ -82,6 +81,58 @@
|
|||||||
#define OPENTHREAD_ENABLE_COVERAGE 0
|
#define OPENTHREAD_ENABLE_COVERAGE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function initializes NCP app.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A pointer to the OpenThread instance.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppNcpInit(otInstance *aInstance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function deinitializes NCP app.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppNcpUpdate(otSysMainloopContext *aContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function updates the file descriptor sets with file descriptors used by console.
|
||||||
|
*
|
||||||
|
* @param[inout] aMainloop A pointer to the mainloop context.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppNcpProcess(const otSysMainloopContext *aContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function initializes CLI app.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A pointer to the OpenThread instance.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppCliInit(otInstance *aInstance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function deinitializes CLI app.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppCliDeinit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function updates the file descriptor sets with file descriptors used by console.
|
||||||
|
*
|
||||||
|
* @param[inout] aMainloop A pointer to the mainloop context.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppCliUpdate(otSysMainloopContext *aMainloop);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function performs console driver processing.
|
||||||
|
*
|
||||||
|
* @param[in] aMainloop A pointer to the mainloop context.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void otAppCliProcess(const otSysMainloopContext *aMainloop);
|
||||||
|
|
||||||
typedef struct PosixConfig
|
typedef struct PosixConfig
|
||||||
{
|
{
|
||||||
otPlatformConfig mPlatformConfig; ///< Platform configuration.
|
otPlatformConfig mPlatformConfig; ///< Platform configuration.
|
||||||
@@ -330,12 +381,10 @@ int main(int argc, char *argv[])
|
|||||||
instance = InitInstance(&config);
|
instance = InitInstance(&config);
|
||||||
|
|
||||||
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
otNcpInit(instance);
|
otAppNcpInit(instance);
|
||||||
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
||||||
#ifdef OPENTHREAD_USE_CONSOLE
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
otxConsoleInit(instance);
|
otAppCliInit(instance);
|
||||||
#else
|
|
||||||
otCliUartInit(instance);
|
|
||||||
#endif
|
#endif
|
||||||
otCliSetUserCommands(&radioUrlCommand, 1, &config.mPlatformConfig);
|
otCliSetUserCommands(&radioUrlCommand, 1, &config.mPlatformConfig);
|
||||||
#endif
|
#endif
|
||||||
@@ -354,8 +403,12 @@ int main(int argc, char *argv[])
|
|||||||
mainloop.mTimeout.tv_sec = 10;
|
mainloop.mTimeout.tv_sec = 10;
|
||||||
mainloop.mTimeout.tv_usec = 0;
|
mainloop.mTimeout.tv_usec = 0;
|
||||||
|
|
||||||
#ifdef OPENTHREAD_USE_CONSOLE
|
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
otxConsoleUpdate(&mainloop);
|
otAppNcpUpdate(&mainloop);
|
||||||
|
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
||||||
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
otAppCliUpdate(&mainloop);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
otSysMainloopUpdate(instance, &mainloop);
|
otSysMainloopUpdate(instance, &mainloop);
|
||||||
@@ -363,8 +416,12 @@ int main(int argc, char *argv[])
|
|||||||
if (otSysMainloopPoll(&mainloop) >= 0)
|
if (otSysMainloopPoll(&mainloop) >= 0)
|
||||||
{
|
{
|
||||||
otSysMainloopProcess(instance, &mainloop);
|
otSysMainloopProcess(instance, &mainloop);
|
||||||
#ifdef OPENTHREAD_USE_CONSOLE
|
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
otxConsoleProcess(&mainloop);
|
otAppNcpProcess(&mainloop);
|
||||||
|
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
||||||
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
otAppCliProcess(&mainloop);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (errno != EINTR)
|
else if (errno != EINTR)
|
||||||
@@ -374,8 +431,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OPENTHREAD_USE_CONSOLE
|
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
otxConsoleDeinit();
|
// disable ncp
|
||||||
|
#elif OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_CLI
|
||||||
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
otAppCliDeinit();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
add_executable(ot-ncp
|
add_executable(ot-ncp
|
||||||
main.c
|
main.c
|
||||||
|
ncp.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021, The OpenThread Authors.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holder nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "openthread-posix-config.h"
|
||||||
|
#include "platform-posix.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <openthread/ncp.h>
|
||||||
|
#include <openthread/platform/misc.h>
|
||||||
|
|
||||||
|
#include "common/code_utils.hpp"
|
||||||
|
|
||||||
|
#if OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
|
static const uint8_t *sWriteBuffer = nullptr;
|
||||||
|
static uint16_t sWriteLength = 0;
|
||||||
|
|
||||||
|
static int ncpHdlcSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||||
|
{
|
||||||
|
sWriteBuffer = aBuf;
|
||||||
|
sWriteLength = aBufLength;
|
||||||
|
|
||||||
|
return aBufLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void otAppNcpInit(otInstance *aInstance)
|
||||||
|
{
|
||||||
|
otNcpHdlcInit(aInstance, ncpHdlcSend);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void otAppNcpUpdate(otSysMainloopContext *aContext)
|
||||||
|
{
|
||||||
|
FD_SET(STDIN_FILENO, &aContext->mReadFdSet);
|
||||||
|
FD_SET(STDIN_FILENO, &aContext->mErrorFdSet);
|
||||||
|
|
||||||
|
if (aContext->mMaxFd < STDIN_FILENO)
|
||||||
|
{
|
||||||
|
aContext->mMaxFd = STDIN_FILENO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sWriteLength > 0)
|
||||||
|
{
|
||||||
|
FD_SET(STDOUT_FILENO, &aContext->mWriteFdSet);
|
||||||
|
FD_SET(STDOUT_FILENO, &aContext->mErrorFdSet);
|
||||||
|
|
||||||
|
if (aContext->mMaxFd < STDOUT_FILENO)
|
||||||
|
{
|
||||||
|
aContext->mMaxFd = STDOUT_FILENO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void otAppNcpProcess(const otSysMainloopContext *aContext)
|
||||||
|
{
|
||||||
|
ssize_t rval;
|
||||||
|
|
||||||
|
if (FD_ISSET(STDIN_FILENO, &aContext->mErrorFdSet))
|
||||||
|
{
|
||||||
|
DieNowWithMessage("stdin", OT_EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FD_ISSET(STDOUT_FILENO, &aContext->mErrorFdSet))
|
||||||
|
{
|
||||||
|
DieNowWithMessage("stdout", OT_EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FD_ISSET(STDIN_FILENO, &aContext->mReadFdSet))
|
||||||
|
{
|
||||||
|
uint8_t buffer[256];
|
||||||
|
|
||||||
|
rval = read(STDIN_FILENO, buffer, sizeof(buffer));
|
||||||
|
|
||||||
|
if (rval > 0)
|
||||||
|
{
|
||||||
|
otNcpHdlcReceive(buffer, static_cast<uint16_t>(rval));
|
||||||
|
}
|
||||||
|
else if (rval <= 0)
|
||||||
|
{
|
||||||
|
DieNowWithMessage("UART read", (rval < 0) ? OT_EXIT_ERROR_ERRNO : OT_EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((FD_ISSET(STDOUT_FILENO, &aContext->mWriteFdSet)))
|
||||||
|
{
|
||||||
|
if (sWriteLength > 0)
|
||||||
|
{
|
||||||
|
rval = write(STDOUT_FILENO, sWriteBuffer, sWriteLength);
|
||||||
|
|
||||||
|
if (rval < 0)
|
||||||
|
{
|
||||||
|
DieNow(OT_EXIT_ERROR_ERRNO);
|
||||||
|
}
|
||||||
|
|
||||||
|
sWriteBuffer += rval;
|
||||||
|
sWriteLength -= static_cast<uint16_t>(rval);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sWriteLength == 0)
|
||||||
|
{
|
||||||
|
otNcpHdlcSendDone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // OPENTHREAD_POSIX_APP_TYPE == OT_POSIX_APP_TYPE_NCP
|
||||||
@@ -60,6 +60,7 @@ list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONF
|
|||||||
add_library(openthread-posix
|
add_library(openthread-posix
|
||||||
alarm.cpp
|
alarm.cpp
|
||||||
backbone.cpp
|
backbone.cpp
|
||||||
|
daemon.cpp
|
||||||
entropy.cpp
|
entropy.cpp
|
||||||
hdlc_interface.cpp
|
hdlc_interface.cpp
|
||||||
infra_if.cpp
|
infra_if.cpp
|
||||||
@@ -74,7 +75,6 @@ add_library(openthread-posix
|
|||||||
spi_interface.cpp
|
spi_interface.cpp
|
||||||
system.cpp
|
system.cpp
|
||||||
trel_udp6.cpp
|
trel_udp6.cpp
|
||||||
uart.cpp
|
|
||||||
udp.cpp
|
udp.cpp
|
||||||
virtual_time.cpp
|
virtual_time.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ libopenthread_posix_a_CPPFLAGS = \
|
|||||||
libopenthread_posix_a_SOURCES = \
|
libopenthread_posix_a_SOURCES = \
|
||||||
alarm.cpp \
|
alarm.cpp \
|
||||||
backbone.cpp \
|
backbone.cpp \
|
||||||
|
daemon.cpp \
|
||||||
entropy.cpp \
|
entropy.cpp \
|
||||||
hdlc_interface.cpp \
|
hdlc_interface.cpp \
|
||||||
infra_if.cpp \
|
infra_if.cpp \
|
||||||
@@ -60,7 +61,6 @@ libopenthread_posix_a_SOURCES = \
|
|||||||
spi_interface.cpp \
|
spi_interface.cpp \
|
||||||
system.cpp \
|
system.cpp \
|
||||||
trel_udp6.cpp \
|
trel_udp6.cpp \
|
||||||
uart.cpp \
|
|
||||||
udp.cpp \
|
udp.cpp \
|
||||||
virtual_time.cpp \
|
virtual_time.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user