[posix] clean up for radio url (#5027)

* fix max-power-table documentation
* rename `baudrate` to `uart-baudrate`, `arg` to `forkpty-arg`
* update command line enumeration
* update README
* remove trailing argument from node.py
This commit is contained in:
Yakun Xu
2020-06-01 08:13:46 -07:00
committed by GitHub
parent 115616c6bf
commit f8f75d6d05
13 changed files with 111 additions and 87 deletions
+3 -3
View File
@@ -93,12 +93,12 @@ EOF
echo "Step 2. Start retrieving dataset from Radio..."
RADIO_NCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-ncp-ftd)"
"$(pwd)/$(ls output/posix/*linux*/bin/ot-ncp)" -n --radio-version "spinel+hdlc+forkpty://${RADIO_NCP_PATH}?arg=1&ncp-dataset=1"
"$(pwd)/$(ls output/posix/*linux*/bin/ot-ncp)" -n --radio-version "spinel+hdlc+forkpty://${RADIO_NCP_PATH}?forkpty-arg=1&ncp-dataset=1"
echo "Step 3. Start posix app and check whether PAN dataset is the same..."
RADIO_RCP_PATH="$(pwd)/$(ls output/*linux*/bin/ot-rcp)"
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli) spinel+hdlc+forkpty://${RADIO_RCP_PATH}?arg=1"
OT_CLI_CMD="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli) spinel+hdlc+forkpty://${RADIO_RCP_PATH}?forkpty-arg=1"
expect <<EOF
spawn ${OT_CLI_CMD}
@@ -126,7 +126,7 @@ expect eof
EOF
echo "Step 4. Start posix app and check whether it can get radio firmware version..."
RADIO_VERSION="$("$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)" -n --radio-version "spinel+hdlc+forkpty://${RADIO_RCP_PATH}?arg=1&ncp-dataset=1")" || true
RADIO_VERSION="$("$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)" -n --radio-version "spinel+hdlc+forkpty://${RADIO_RCP_PATH}?forkpty-arg=1&ncp-dataset=1")" || true
echo "${RADIO_VERSION}"
test -n "{RADIO_VERSION}"
}
+2
View File
@@ -91,6 +91,8 @@ check()
# verify this reset and factoryreset end immediately
sudo "${OT_CLI_CMD}" reset
# sleep a while for daemon ready
sleep 2
sudo "${OT_CLI_CMD}" factoryreset
else
OT_CLI="$(pwd)/$(ls output/posix/*linux*/bin/ot-cli)"
+9 -9
View File
@@ -33,7 +33,7 @@ make -f examples/Makefile-xxxx
```sh
make -f examples/Makefile-simulation
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli ./output/x86_64-unknown-linux-gnu/bin/ot-rcp 1
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli 'spinel+hdlc+forkpty://output/x86_64-unknown-linux-gnu/bin/ot-rcp?forkpty-arg=1'
```
### With Real Device
@@ -58,7 +58,7 @@ expect "Probe configured successfully."
exit
EOF
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli /dev/ttyACM0 115200
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200'
```
- USB=1
@@ -69,7 +69,7 @@ make -f examples/Makefile-nrf52840 USB=1
arm-none-eabi-objcopy -O ihex output/nrf52840/bin/ot-rcp ot-rcp.hex
nrfjprog -f nrf52 --chiperase --reset --program ot-rcp.hex
# plug the CDC serial USB port
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli /dev/ttyACM0 115200
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200'
```
#### CC2538
@@ -79,7 +79,7 @@ make -f examples/Makefile-cc2538
arm-none-eabi-objcopy -O binary output/cc2538/bin/ot-rcp ot-rcp.bin
# see https://github.com/JelmerT/cc2538-bsl
python cc2538-bsl/cc2538-bsl.py -b 460800 -e -w -v -p /dev/ttyUSB0 ot-rcp.bin
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli /dev/ttyUSB0 115200
./output/posix/x86_64-unknown-linux-gnu/bin/ot-cli 'spinel+hdlc+uart:///dev/ttyUSB0?uart-baudrate=115200'
```
## Wpantund Support
@@ -89,16 +89,16 @@ python cc2538-bsl/cc2538-bsl.py -b 460800 -e -w -v -p /dev/ttyUSB0 ot-rcp.bin
### With Simulation
```sh
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp ./output/x86_64-unknown-linux-gnu/bin/ot-rcp 1'
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp spinel+hdlc+forkpty://output/x86_64-unknown-linux-gnu/bin/ot-rcp?forkpty-arg=1'
```
### With Real Device
```sh
# nRF52840
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp /dev/ttyACM0 115200'
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200'
# CC2538
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp /dev/ttyUSB0 115200'
sudo wpantund -s 'system:./output/posix/x86_64-unknown-linux-gnu/bin/ot-ncp spinel+hdlc+uart:///dev/ttyUSB0?uart-baudrate=115200'
```
## Daemon Mode Support
@@ -109,9 +109,9 @@ OpenThread Posix Daemon mode uses a unix socket as input and output, so that Ope
# build daemon mode core stack for POSIX
make -f src/posix/Makefile-posix DAEMON=1
# Daemon with simulation
./output/posix/x86_64-unknown-linux-gnu/bin/ot-daemon ./output/x86_64-unknown-linux-gnu/bin/ot-rcp 1
./output/posix/x86_64-unknown-linux-gnu/bin/ot-daemon 'spinel+hdlc+forkpty://output/x86_64-unknown-linux-gnu/bin/ot-rcp?forkpty-arg=1'
# Daemon with real device
./output/posix/x86_64-unknown-linux-gnu/bin/ot-daemon /dev/ttyACM0 115200
./output/posix/x86_64-unknown-linux-gnu/bin/ot-daemon 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200'
# Built-in controller
./output/posix/x86_64-unknown-linux-gnu/bin/ot-ctl
```
+25 -22
View File
@@ -37,6 +37,7 @@
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
@@ -102,16 +103,25 @@ void __gcov_flush();
*/
enum
{
ARG_PRINT_RADIO_VERSION = 1001,
OT_POSIX_OPT_DEBUG_LEVEL = 'd',
OT_POSIX_OPT_DRY_RUN = 'n',
OT_POSIX_OPT_HELP = 'h',
OT_POSIX_OPT_INTERFACE_NAME = 'I',
OT_POSIX_OPT_TIME_SPEED = 's',
OT_POSIX_OPT_VERBOSE = 'v',
OT_POSIX_OPT_SHORT_MAX = 128,
OT_POSIX_OPT_RADIO_VERSION,
};
static const struct option kOptions[] = {{"debug-level", required_argument, NULL, 'd'},
{"dry-run", no_argument, NULL, 'n'},
{"help", no_argument, NULL, 'h'},
{"interface-name", required_argument, NULL, 'I'},
{"radio-version", no_argument, NULL, ARG_PRINT_RADIO_VERSION},
{"time-speed", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
static const struct option kOptions[] = {{"debug-level", required_argument, NULL, OT_POSIX_OPT_DEBUG_LEVEL},
{"dry-run", no_argument, NULL, OT_POSIX_OPT_DRY_RUN},
{"help", no_argument, NULL, OT_POSIX_OPT_HELP},
{"interface-name", required_argument, NULL, OT_POSIX_OPT_INTERFACE_NAME},
{"radio-version", no_argument, NULL, OT_POSIX_OPT_RADIO_VERSION},
{"time-speed", required_argument, NULL, OT_POSIX_OPT_TIME_SPEED},
{"verbose", no_argument, NULL, OT_POSIX_OPT_VERBOSE},
{0, 0, 0, 0}};
static void PrintUsage(const char *aProgramName, FILE *aStream, int aExitCode)
@@ -128,13 +138,6 @@ static void PrintUsage(const char *aProgramName, FILE *aStream, int aExitCode)
" -s --time-speed factor Time speed up factor.\n"
" -v --verbose Also log to stderr.\n",
aProgramName);
#if OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
fprintf(aStream,
" --max-power-table Max power for channels in ascending order separated by commas,\n"
" If the number of values is less than that of supported channels,\n"
" the last value will be applied to all remaining channels.\n"
" Special value 0x7f disables a channel.\n");
#endif
fprintf(aStream, "%s", otSysGetRadioUrlHelpString());
exit(aExitCode);
}
@@ -160,19 +163,19 @@ static void ParseArg(int aArgCount, char *aArgVector[], PosixConfig *aConfig)
switch (option)
{
case 'd':
case OT_POSIX_OPT_DEBUG_LEVEL:
aConfig->mLogLevel = (otLogLevel)atoi(optarg);
break;
case 'h':
case OT_POSIX_OPT_HELP:
PrintUsage(aArgVector[0], stdout, OT_EXIT_SUCCESS);
break;
case 'I':
case OT_POSIX_OPT_INTERFACE_NAME:
aConfig->mPlatformConfig.mInterfaceName = optarg;
break;
case 'n':
case OT_POSIX_OPT_DRY_RUN:
aConfig->mIsDryRun = true;
break;
case 's':
case OT_POSIX_OPT_TIME_SPEED:
{
char *endptr = NULL;
@@ -185,10 +188,10 @@ static void ParseArg(int aArgCount, char *aArgVector[], PosixConfig *aConfig)
}
break;
}
case 'v':
case OT_POSIX_OPT_VERBOSE:
aConfig->mIsVerbose = true;
break;
case ARG_PRINT_RADIO_VERSION:
case OT_POSIX_OPT_RADIO_VERSION:
aConfig->mPrintRadioVersion = true;
break;
case '?':
+2 -2
View File
@@ -155,7 +155,7 @@ otError HdlcInterface::Init(Arguments &aArguments)
#if OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
else if (S_ISREG(st.st_mode))
{
mSockFd = ForkPty(aArguments.GetPath(), aArguments.GetValue("arg"));
mSockFd = ForkPty(aArguments.GetPath(), aArguments.GetValue("forkpty-arg"));
VerifyOrExit(mSockFd != -1, error = OT_ERROR_INVALID_ARGS);
}
#endif // OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
@@ -469,7 +469,7 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
break;
}
if (aArguments.GetValue("baudrate"))
if (aArguments.GetValue("uart-baudrate"))
{
baudrate = static_cast<uint32_t>(atoi(aArguments.GetValue("baudrate")));
}
@@ -64,6 +64,12 @@ enum
32, ///< Default smallest SPI packet size we can receive in a single transaction.
};
/**
* This structure represents the radio URL.
*
*/
typedef struct otPosixRadioArguments otPosixRadioArguments;
/**
* This structure represents platform specific configurations.
*
+49 -37
View File
@@ -39,45 +39,57 @@
const char *otSysGetRadioUrlHelpString(void)
{
#if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_SPI
#define RADIO_URL_HELP_BUS \
"Radio URL:\n" \
"spinel+spi://${PATH_TO_SPI_DEVICE}?${arguments}\n" \
"arguments:\n" \
" gpio-int-device[=gpio-device-path]\n" \
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
" `I̅N̅T̅` pin. If not specified, `SPI` interface will fall back to\n" \
" polling, which is inefficient.\n" \
" gpio-int-line[=line-offset]\n" \
" The offset index of `I̅N̅T̅` pin for the associated GPIO device.\n" \
" If not specified, `SPI` interface will fall back to polling,\n" \
" which is inefficient.\n" \
" gpio-reset-dev[=gpio-device-path]\n" \
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
" `R̅E̅S̅` pin.\n" \
" gpio-reset-line[=line-offset]" \
" The offset index of `R̅E̅S̅` pin for the associated GPIO device.\n" \
" spi-mode[=mode] Specify the SPI mode to use (0-3).\n" \
" spi-speed[=hertz] Specify the SPI speed in hertz.\n" \
" spi-cs-delay[=usec] Specify the delay after C̅S̅ assertion, in µsec.\n" \
" spi-reset-delay[=ms] Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds.\n" \
" spi-align-allowance[=n] Specify the maximum number of 0xFF bytes to clip from start of\n" \
" MISO frame. Max value is 16.\n" \
" spi-small-packet=[n] Specify the smallest packet we can receive in a single transaction.\n" \
" (larger packets will require two transactions). Default value is 32.\n"
#define OT_RADIO_URL_HELP_BUS \
" spinel+spi://${PATH_TO_SPI_DEVICE}?${Parameters}\n" \
"Parameters:\n" \
" gpio-int-device[=gpio-device-path]\n" \
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
" `I̅N̅T̅` pin. If not specified, `SPI` interface will fall back to\n" \
" polling, which is inefficient.\n" \
" gpio-int-line[=line-offset]\n" \
" The offset index of `I̅N̅T̅` pin for the associated GPIO device.\n" \
" If not specified, `SPI` interface will fall back to polling,\n" \
" which is inefficient.\n" \
" gpio-reset-dev[=gpio-device-path]\n" \
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
" `R̅E̅S̅` pin.\n" \
" gpio-reset-line[=line-offset]" \
" The offset index of `R̅E̅S̅` pin for the associated GPIO device.\n" \
" spi-mode[=mode] Specify the SPI mode to use (0-3).\n" \
" spi-speed[=hertz] Specify the SPI speed in hertz.\n" \
" spi-cs-delay[=usec] Specify the delay after C̅S̅ assertion, in µsec.\n" \
" spi-reset-delay[=ms] Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds.\n" \
" spi-align-allowance[=n] Specify the maximum number of 0xFF bytes to clip from start of\n" \
" MISO frame. Max value is 16.\n" \
" spi-small-packet=[n] Specify the smallest packet we can receive in a single transaction.\n" \
" (larger packets will require two transactions). Default value is 32.\n"
#else
#define RADIO_URL_HELP_BUS \
"Radio URL:\n" \
"spinel+hdlc+uart://${PATH_TO_UART_DEVICE}?${arguments} for real uart device\n" \
"spinel+hdlc+fortpty://${PATH_TO_UART_DEVICE}?${arguments} for forking a pty subprocess.\n" \
"arguments:\n" \
" uart-parity[=even|odd] Uart parity config, optional.\n" \
" uart-stop[=number-of-bits] Uart stop bit, default is 1.\n" \
" baudrate[=baudrate] Uart baud rate, default is 115200.\n" \
" arg[=argument string] Command line arguments for subprocess, can be repeated.\n"
#define OT_RADIO_URL_HELP_BUS \
" spinel+hdlc+uart://${PATH_TO_UART_DEVICE}?${Parameters} for real uart device\n" \
" spinel+hdlc+fortpty://${PATH_TO_UART_DEVICE}?${Parameters} for forking a pty subprocess.\n" \
"Parameters:\n" \
" uart-parity[=even|odd] Uart parity config, optional.\n" \
" uart-stop[=number-of-bits] Uart stop bit, default is 1.\n" \
" uart-baudrate[=baudrate] Uart baud rate, default is 115200.\n" \
" forkpty-arg[=argument string] Command line arguments for subprocess, can be repeated.\n"
#endif // OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_SPI
#if OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
#define OT_RADIO_URL_HELP_MAX_POWER_TABLE \
" max-power-table Max power for channels in ascending order separated by commas,\n" \
" If the number of values is less than that of supported channels,\n" \
" the last value will be applied to all remaining channels.\n" \
" Special value 0x7f disables a channel.\n"
#else
#define OT_RADIO_URL_HELP_MAX_POWER_TABLE
#endif
return RADIO_URL_HELP_BUS " no-reset Skip resetting the radio device.\n"
" ncp-dataset Retrieve dataset from ncp.\n"
" max-power-table Max power table for each channel, splitted by comma.\n";
return "RadioURL:\n" OT_RADIO_URL_HELP_BUS OT_RADIO_URL_HELP_MAX_POWER_TABLE
" no-reset Do not send Spinel reset command to RCP on initialization.\n"
" ncp-dataset Retrieve dataset from ncp.\n";
}
namespace ot {
+2 -4
View File
@@ -34,12 +34,10 @@
#include <openthread/openthread-system.h>
extern "C" {
typedef struct otPosixRadioArguments
struct otPosixRadioArguments
{
const char *mPath; ///< The path to the executable or device
} otPosixRadioArguments;
}
};
namespace ot {
namespace Posix {
+1 -1
View File
@@ -53,7 +53,7 @@ otInstance *otSysInit(otPlatformConfig *aPlatformConfig)
ot::Posix::Arguments args(aPlatformConfig->mRadioUrl);
#if OPENTHREAD_POSIX_VIRTUAL_TIME
virtualTimeInit(static_cast<uint16_t>(atoi(args.GetValue("arg"))));
virtualTimeInit(static_cast<uint16_t>(atoi(args.GetValue("forkpty-arg"))));
#endif
VerifyOrDie(args.GetPath() != NULL, OT_EXIT_INVALID_ARGUMENTS);
+1 -1
View File
@@ -27,7 +27,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?arg=1"
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1"
set timeout 1
expect_after {
timeout { exit 1 }
@@ -28,7 +28,7 @@
#
# allows 11-25 and forbidden 26
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?max-power-table=11,12,13,14,15,16,17,18,19,20,21,22,23,24,-1,0x7f&arg=1"
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?max-power-table=11,12,13,14,15,16,17,18,19,20,21,22,23,24,-1,0x7f&forkpty-arg=1"
set timeout 1
expect_after {
timeout { exit 1 }
@@ -42,7 +42,7 @@ expect "Done"
send "\x04"
expect eof
# allows all channels by default
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?arg=1"
spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1"
set timeout 1
expect_after {
timeout { exit 1 }
+8 -5
View File
@@ -108,8 +108,10 @@ class Node:
cmd = '%s/examples/apps/cli/ot-cli-%s' % (srcdir, mode)
if 'RADIO_DEVICE' in os.environ:
cmd += ' -v spinel+hdlc+uart://%s?arg=%d' % (
cmd += ' -v spinel+hdlc+uart://%s?forkpty-arg=%d' % (
os.environ['RADIO_DEVICE'], nodeid)
else:
cmd += ' %d' % nodeid
# Load Thread 1.1 node when testing Thread 1.2 scenarios for interoperability
elif self.version == '1.1':
@@ -121,10 +123,11 @@ class Node:
cmd = '%s/examples/apps/cli/ot-cli-%s' % (srcdir, mode)
if 'RADIO_DEVICE_1_1' in os.environ:
cmd += ' -v spinel+hdlc+uart://%s?arg=%d' % (
cmd += ' -v spinel+hdlc+uart://%s?forkpty-arg=%d' % (
os.environ['RADIO_DEVICE_1_1'], nodeid)
else:
cmd += ' %d' % nodeid
cmd += ' %d' % nodeid
print("%s" % cmd)
self.pexpect = pexpect.popen_spawn.PopenSpawn(cmd, timeout=4)
@@ -148,7 +151,7 @@ class Node:
# If Thread version of node matches the testing environment version.
if self.version == self.env_version:
if 'RADIO_DEVICE' in os.environ:
args = ' spinel+hdlc+uart://%s?arg=%d' % (
args = ' spinel+hdlc+uart://%s?forkpty-arg=%d' % (
os.environ['RADIO_DEVICE'], nodeid)
else:
args = ''
@@ -187,7 +190,7 @@ class Node:
# Load Thread 1.1 node when testing Thread 1.2 scenarios for interoperability.
elif self.version == '1.1':
if 'RADIO_DEVICE_1_1' in os.environ:
args = ' spinel+hdlc+uart://%s?arg=%d' % (
args = ' spinel+hdlc+uart://%s?forkpty-arg=%d' % (
os.environ['RADIO_DEVICE_1_1'], nodeid)
else:
args = ''
+1 -1
View File
@@ -330,7 +330,7 @@ class Node(object):
self._use_posix_with_rcp = False
if self._use_posix_with_rcp:
ncp_socket_path = 'system:{} -s {} spinel+hdlc+uart://{}?arg={}'.format(
ncp_socket_path = 'system:{} -s {} spinel+hdlc+uart://{}?forkpty-arg={}'.format(
self._OT_NCP_FTD_POSIX, self._SPEED_UP_FACTOR, self._OT_RCP,
index)
else: