source: mainline/uspace/app/tmon/main.c@ acb9aa7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since acb9aa7 was 00d23a2, checked in by Petr Mánek <petr.manek@…>, 8 years ago

tmon: finalize usage string

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[81ee1009]1/*
2 * Copyright (c) 2017 Petr Manek
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup tmon
30 * @{
31 */
32/**
33 * @file
34 * USB transfer debugging.
35 */
36
37#include <stdio.h>
[73b0773]38#include "commands.h"
[81ee1009]39
[00d23a2]40#define NAME "tmon"
41#define INDENT " "
[81ee1009]42
[00d23a2]43typedef struct tmon_cmd {
[73b0773]44 const char *name;
[25935f1e]45 const char *description;
[73b0773]46 int (*action)(int, char **);
[00d23a2]47} tmon_cmd_t;
[64d138b]48
[00d23a2]49static tmon_cmd_t commands[] = {
[73b0773]50 {
51 .name = "list",
[25935f1e]52 .description = "Print a list of connected diagnostic devices.",
[73b0773]53 .action = tmon_list,
54 },
[e9d600c2]55 {
[2986763]56 .name = "test-intr-in",
[00d23a2]57 .description = "Read from interrupt endpoint as fast as possible.",
[2986763]58 .action = tmon_burst_intr_in,
[e9d600c2]59 },
60 {
[2986763]61 .name = "test-intr-out",
[00d23a2]62 .description = "Write to interrupt endpoint as fast as possible.",
[2986763]63 .action = tmon_burst_intr_out,
[e9d600c2]64 },
[2bd04b2]65 {
[2986763]66 .name = "test-bulk-in",
[00d23a2]67 .description = "Read from bulk endpoint as fast as possible.",
[2986763]68 .action = tmon_burst_bulk_in,
[25935f1e]69 },
70 {
[2986763]71 .name = "test-bulk-out",
[00d23a2]72 .description = "Write to bulk endpoint as fast as possible.",
[2986763]73 .action = tmon_burst_bulk_out,
[25935f1e]74 },
[ff16da5f]75 {
[2986763]76 .name = "test-isoch-in",
[00d23a2]77 .description = "Read from isochronous endpoint as fast as possible.",
[2986763]78 .action = tmon_burst_isoch_in,
[ff16da5f]79 },
80 {
[2986763]81 .name = "test-isoch-out",
[00d23a2]82 .description = "Write to isochronous endpoint as fast as possible.",
[2986763]83 .action = tmon_burst_isoch_out,
[ff16da5f]84 },
[00d23a2]85 { /* NULL-terminated */ }
86};
87
88typedef struct tmon_opt {
89 const char *long_name;
90 char short_name;
91 const char *description;
92} tmon_opt_t;
93
94static tmon_opt_t options[] = {
[73b0773]95 {
[00d23a2]96 .long_name = "cycles",
97 .short_name = 'n',
98 .description = "Set the number of read/write cycles."
99 },
100 {
101 .long_name = "size",
102 .short_name = 's',
103 .description = "Set the data size transferred in a single cycle."
104 },
105 { /* NULL-terminated */ }
[73b0773]106};
[64d138b]107
[25935f1e]108static void print_usage(char *app_name)
109{
[00d23a2]110 puts(NAME ": benchmark USB diagnostic device\n\n");
111 printf("Usage: %s command [device] [options]\n\n", app_name);
[25935f1e]112
113 for (int i = 0; commands[i].name; ++i) {
[00d23a2]114 printf(INDENT "%s - %s\n", commands[i].name, commands[i].description);
[25935f1e]115 }
116
[00d23a2]117 puts("\n");
118 for (int i = 0; options[i].long_name; ++i) {
119 printf(INDENT "-%c --%s\n" INDENT INDENT "%s\n", options[i].short_name, options[i].long_name, options[i].description);
120 }
[25935f1e]121
[00d23a2]122 puts("\nIf no device is specified, the first device is used provided that it is the only one connected. Otherwise, the command fails.\n\n");
[25935f1e]123}
124
[73b0773]125int main(int argc, char *argv[])
[64d138b]126{
[73b0773]127 // Find a command to execute.
[00d23a2]128 tmon_cmd_t *cmd = NULL;
[73b0773]129 for (int i = 0; argc > 1 && commands[i].name; ++i) {
130 if (str_cmp(argv[1], commands[i].name) == 0) {
131 cmd = commands + i;
132 break;
133 }
[64d138b]134 }
135
[73b0773]136 if (!cmd) {
[81ee1009]137 print_usage(argv[0]);
138 return -1;
139 }
140
[119a794]141 return cmd->action(argc - 1, argv + 1);
[81ee1009]142}
143
144/** @}
145 */
Note: See TracBrowser for help on using the repository browser.