[tuxdroid-svn] r965 - software_suite_v2/middleware/tuxdriver/trunk/test
Status: Beta
Brought to you by:
ks156
From: eFfeM <c2m...@c2...> - 2008-04-19 10:25:13
|
Author: eFfeM Date: 2008-04-19 12:25:11 +0200 (Sat, 19 Apr 2008) New Revision: 965 Modified: software_suite_v2/middleware/tuxdriver/trunk/test/main.c Log: added options to control level of output; added usage() function Modified: software_suite_v2/middleware/tuxdriver/trunk/test/main.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/test/main.c 2008-04-17 09:12:05 UTC (rev 964) +++ software_suite_v2/middleware/tuxdriver/trunk/test/main.c 2008-04-19 10:25:11 UTC (rev 965) @@ -18,16 +18,21 @@ * 02111-1307, USA. */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> -#include <string.h> -#include <errno.h> +#include <unistd.h> #ifdef WIN32 # include <windows.h> #endif + #include "../include/tux_driver.h" +static int print_descriptor = 0; +static int print_status = 0; + /** * */ @@ -128,22 +133,35 @@ } } - /* Tuxdroid descriptor is complete */ - if (!strcmp(tokens[0], "descriptor_complete")) - /* TuxDrv_GetDescriptor */ - if (!strcmp(tokens[2], "True")) { - TuxDrv_GetDescriptor(&tux_desc); - printf("%s\n", tux_desc.firmwares.package->version_string); - printf("%s\n", tux_desc.firmwares.tuxcore->version_string); - printf("%s\n", tux_desc.firmwares.tuxaudio->version_string); - printf("%s\n", tux_desc.firmwares.tuxrf->version_string); - printf("%s\n", tux_desc.firmwares.fuxrf->version_string); - printf("%s\n", tux_desc.firmwares.fuxusb->version_string); - printf("%s\n", tux_desc.driver.version_string); + if (print_descriptor) + { + /* Tuxdroid descriptor is complete */ + if (!strcmp(tokens[0], "descriptor_complete")) + { + /* TuxDrv_GetDescriptor */ + if (!strcmp(tokens[2], "True")) + { + TuxDrv_GetDescriptor(&tux_desc); + printf("%s\n", tux_desc.firmwares.package->version_string); + printf("%s\n", tux_desc.firmwares.tuxcore->version_string); + printf("%s\n", tux_desc.firmwares.tuxaudio->version_string); + printf("%s\n", tux_desc.firmwares.tuxrf->version_string); + printf("%s\n", tux_desc.firmwares.fuxrf->version_string); + printf("%s\n", tux_desc.firmwares.fuxusb->version_string); + printf("%s\n", tux_desc.driver.version_string); + } } + } - /* Print status string */ - printf("%s\n", status); + if (print_status) + { + + /* Print status string */ + if ((print_status > 1) || (strcmp(tokens[0], "light_level"))) + { + printf("%s\n", status); + } + } } /** @@ -154,6 +172,15 @@ { } +static void +usage(char *progname) +{ + fprintf(stderr, "Usage: %s [-d -s -S]\n", progname); + fprintf(stderr, " -d: prints descriptor\n"); + fprintf(stderr, " -s: prints status messages except light_senser\n"); + fprintf(stderr, " -S: prints all status messages\n"); +} + /** * Main function. */ @@ -162,12 +189,40 @@ int argc; char* argv[]; { + char ch; + char *progname = argv[0]; + + // option names are to be reconsidered + while ((ch = getopt(argc, argv, "dsS")) != -1) + { + switch (ch) { + case 'd': + print_descriptor = 1; + break; + case 's': + print_status = 1; + break; + case 'S': + print_status = 2; + break; + case '?': + default: + usage(progname); + } + } + argc -= optind; + argv += optind; + #ifdef WIN32 if (TuxDrv_InitDll("../win32/tux_driver.dll") == NULL) + { return -1; + } #else if (TuxDrv_InitDll("../unix/tux_driver.so") == NULL) + { return -1; + } #endif TuxDrv_SetLogLevel(LOG_LEVEL_ERROR); TuxDrv_SetLogTarget(LOG_TARGET_SHELL); |