mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 13:59:05 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
bin_PROGRAMS = soc
|
||||
|
||||
soc_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples \
|
||||
-I$(top_srcdir)/examples/platform/posix \
|
||||
$(OPENTHREAD_TARGET_DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
soc_LDADD = \
|
||||
$(top_srcdir)/src/core/libopenthread.a \
|
||||
$(top_srcdir)/src/cli/libopenthread-cli.a \
|
||||
$(top_srcdir)/examples/platform/posix/libopenthread-posix.a \
|
||||
$(top_srcdir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
-lpthread \
|
||||
$(NULL)
|
||||
|
||||
soc_SOURCES = \
|
||||
main.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,85 @@
|
||||
# OpenThread CLI Example
|
||||
|
||||
This example application demonstrates a minimal OpenThread application
|
||||
that exposes the OpenThread configuration and management interfaces
|
||||
via a basic command-line interface. The steps below take you through
|
||||
the minimal steps required to ping one (emulated) Thread device from
|
||||
another (emulated) Thread device.
|
||||
|
||||
## 1. Build
|
||||
|
||||
```bash
|
||||
$ cd openthread
|
||||
$ ./bootstrap-configure
|
||||
$ make
|
||||
```
|
||||
|
||||
## 2. Start Node 1
|
||||
|
||||
Spawn the process:
|
||||
|
||||
```bash
|
||||
$ cd openthread/examples/cli
|
||||
$ ./soc --nodeid=1 -S
|
||||
```
|
||||
|
||||
Start OpenThread:
|
||||
|
||||
```bash
|
||||
$ start
|
||||
Done
|
||||
```
|
||||
|
||||
Wait a few seconds and verify that the device has become a Thread Leader:
|
||||
|
||||
```bash
|
||||
$ state
|
||||
leader
|
||||
Done
|
||||
```
|
||||
|
||||
View IPv6 addresses assigned to Node 1's Thread interface:
|
||||
|
||||
```bash
|
||||
$ ipaddr
|
||||
fdde:ad00:beef:0:0:ff:fe00:0
|
||||
fe80:0:0:0:0:ff:fe00:0
|
||||
fdde:ad00:beef:0:558:f56b:d688:799
|
||||
fe80:0:0:0:f3d9:2a82:c8d8:fe43
|
||||
Done
|
||||
```
|
||||
|
||||
## 2. Start Node 2
|
||||
|
||||
Spawn the process:
|
||||
|
||||
```bash
|
||||
$ cd openthread/examples/cli
|
||||
$ ./soc --nodeid=2 -S
|
||||
```
|
||||
|
||||
Start OpenThread:
|
||||
|
||||
```bash
|
||||
$ start
|
||||
Done
|
||||
```
|
||||
|
||||
Wait a few seconds and verify that the device has become a Thread Router:
|
||||
|
||||
```bash
|
||||
$ state
|
||||
leader
|
||||
Done
|
||||
```
|
||||
|
||||
## 3. Ping Node 1 from Node 2
|
||||
|
||||
```bash
|
||||
$ ping fdde:ad00:beef:0:558:f56b:d688:799
|
||||
16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64
|
||||
```
|
||||
|
||||
## 4. Ready for More?
|
||||
|
||||
See the [OpenThread CLI Reference README.md](../../src/cli/README.md) to explore more.
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include <platform/posix/cmdline.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <cli/cli_serial.hpp>
|
||||
#include <platform/atomic.h>
|
||||
#include <platform.h>
|
||||
|
||||
struct gengetopt_args_info args_info;
|
||||
|
||||
Thread::Cli::Serial sCliServer;
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint32_t atomic_state;
|
||||
|
||||
memset(&args_info, 0, sizeof(args_info));
|
||||
|
||||
if (cmdline_parser(argc, argv, &args_info) != 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
hwAlarmInit();
|
||||
hwRadioInit();
|
||||
hwRandomInit();
|
||||
|
||||
otInit();
|
||||
sCliServer.Start();
|
||||
|
||||
while (1)
|
||||
{
|
||||
otProcessNextTasklet();
|
||||
|
||||
atomic_state = otPlatAtomicBegin();
|
||||
|
||||
if (!otAreTaskletsPending())
|
||||
{
|
||||
hwSleep();
|
||||
}
|
||||
|
||||
otPlatAtomicEnd(atomic_state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user