1 /*
2 * Copyright 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <stdlib.h>
7 #include "bs_pause_args.h"
8 #include "bs_tracing.h"
9 #include "bs_utils.h"
10
11 char executable_name[] = "bs_device_pause_simu";
12
component_print_post_help()13 void component_print_post_help(){
14 fprintf(stdout,"\n"
15 "This device pauses the simulation once for each element of the\n"
16 "list provided from command line, while it awaits some user input\n\n"
17 );
18 }
19
20 pause_args_t *args_g;
21
cmd_trace_lvl_found(char * argv,int offset)22 void cmd_trace_lvl_found(char * argv, int offset){
23 bs_trace_set_level(args_g->verb);
24 }
25
cmd_gdev_nbr_found(char * argv,int offset)26 void cmd_gdev_nbr_found(char * argv, int offset){
27 bs_trace_set_prefix_dev(args_g->global_device_nbr);
28 }
29
30 /**
31 * Check the arguments provided in the command line: set args based on it or
32 * defaults, and check they are correct
33 */
bs_pause_argparse(int argc,char * argv[],pause_args_t * args)34 void bs_pause_argparse(int argc, char *argv[], pause_args_t *args)
35 {
36 args_g = args;
37 bs_args_struct_t args_struct[] = {
38 BS_BASIC_DEVICE_2G4_FAKE_OPTIONS_ARG_STRUCT,
39 { true, false , false, "times", "time", 'l', (void*)NULL, NULL, "Times at which the simulation will be stalled (up to " STR(MAX_NBR_PAUSES) ")"},
40 ARG_TABLE_ENDMARKER
41 };
42
43 bs_args_typical_dev_set_defaults((bs_basic_dev_args_t *)args, args_struct);
44 args->n_times = 0;
45 static char default_phy[] ="2G4";
46
47 for (int i=1; i<argc; i++){
48 int offset;
49 if ( !bs_args_parse_one_arg(argv[i], args_struct) ){
50
51 if ( ( offset = bs_is_option(argv[i], "times", 0) ) ) {
52 double time;
53 while ( ( i + 1 < argc ) && ( argv[i+1][0] != '-' ) ) {
54 i += 1;
55 if ( sscanf(argv[i],"%lf",&time) != 1 ){
56 bs_trace_error_line("Could not parse time entry nbr %i (%s)\n", args->n_times+1, argv[i]);
57 }
58 if (args->n_times >= MAX_NBR_PAUSES) {
59 bs_trace_error_line("Too many pauses. Maximum is "STR(MAX_NBR_PAUSES)"\n");
60 }
61 args->times[args->n_times] = time;
62 bs_trace_raw(9,"added time[%i] = %"PRItime" to list\n", args->n_times, args->times[args->n_times]);
63 args->n_times += 1;
64 }
65 } else {
66 bs_args_print_switches_help(args_struct);
67 bs_trace_error_line("Unknown command line switch '%s'\n",argv[i]);
68 }
69 }
70 }
71
72 bs_args_typical_dev_post_check((bs_basic_dev_args_t *)args, args_struct, default_phy);
73 }
74