From c0cb64f3166a7c3b3d026369e6de8222a7e49db6 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 11 Oct 2012 13:07:25 -0700 Subject: [PATCH] Add support for TX mode. Add getopt control of RX or TX mode. --- host/usb_test/usb_test.c | 55 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/host/usb_test/usb_test.c b/host/usb_test/usb_test.c index 5ce79244..c984898c 100644 --- a/host/usb_test/usb_test.c +++ b/host/usb_test/usb_test.c @@ -21,7 +21,9 @@ #include #include +#include #include +#include #include #include @@ -156,13 +158,56 @@ struct libusb_transfer** prepare_transfers( return transfers; } +static void usage() { + printf("Usage:\n"); + printf("\tGo fish.\n"); +} + int main(int argc, char** argv) { - if( argc != 2 ) { - printf("Usage: usb_test \n"); - return -1; - } + int opt; + bool receive = false; + bool transmit = false; + const char* path = NULL; - const char* const path = argv[1]; + while( (opt = getopt(argc, argv, "r:t:")) != EOF ) { + switch( opt ) { + case 'r': + receive = true; + path = optarg; + break; + + case 't': + transmit = true; + path = optarg; + break; + + default: + usage(); + return 1; + } + } + + if( transmit == receive ) { + if( transmit == true ) { + fprintf(stderr, "receive and transmit options are mutually exclusive\n"); + } else { + fprintf(stderr, "specify either transmit or receive option\n"); + } + return 1; + } + + if( receive ) { + transceiver_mode = TRANSCEIVER_MODE_RX; + } + + if( transmit ) { + transceiver_mode = TRANSCEIVER_MODE_TX; + } + + if( path == NULL ) { + fprintf(stderr, "specify a path to a file to transmit/receive\n"); + return 1; + } fd = -1; uint_fast8_t endpoint_address = 0;