diff --git a/script/check-ncp-rcp-migrate b/script/check-ncp-rcp-migrate index c0696891c..a52836d4c 100755 --- a/script/check-ncp-rcp-migrate +++ b/script/check-ncp-rcp-migrate @@ -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 < #include #include +#include #include #include #include @@ -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 '?': diff --git a/src/posix/platform/hdlc_interface.cpp b/src/posix/platform/hdlc_interface.cpp index c9a3c654f..0d3f8deb8 100644 --- a/src/posix/platform/hdlc_interface.cpp +++ b/src/posix/platform/hdlc_interface.cpp @@ -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(atoi(aArguments.GetValue("baudrate"))); } diff --git a/src/posix/platform/include/openthread/openthread-system.h b/src/posix/platform/include/openthread/openthread-system.h index be5bc08af..fcb24eb2a 100644 --- a/src/posix/platform/include/openthread/openthread-system.h +++ b/src/posix/platform/include/openthread/openthread-system.h @@ -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. * diff --git a/src/posix/platform/radio_url.cpp b/src/posix/platform/radio_url.cpp index d6d73e0e4..c75892227 100644 --- a/src/posix/platform/radio_url.cpp +++ b/src/posix/platform/radio_url.cpp @@ -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 { diff --git a/src/posix/platform/radio_url.hpp b/src/posix/platform/radio_url.hpp index 998aad3c8..f9c0aa08a 100644 --- a/src/posix/platform/radio_url.hpp +++ b/src/posix/platform/radio_url.hpp @@ -34,12 +34,10 @@ #include -extern "C" { -typedef struct otPosixRadioArguments +struct otPosixRadioArguments { const char *mPath; ///< The path to the executable or device -} otPosixRadioArguments; -} +}; namespace ot { namespace Posix { diff --git a/src/posix/platform/system.cpp b/src/posix/platform/system.cpp index a59d76bf9..8bdc6b263 100644 --- a/src/posix/platform/system.cpp +++ b/src/posix/platform/system.cpp @@ -53,7 +53,7 @@ otInstance *otSysInit(otPlatformConfig *aPlatformConfig) ot::Posix::Arguments args(aPlatformConfig->mRadioUrl); #if OPENTHREAD_POSIX_VIRTUAL_TIME - virtualTimeInit(static_cast(atoi(args.GetValue("arg")))); + virtualTimeInit(static_cast(atoi(args.GetValue("forkpty-arg")))); #endif VerifyOrDie(args.GetPath() != NULL, OT_EXIT_INVALID_ARGUMENTS); diff --git a/tests/scripts/expect/posix-diag-rcp.exp b/tests/scripts/expect/posix-diag-rcp.exp index 5a83950b2..2b26ee32c 100755 --- a/tests/scripts/expect/posix-diag-rcp.exp +++ b/tests/scripts/expect/posix-diag-rcp.exp @@ -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 } diff --git a/tests/scripts/expect/posix-max-power-table.exp b/tests/scripts/expect/posix-max-power-table.exp index e25ec300f..6971830a9 100755 --- a/tests/scripts/expect/posix-max-power-table.exp +++ b/tests/scripts/expect/posix-max-power-table.exp @@ -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 } diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index 4ed5403f2..5cceea7ef 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -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 = '' diff --git a/tests/toranj/wpan.py b/tests/toranj/wpan.py index 95f3f0ba1..6c72c84ae 100644 --- a/tests/toranj/wpan.py +++ b/tests/toranj/wpan.py @@ -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: