command: Add command_decode_ptr() helper

Add a helper function to convert from a string buffer passed in the
args[] parameter to an actual pointer.  This avoids all the callers
needing to perfrom pointer manipulation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2020-10-29 23:54:17 -04:00
parent aaf3dc6ac3
commit 473828ca6a
10 changed files with 38 additions and 30 deletions

View File

@@ -101,7 +101,7 @@ command_spi_transfer(uint32_t *args)
uint8_t oid = args[0];
struct spidev_s *spi = spidev_oid_lookup(oid);
uint8_t data_len = args[1];
uint8_t *data = (void*)(size_t)args[2];
uint8_t *data = command_decode_ptr(args[2]);
spidev_transfer(spi, 1, data_len, data);
sendf("spi_transfer_response oid=%c response=%*s", oid, data_len, data);
}
@@ -112,7 +112,7 @@ command_spi_send(uint32_t *args)
{
struct spidev_s *spi = spidev_oid_lookup(args[0]);
uint8_t data_len = args[1];
uint8_t *data = (void*)(size_t)args[2];
uint8_t *data = command_decode_ptr(args[2]);
spidev_transfer(spi, 0, data_len, data);
}
DECL_COMMAND(command_spi_send, "spi_send oid=%c data=%*s");
@@ -137,7 +137,7 @@ command_config_spi_shutdown(uint32_t *args)
args[0], command_config_spi_shutdown, sizeof(*sd) + shutdown_msg_len);
sd->spi = spi;
sd->shutdown_msg_len = shutdown_msg_len;
uint8_t *shutdown_msg = (void*)(size_t)args[3];
uint8_t *shutdown_msg = command_decode_ptr(args[3]);
memcpy(sd->shutdown_msg, shutdown_msg, shutdown_msg_len);
}
DECL_COMMAND(command_config_spi_shutdown,