apps/exmamples/media: Allow choosign the device to be tested via a comman line argument

This commit is contained in:
Sebastien Lorquet 2016-06-01 08:15:10 -06:00 committed by Gregory Nutt
parent 700331ad69
commit 6142ed8e61
3 changed files with 21 additions and 4 deletions

View File

@ -1601,3 +1601,7 @@
Bouteville (2016-05-21).
* apps/canutils/: Rename uavcan to libuavcan. From Paul Alexander
Patience (2016-05-25).
* apps/examples/media: You can now override the default device driver
path by providing an alternal path on the command line. From Sébastien
Lorquet (2016-06-01).

View File

@ -49,6 +49,9 @@ config EXAMPLES_MEDIA_DEVPATH
ret = bchdev_register(/dev/mtdblock<N>, <path-to-character-driver>,
false);
NOTE: This drivr path can be overridden when the application is
executed by providing a differ device path on the 'media' command line.
config EXAMPLES_MEDIA_BLOCKSIZE
int "Block size"
default 512

View File

@ -127,11 +127,12 @@ static void get_blocksize(int fd, FAR struct media_info_s *info)
#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
#else
int media_main(int argc, char *argv[])
int media_main(int argc, FAR char *argv[])
#endif
{
FAR uint8_t *txbuffer;
FAR uint8_t *rxbuffer;
FAR char *devpath;
struct media_info_s info;
ssize_t nwritten;
ssize_t nread;
@ -145,14 +146,23 @@ int media_main(int argc, char *argv[])
/* Open the character driver that wraps the media */
fd = open(CONFIG_EXAMPLES_MEDIA_DEVPATH, O_RDWR);
if (argc < 2)
{
devpath = CONFIG_EXAMPLES_MEDIA_DEVPATH;
}
else
{
devpath = argv[1];
}
fd = open(argv[1], O_RDWR);
if (fd < 0)
{
fprintf(stderr, "ERROR: failed to open %s: %d\n",
CONFIG_EXAMPLES_MEDIA_DEVPATH, errno);
devpath, errno);
return 1;
}
/* Get the block size to use */
get_blocksize(fd, &info);