1 /*
2  * Copyright 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stdlib.h>
7 #include "bs_time_monitor_args.h"
8 #include "bs_tracing.h"
9 #include "bs_oswrap.h"
10 
11 char executable_name[] = "bs_device_time_monitor";
12 
component_print_post_help()13 void component_print_post_help(){
14   fprintf(stdout,"\n"
15           "This device just connects to a phy and prints the time as\n"
16           "it passes (for ex. if you want to monitor long simulations)\n\n");
17 }
18 
19 time_monitor_args_t *args_g;
20 
cmd_trace_lvl_found(char * argv,int offset)21 static void cmd_trace_lvl_found(char * argv, int offset){
22   bs_trace_set_level(args_g->verb);
23 }
24 
cmd_gdev_nbr_found(char * argv,int offset)25 static void cmd_gdev_nbr_found(char * argv, int offset){
26   bs_trace_set_prefix_dev(args_g->global_device_nbr);
27 }
28 
29 static double interval;
cmd_interval_found(char * argv,int offset)30 static void cmd_interval_found(char * argv, int offset){
31   args_g->interval = interval;
32 }
33 
34 /**
35  * Check the arguments provided in the command line: set args based on it
36  * or defaults, and check they are correct
37  */
bs_time_monitor_argparse(int argc,char * argv[],time_monitor_args_t * args)38 void bs_time_monitor_argparse(int argc, char *argv[], time_monitor_args_t *args)
39 {
40   args_g = args;
41   bs_args_struct_t args_struct[] = {
42       BS_BASIC_DEVICE_2G4_FAKE_OPTIONS_ARG_STRUCT,
43       {false, false , false, "interval", "int", 'f', (void*)&interval, cmd_interval_found, "Monitoring interval, in microseconds"},
44       ARG_TABLE_ENDMARKER
45   };
46 
47   bs_args_typical_dev_set_defaults((bs_basic_dev_args_t *)args, args_struct);
48   args->interval  = 150*1e6;
49   static char default_phy[] ="2G4";
50 
51   bs_args_parse_cmd_line(argc, argv, args_struct);
52 
53   bs_args_typical_dev_post_check((bs_basic_dev_args_t *)args, args_struct, default_phy);
54 }
55