[radio-url] GetValue once and add missing doc (#5046)

This commit is contained in:
Yakun Xu
2020-06-04 13:21:34 -07:00
committed by GitHub
parent 1d9b705a48
commit 61f24c70fb
3 changed files with 40 additions and 30 deletions
+22 -14
View File
@@ -409,10 +409,8 @@ exit:
int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
{
int fd = -1;
int rval = 0;
const char *parity = aArguments.GetValue("uart-parity");
uint32_t baudrate = 115200;
int fd = -1;
int rval = 0;
fd = open(aFile, O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
if (fd == -1)
@@ -424,9 +422,11 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
if (isatty(fd))
{
struct termios tios;
const char * value;
speed_t speed;
unsigned int speed = 115200;
int stopBit = 1;
int stopBit = 1;
uint32_t baudrate = 115200;
VerifyOrExit((rval = tcgetattr(fd, &tios)) == 0, OT_NOOP);
@@ -434,14 +434,14 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
tios.c_cflag = CS8 | HUPCL | CREAD | CLOCAL;
if (parity)
if ((value = aArguments.GetValue("uart-parity")) != NULL)
{
if (strncmp(parity, "odd", 3) == 0)
if (strncmp(value, "odd", 3) == 0)
{
tios.c_cflag |= PARENB;
tios.c_cflag |= PARODD;
}
else if (strncmp(parity, "even", 4) == 0)
else if (strncmp(value, "even", 4) == 0)
{
tios.c_cflag |= PARENB;
}
@@ -451,9 +451,9 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
}
}
if (aArguments.GetValue("uart-stop"))
if ((value = aArguments.GetValue("uart-stop")) != NULL)
{
stopBit = atoi(aArguments.GetValue("uart-stop"));
stopBit = atoi(value);
}
switch (stopBit)
@@ -469,10 +469,11 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments)
break;
}
if (aArguments.GetValue("uart-baudrate"))
if ((value = aArguments.GetValue("uart-baudrate")))
{
baudrate = static_cast<uint32_t>(atoi(aArguments.GetValue("uart-baudrate")));
baudrate = static_cast<uint32_t>(atoi(value));
}
switch (baudrate)
{
case 9600:
@@ -601,7 +602,14 @@ int HdlcInterface::ForkPty(const char *aCommand, const char *aArguments)
const int kMaxCommand = 255;
char cmd[kMaxCommand];
rval = snprintf(cmd, sizeof(cmd), "exec %s %s", aCommand, aArguments);
if (aArguments == NULL)
{
rval = snprintf(cmd, sizeof(cmd), "exec %s", aCommand);
}
else
{
rval = snprintf(cmd, sizeof(cmd), "exec %s %s", aCommand, aArguments);
}
VerifyOrExit(rval > 0 && static_cast<size_t>(rval) < sizeof(cmd),
fprintf(stderr, "NCP file and configuration is too long!");
rval = -1);
+1
View File
@@ -73,6 +73,7 @@ const char *otSysGetRadioUrlHelpString(void)
" 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" \
" uart-flow-control Enable flow control, disabled by default.\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
+17 -16
View File
@@ -103,6 +103,7 @@ otError SpiInterface::Init(Arguments &aArguments)
uint16_t spiCsDelay = OT_PLATFORM_CONFIG_SPI_DEFAULT_CS_DELAY_US;
uint8_t spiAlignAllowance = OT_PLATFORM_CONFIG_SPI_DEFAULT_ALIGN_ALLOWANCE;
uint8_t spiSmallPacketSize = OT_PLATFORM_CONFIG_SPI_DEFAULT_SMALL_PACKET_SIZE;
const char *value;
spiGpioIntDevice = aArguments.GetValue("gpio-int-device");
spiGpioResetDevice = aArguments.GetValue("gpio-reset-device");
@@ -111,45 +112,45 @@ otError SpiInterface::Init(Arguments &aArguments)
DieNow(OT_EXIT_INVALID_ARGUMENTS);
}
if (aArguments.GetValue("gpio-int-line"))
if ((value = aArguments.GetValue("gpio-int-line")))
{
spiGpioIntLine = static_cast<uint8_t>(atoi(aArguments.GetValue("gpio-int-line")));
spiGpioIntLine = static_cast<uint8_t>(atoi(value));
}
else
{
DieNow(OT_EXIT_INVALID_ARGUMENTS);
}
if (aArguments.GetValue("gpio-reset-line"))
if ((value = aArguments.GetValue("gpio-reset-line")))
{
spiGpioResetLine = static_cast<uint8_t>(atoi(aArguments.GetValue("gpio-reset-line")));
spiGpioResetLine = static_cast<uint8_t>(atoi(value));
}
else
{
DieNow(OT_EXIT_INVALID_ARGUMENTS);
}
if (aArguments.GetValue("spi-mode"))
if ((value = aArguments.GetValue("spi-mode")))
{
spiMode = static_cast<uint8_t>(atoi(aArguments.GetValue("spi-mode")));
spiMode = static_cast<uint8_t>(atoi(value));
}
if (aArguments.GetValue("spi-speed"))
if ((value = aArguments.GetValue("spi-speed")))
{
spiSpeed = static_cast<uint32_t>(atoi(aArguments.GetValue("spi-speed")));
spiSpeed = static_cast<uint32_t>(atoi(value));
}
if (aArguments.GetValue("spi-reset-delay"))
if ((value = aArguments.GetValue("spi-reset-delay")))
{
spiResetDelay = static_cast<uint32_t>(atoi(aArguments.GetValue("spi-reset-delay")));
spiResetDelay = static_cast<uint32_t>(atoi(value));
}
if (aArguments.GetValue("spi-cs-delay"))
if ((value = aArguments.GetValue("spi-cs-delay")))
{
spiCsDelay = static_cast<uint16_t>(atoi(aArguments.GetValue("spi-cs-delay")));
spiCsDelay = static_cast<uint16_t>(atoi(value));
}
if (aArguments.GetValue("spi-align-allowance"))
if ((value = aArguments.GetValue("spi-align-allowance")))
{
spiAlignAllowance = static_cast<uint8_t>(atoi(aArguments.GetValue("spi-align-allowance")));
spiAlignAllowance = static_cast<uint8_t>(atoi(value));
}
if (aArguments.GetValue("spi-small-packet"))
if ((value = aArguments.GetValue("spi-small-packet")))
{
spiSmallPacketSize = static_cast<uint8_t>(atoi(aArguments.GetValue("spi-small-packet")));
spiSmallPacketSize = static_cast<uint8_t>(atoi(value));
}
VerifyOrDie(spiAlignAllowance <= kSpiAlignAllowanceMax, OT_EXIT_FAILURE);