reorg apps and platforms (#89)

This commit is contained in:
Marcin K Szczodrak
2016-06-01 16:01:22 -07:00
committed by Jonathan Hui
parent ba0955a030
commit ef9de65117
21 changed files with 164 additions and 85 deletions
+2 -1
View File
@@ -45,7 +45,8 @@ contributing to the ongoing development of OpenThread.
# Getting Started #
The easiest way to get started is to run the CLI example in
`/examples/cli`. See the [CLI example README](examples/cli/README.md)
`/examples/posix/app/cli`. See the
[CLI example README](examples/posix/app/cli/README.md)
for more details.
+5 -4
View File
@@ -434,10 +434,11 @@ src/core/Makefile
third_party/Makefile
third_party/mbedtls/Makefile
examples/Makefile
examples/platform/Makefile
examples/platform/posix/Makefile
examples/cli/Makefile
examples/ncp/Makefile
examples/posix/Makefile
examples/posix/app/Makefile
examples/posix/app/cli/Makefile
examples/posix/app/ncp/Makefile
examples/posix/platform/Makefile
tests/Makefile
tests/scripts/Makefile
tests/unit/Makefile
+3 -8
View File
@@ -31,24 +31,19 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
# Always package (e.g. for 'make dist') these subdirectories.
DIST_SUBDIRS = \
platform \
cli \
ncp \
posix \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
SUBDIRS = \
platform \
cli \
ncp \
posix \
$(NULL)
# Always pretty (e.g. for 'make pretty') these subdirectories.
PRETTY_SUBDIRS = \
platform \
cli \
posix \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+52
View File
@@ -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.
#
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
# Always package (e.g. for 'make dist') these subdirectories.
DIST_SUBDIRS = \
platform \
app \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
SUBDIRS = \
platform \
app \
$(NULL)
# Always pretty (e.g. for 'make pretty') these subdirectories.
PRETTY_SUBDIRS = \
platform \
app \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
@@ -31,19 +31,21 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
# Always package (e.g. for 'make dist') these subdirectories.
DIST_SUBDIRS = \
posix \
cli \
ncp \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
SUBDIRS = \
posix \
cli \
ncp \
$(NULL)
# Always pretty (e.g. for 'make pretty') these subdirectories.
PRETTY_SUBDIRS = \
posix \
cli \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
@@ -34,15 +34,14 @@ 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 \
-I$(top_srcdir)/examples/posix/platform \
$(OPENTHREAD_TARGET_DEFINES) \
$(NULL)
soc_LDADD = \
$(top_builddir)/src/core/libopenthread.a \
$(top_builddir)/src/cli/libopenthread-cli.a \
$(top_builddir)/examples/platform/posix/libopenthread-posix.a \
$(top_builddir)/examples/posix/platform/libopenthread-posix.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
$(NULL)
@@ -19,7 +19,7 @@ $ make
Spawn the process:
```bash
$ cd openthread/examples/cli
$ cd openthread/examples/posix/app/cli
$ ./soc 1
```
@@ -54,7 +54,7 @@ Done
Spawn the process:
```bash
$ cd openthread/examples/cli
$ cd openthread/examples/posix/app/cli
$ ./soc 2
```
@@ -30,7 +30,7 @@
#include <openthread.h>
#include <cli/cli_serial.hpp>
#include <platform.h>
#include <posix-platform.h>
Thread::Cli::Serial sCliServer;
@@ -47,14 +47,14 @@ int main(int argc, char *argv[])
NODE_ID = atoi(argv[1]);
PlatformInit();
posixPlatformInit();
otInit();
sCliServer.Start();
while (1)
{
otProcessNextTasklet();
PlatformProcessDrivers();
posixPlatformProcessDrivers();
}
return 0;
@@ -34,8 +34,7 @@ ncp_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examples \
-I$(top_srcdir)/examples/platform/posix \
-I$(top_srcdir)/examples/posix/platform \
-I$(top_srcdir)/third_party \
$(OPENTHREAD_TARGET_DEFINES) \
$(NULL)
@@ -43,7 +42,7 @@ ncp_CPPFLAGS = \
ncp_LDADD = \
$(top_builddir)/src/ncp/libopenthread-ncp.a \
$(top_builddir)/src/core/libopenthread.a \
$(top_builddir)/examples/platform/posix/libopenthread-posix.a \
$(top_builddir)/examples/posix/platform/libopenthread-posix.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
$(NULL)
@@ -28,7 +28,7 @@
#include <stdlib.h>
#include <ncp/ncp.hpp>
#include <platform.h>
#include <posix-platform.h>
Thread::Ncp sNcp;
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
}
NODE_ID = atoi(argv[1]);
PlatformInit();
posixPlatformInit();
otInit();
sNcp.Start();
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
while (1)
{
otProcessNextTasklet();
PlatformProcessDrivers();
posixPlatformProcessDrivers();
}
return 0;
@@ -34,8 +34,7 @@ libopenthread_posix_a_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examples \
-I$(top_srcdir)/examples/platform/posix \
-I$(top_srcdir)/examples/posix/platform \
$(OPENTHREAD_TARGET_DEFINES) \
-D_BSD_SOURCE \
-D_GNU_SOURCE \
@@ -45,8 +44,7 @@ libopenthread_posix_a_CXXFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examplse \
-I$(top_srcdir)/examples/platform/posix \
-I$(top_srcdir)/examples/posix/platform \
$(OPENTHREAD_TARGET_DEFINES) \
$(NULL)
@@ -54,13 +52,14 @@ libopenthread_posix_a_SOURCES = \
alarm.c \
logging.c \
platform.c \
posix-platform.c \
radio.cpp \
random.c \
serial.c \
$(NULL)
include_HEADERS = \
platform.h \
posix-platform.h \
$(NULL)
install-headers: install-includeHEADERS
@@ -32,12 +32,13 @@
#include <sys/time.h>
#include <platform/alarm.h>
#include <posix-platform.h>
static bool s_is_running = false;
static uint32_t s_alarm = 0;
static struct timeval s_start;
void PlatformAlarmInit(void)
void posixPlatformAlarmInit(void)
{
gettimeofday(&s_start, NULL);
}
@@ -63,7 +64,7 @@ void otPlatAlarmStop(void)
s_is_running = false;
}
void PlatformAlarmUpdateTimeout(struct timeval *aTimeout)
void posixPlatformAlarmUpdateTimeout(struct timeval *aTimeout)
{
int32_t remaining;
@@ -94,7 +95,7 @@ void PlatformAlarmUpdateTimeout(struct timeval *aTimeout)
}
}
void PlatformAlarmProcess(void)
void posixPlatformAlarmProcess(void)
{
int32_t remaining;
@@ -40,20 +40,19 @@
#include <openthread.h>
#include <platform/alarm.h>
#include "platform.h"
#include <posix-platform.h>
uint32_t NODE_ID = 1;
uint32_t WELLKNOWN_NODE_ID = 34;
void PlatformInit(void)
void posixPlatformInit(void)
{
PlatformAlarmInit();
PlatformRadioInit();
PlatformRandomInit();
posixPlatformAlarmInit();
posixPlatformRadioInit();
posixPlatformRandomInit();
}
void PlatformProcessDrivers(void)
void posixPlatformProcessDrivers(void)
{
fd_set read_fds;
fd_set write_fds;
@@ -64,9 +63,9 @@ void PlatformProcessDrivers(void)
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
PlatformSerialUpdateFdSet(&read_fds, &write_fds, &max_fd);
PlatformRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
PlatformAlarmUpdateTimeout(&timeout);
posixPlatformSerialUpdateFdSet(&read_fds, &write_fds, &max_fd);
posixPlatformRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
posixPlatformAlarmUpdateTimeout(&timeout);
if (!otAreTaskletsPending())
{
@@ -74,8 +73,8 @@ void PlatformProcessDrivers(void)
assert(rval >= 0 && errno != ETIME);
}
PlatformSerialProcess();
PlatformRadioProcess();
PlatformAlarmProcess();
posixPlatformSerialProcess();
posixPlatformRadioProcess();
posixPlatformAlarmProcess();
}
+38
View File
@@ -0,0 +1,38 @@
/*
* 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 includes the platform-specific initializers.
*/
#include <posix-platform.h>
uint32_t NODE_ID = 1;
@@ -29,11 +29,11 @@
/**
* @file
* @brief
* This file includes the platform-specific initializers.
* This file includes the posix platform-specific initializers.
*/
#ifndef PLATFORM_H_
#define PLATFORM_H_
#ifndef POSIX_PLATFORM_H_
#define POSIX_PLATFORM_H_
#include <stdint.h>
#include <sys/select.h>
@@ -44,7 +44,7 @@ extern "C" {
#endif
/**
* Unique ID used by a simulated node.
* Unique node ID.
*
*/
extern uint32_t NODE_ID;
@@ -59,19 +59,19 @@ extern uint32_t WELLKNOWN_NODE_ID;
* This method performs all platform-specific initialization.
*
*/
void PlatformInit(void);
void posixPlatformInit(void);
/**
* This method performs all platform-specific processing.
*
*/
void PlatformProcessDrivers(void);
void posixPlatformProcessDrivers(void);
/**
* This method initializes the alarm service used by OpenThread.
*
*/
void PlatformAlarmInit(void);
void posixPlatformAlarmInit(void);
/**
* This method retrieves the time remaining until the alarm fires.
@@ -79,19 +79,19 @@ void PlatformAlarmInit(void);
* @param[out] aTimeval A pointer to the timeval struct.
*
*/
void PlatformAlarmUpdateTimeout(struct timeval *tv);
void posixPlatformAlarmUpdateTimeout(struct timeval *tv);
/**
* This method performs alarm driver processing.
*
*/
void PlatformAlarmProcess(void);
void posixPlatformAlarmProcess(void);
/**
* This method initializes the radio service used by OpenThread.
*
*/
void PlatformRadioInit(void);
void posixPlatformRadioInit(void);
/**
* This method updates the file descriptor sets with file descriptors used by the radio driver.
@@ -101,19 +101,19 @@ void PlatformRadioInit(void);
* @param[inout] aMaxFd A pointer to the max file descriptor.
*
*/
void PlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
void posixPlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
/**
* This method performs radio driver processing.
*
*/
void PlatformRadioProcess(void);
void posixPlatformRadioProcess(void);
/**
* This method initializes the random number service used by OpenThread.
*
*/
void PlatformRandomInit(void);
void posixPlatformRandomInit(void);
/**
* This method updates the file descriptor sets with file descriptors used by the serial driver.
@@ -123,22 +123,16 @@ void PlatformRandomInit(void);
* @param[inout] aMaxFd A pointer to the max file descriptor.
*
*/
void PlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
void posixPlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
/**
* This method performs radio driver processing.
*
*/
void PlatformSerialProcess(void);
/**
* This method puts the thread executing OpenThread to sleep.
*
*/
void PlatformSleep(void);
void posixPlatformSerialProcess(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // PLATFORM_H_
#endif // POSIX_PLATFORM_H_
@@ -42,8 +42,7 @@
#include <common/debug.hpp>
#include <mac/mac.hpp>
#include <platform/radio.h>
#include "platform.h"
#include <posix-platform.h>
#ifdef __cplusplus
extern "C" {
@@ -110,7 +109,7 @@ ThreadError otPlatRadioSetShortAddress(uint16_t address)
return kThreadError_None;
}
void PlatformRadioInit(void)
void posixPlatformRadioInit(void)
{
struct sockaddr_in sockaddr;
memset(&sockaddr, 0, sizeof(sockaddr));
@@ -370,7 +369,7 @@ int radioTransmit(void)
return rval;
}
void PlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
void posixPlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
{
if (aReadFdSet != NULL &&
(s_state == kStateDisabled || s_state == kStateSleep || s_state == kStateListen || s_state == kStateAckWait))
@@ -394,7 +393,7 @@ void PlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMax
}
}
void PlatformRadioProcess(void)
void posixPlatformRadioProcess(void)
{
const int flags = POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd = { s_sockfd, flags, 0 };
@@ -35,11 +35,11 @@
*/
#include <platform/random.h>
#include "platform.h"
#include <posix-platform.h>
static uint32_t s_state = 1;
void PlatformRandomInit(void)
void posixPlatformRandomInit(void)
{
s_state = NODE_ID;
}
@@ -35,7 +35,7 @@
#include <common/code_utils.hpp>
#include <platform/serial.h>
#include "platform.h"
#include <posix-platform.h>
#ifdef OPENTHREAD_TARGET_LINUX
int posix_openpt(int oflag);
@@ -162,7 +162,7 @@ exit:
return error;
}
void PlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
void posixPlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
{
if (aReadFdSet != NULL)
{
@@ -185,7 +185,7 @@ void PlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMa
}
}
void PlatformSerialProcess(void)
void posixPlatformSerialProcess(void)
{
const int flags = POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd = { s_in_fd, flags, 0 };
+1 -1
View File
@@ -54,7 +54,7 @@ class Node:
""" Initialize a simulation node. """
if "top_builddir" in os.environ.keys():
srcdir = os.environ['top_builddir']
cmd = '%s/examples/cli/soc' % srcdir
cmd = '%s/examples/posix/app/cli/soc' % srcdir
else:
cmd = './soc'
cmd += ' %d' % nodeid
+1 -1
View File
@@ -55,7 +55,7 @@ AM_CPPFLAGS = \
COMMON_LDADD = \
$(top_builddir)/src/core/libopenthread.a \
$(top_builddir)/examples/platform/posix/libopenthread-posix.a \
$(top_builddir)/examples/posix/platform/libopenthread-posix.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
-lpthread \
$(NULL)