1 /*
2 * Copyright 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "channel_multiatt_args.h"
7 #include "bs_tracing.h"
8 #include "bs_oswrap.h"
9 #include "bs_cmd_line_typical.h"
10
11 static char library_name[] = "Multi attenautor 2G4 channel";
12
component_print_post_help()13 void component_print_post_help() {
14 fprintf(stdout,"This is a non realistic channel model.\n"
15 "It models NxN independent paths each with a configurable attenuation\n"
16 "This attenuation can also be configured to change over time\n\n"
17 "Note that parameters are processed from left to right and can be overriden\n\n"
18 "For more information on the format of <att_matrix_file> and \n"
19 "<att_file> please check: docs/README.txt\n"
20 );
21 }
22
23 ch_multiatt_args_t *args_g;
24
cmd_att_found(char * argv,int offset)25 void cmd_att_found(char * argv, int offset) {
26 if ((args_g->att < -100) || (args_g->att > 100)) {
27 bs_trace_error("channel: cmdarg: attenuation can only be between -100 and 100dB (%lf)\n", args_g->att);
28 }
29 }
cmd_attextra_found(char * argv,int offset)30 void cmd_attextra_found(char * argv, int offset) {
31 if ((args_g->attextra < -100) || (args_g->attextra > 100)) {
32 bs_trace_error("channel: cmdarg: extra attenuation can only be between -100 and 100dB (%lf)\n", args_g->attextra);
33 }
34 }
35 /**
36 * Check the arguments provided in the command line: set args based on it
37 * or defaults, and check they are correct
38 */
channel_multiatt_argparse(int argc,char * argv[],ch_multiatt_args_t * args)39 void channel_multiatt_argparse(int argc, char *argv[], ch_multiatt_args_t *args) {
40 args_g = args;
41 bs_args_struct_t args_struct[] = {
42 /*manual,mandatory,switch,option, name , type, destination, callback, , description*/
43 { false, false, false, "at" ,"att", 'f', (void*)&args->att, cmd_att_found, "default attenuation in dB, used in all NxN paths if <att_matrix_file> is not provided Default: 60dB"},
44 { false, false, false, "atextra","atextra", 'f', (void*)&args->attextra, cmd_attextra_found, "Extra attenuation to be added to all paths (even if <att_matrix_file> is provided)"},
45 { false, false, false, "file","att_matrix_file", 's',(void*)&args->matrix_file_name, NULL, "File containing the attenuation for each NxN path"},
46 ARG_TABLE_ENDMARKER
47 };
48
49 args->att = 60;
50 args->attextra = 0;
51 args->matrix_file_name = NULL;
52
53 char trace_prefix[50]; //it will not be used as soon as we get out of this function
54 snprintf(trace_prefix,50, "channel: (multiatt) ");
55
56 bs_args_override_exe_name(library_name);
57 bs_args_set_trace_prefix(trace_prefix);
58 bs_args_parse_all_cmd_line(argc, argv, args_struct);
59 }
60