mirror of
https://github.com/espressif/openthread.git
synced 2026-08-31 14:29:54 +00:00
Move example apps to C-only API. (#99)
This commit is contained in:
@@ -425,7 +425,9 @@ NL_RESTORE_WERROR
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
include/Makefile
|
||||
include/cli/Makefile
|
||||
include/crypto/Makefile
|
||||
include/ncp/Makefile
|
||||
include/platform/Makefile
|
||||
src/Makefile
|
||||
src/cli/Makefile
|
||||
|
||||
@@ -43,10 +43,11 @@ soc_LDADD = \
|
||||
$(top_builddir)/src/cli/libopenthread-cli.a \
|
||||
$(top_builddir)/examples/posix/platform/libopenthread-posix.a \
|
||||
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
-lstdc++ \
|
||||
$(NULL)
|
||||
|
||||
soc_SOURCES = \
|
||||
main.cpp \
|
||||
main.c \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -29,11 +29,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <cli/cli_serial.hpp>
|
||||
#include <cli/cli-serial.h>
|
||||
#include <posix-platform.h>
|
||||
|
||||
Thread::Cli::Serial sCliServer;
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
{
|
||||
}
|
||||
@@ -49,7 +47,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
posixPlatformInit();
|
||||
otInit();
|
||||
sCliServer.Start();
|
||||
otCliSerialInit();
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -44,8 +44,11 @@ ncp_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(top_builddir)/examples/posix/platform/libopenthread-posix.a \
|
||||
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
-lstdc++ \
|
||||
$(NULL)
|
||||
|
||||
ncp_SOURCES = main.cpp
|
||||
ncp_SOURCES = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -27,11 +27,10 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ncp/ncp.hpp>
|
||||
#include <openthread.h>
|
||||
#include <ncp/ncp.h>
|
||||
#include <posix-platform.h>
|
||||
|
||||
Thread::Ncp sNcp;
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
{
|
||||
}
|
||||
@@ -46,8 +45,7 @@ int main(int argc, char *argv[])
|
||||
NODE_ID = atoi(argv[1]);
|
||||
posixPlatformInit();
|
||||
otInit();
|
||||
|
||||
sNcp.Start();
|
||||
otNcpInit();
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <openthread.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/serial.h>
|
||||
#include <posix-platform.h>
|
||||
|
||||
uint32_t NODE_ID = 1;
|
||||
@@ -50,6 +51,7 @@ void posixPlatformInit(void)
|
||||
posixPlatformAlarmInit();
|
||||
posixPlatformRadioInit();
|
||||
posixPlatformRandomInit();
|
||||
otPlatSerialEnable();
|
||||
}
|
||||
|
||||
void posixPlatformProcessDrivers(void)
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@@ -31,21 +31,27 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
# Always package (e.g. for 'make dist') these subdirectories.
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
cli \
|
||||
crypto \
|
||||
ncp \
|
||||
platform \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
cli \
|
||||
crypto \
|
||||
ncp \
|
||||
platform \
|
||||
$(NULL)
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
cli \
|
||||
crypto \
|
||||
ncp \
|
||||
platform \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
include_HEADERS = \
|
||||
cli-serial.h \
|
||||
$(NULL)
|
||||
|
||||
install-headers: install-includeHEADERS
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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
|
||||
* @brief
|
||||
* This file defines the top-level functions for the OpenThread CLI server.
|
||||
*/
|
||||
|
||||
#ifndef CLI_SERIAL_H_
|
||||
#define CLI_SERIAL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize the CLI serial server.
|
||||
*
|
||||
*/
|
||||
void otCliSerialInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
include_HEADERS = \
|
||||
ncp.h \
|
||||
$(NULL)
|
||||
|
||||
install-headers: install-includeHEADERS
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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
|
||||
* @brief
|
||||
* This file defines the top-level functions for the OpenThread CLI server.
|
||||
*/
|
||||
|
||||
#ifndef NCP_H_
|
||||
#define NCP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize the CLI serial server.
|
||||
*
|
||||
*/
|
||||
void otNcpInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -31,12 +31,15 @@
|
||||
* This file implements the CLI server on the serial service.
|
||||
*/
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cli/cli.hpp>
|
||||
#include <cli/cli-serial.h>
|
||||
#include <cli/cli_serial.hpp>
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/encoding.hpp>
|
||||
@@ -50,19 +53,19 @@ static const char sEraseString[] = {'\b', ' ', '\b'};
|
||||
static const char CRNL[] = {'\r', '\n'};
|
||||
static Serial *sServer;
|
||||
|
||||
Serial::Serial(void)
|
||||
static otDEFINE_ALIGNED_VAR(sCliSerialRaw, sizeof(Serial), uint64_t);
|
||||
|
||||
extern "C" void otCliSerialInit(void)
|
||||
{
|
||||
sServer = this;
|
||||
sServer = new(&sCliSerialRaw) Serial;
|
||||
}
|
||||
|
||||
ThreadError Serial::Start(void)
|
||||
Serial::Serial(void)
|
||||
{
|
||||
mRxLength = 0;
|
||||
mTxHead = 0;
|
||||
mTxLength = 0;
|
||||
mSendLength = 0;
|
||||
otPlatSerialEnable();
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
extern "C" void otPlatSerialReceived(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
|
||||
@@ -50,14 +50,6 @@ class Serial: public Server
|
||||
public:
|
||||
Serial(void);
|
||||
|
||||
/**
|
||||
* This method starts the CLI server.
|
||||
*
|
||||
* @retval kThreadError_None Successfully started the server.
|
||||
*
|
||||
*/
|
||||
ThreadError Start(void);
|
||||
|
||||
/**
|
||||
* This method delivers raw characters to the client.
|
||||
*
|
||||
|
||||
@@ -46,14 +46,6 @@ namespace Cli {
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method starts the CLI server.
|
||||
*
|
||||
* @retval kThreadError_None Successfully started the server.
|
||||
*
|
||||
*/
|
||||
virtual ThreadError Start() = 0;
|
||||
|
||||
/**
|
||||
* This method delivers raw characters to the client.
|
||||
*
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// Allocate the structure using "raw" storage.
|
||||
#define otDEFINE_ALIGNED_VAR(name, size, align_type) \
|
||||
align_type name[(((size) + (sizeof (align_type) - 1)) / sizeof (align_type))]
|
||||
|
||||
#define SuccessOrExit(ERR) \
|
||||
do { \
|
||||
if ((ERR) != 0) { \
|
||||
|
||||
@@ -54,10 +54,6 @@ ThreadNetif *sThreadNetif;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Allocate the structure using "raw" storage.
|
||||
#define otDEFINE_ALIGNED_VAR(name, size, align_type) \
|
||||
align_type name[(((size) + (sizeof (align_type) - 1)) / sizeof (align_type))]
|
||||
|
||||
static otDEFINE_ALIGNED_VAR(sThreadNetifRaw, sizeof(ThreadNetif), uint64_t);
|
||||
|
||||
static void HandleActiveScanResult(void *aContext, Mac::Frame *aFrame);
|
||||
|
||||
+9
-13
@@ -30,31 +30,27 @@
|
||||
* This file implements an HDLC interface to the Thread stack.
|
||||
*/
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <ncp/ncp.h>
|
||||
#include <ncp/ncp.hpp>
|
||||
#include <platform/serial.h>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
static otDEFINE_ALIGNED_VAR(sNcpRaw, sizeof(Ncp), uint64_t);
|
||||
static Ncp *sNcp;
|
||||
|
||||
extern "C" void otNcpInit(void)
|
||||
{
|
||||
sNcp = new(&sNcpRaw) Ncp;
|
||||
}
|
||||
|
||||
Ncp::Ncp():
|
||||
NcpBase(),
|
||||
mFrameDecoder(mReceiveFrame, sizeof(mReceiveFrame), &HandleFrame, this)
|
||||
{
|
||||
sNcp = this;
|
||||
}
|
||||
|
||||
ThreadError Ncp::Start()
|
||||
{
|
||||
otPlatSerialEnable();
|
||||
return super_t::Start();
|
||||
}
|
||||
|
||||
ThreadError Ncp::Stop()
|
||||
{
|
||||
otPlatSerialDisable();
|
||||
return super_t::Stop();
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
||||
@@ -46,10 +46,6 @@ class Ncp : public NcpBase
|
||||
public:
|
||||
Ncp();
|
||||
|
||||
ThreadError Start();
|
||||
ThreadError Stop();
|
||||
|
||||
|
||||
virtual ThreadError OutboundFrameBegin(void);
|
||||
virtual uint16_t OutboundFrameGetRemaining(void);
|
||||
virtual ThreadError OutboundFrameFeedData(const uint8_t *frame, uint16_t frameLength);
|
||||
|
||||
@@ -228,19 +228,10 @@ NcpBase::NcpBase():
|
||||
mSupportedChannelMask = (0xFFFF << 11); // Default to 2.4GHz 802.15.4 channels.
|
||||
mChannelMask = mSupportedChannelMask;
|
||||
mScanPeriod = 200; // ms
|
||||
}
|
||||
|
||||
ThreadError NcpBase::Start()
|
||||
{
|
||||
assert(sThreadNetif != NULL);
|
||||
sThreadNetif->RegisterHandler(mNetifHandler);
|
||||
Ip6::Ip6::SetNcpReceivedHandler(&HandleDatagramFromStack, this);
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError NcpBase::Stop()
|
||||
{
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -47,9 +47,6 @@ public:
|
||||
|
||||
NcpBase();
|
||||
|
||||
ThreadError Start();
|
||||
ThreadError Stop();
|
||||
|
||||
protected:
|
||||
|
||||
virtual ThreadError OutboundFrameBegin(void) = 0;
|
||||
|
||||
Reference in New Issue
Block a user