1 /*
2 * Copyright 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdint.h>
9 #include <inttypes.h>
10 #include <limits.h>
11 #include <stddef.h>
12 #include "bs_handbrake_args.h"
13 #include "bs_tracing.h"
14 #include "bs_oswrap.h"
15
16 char executable_name[] = "bs_device_handbrake";
component_print_post_help()17 void component_print_post_help(){
18 fprintf(stdout,
19 "\nThis device slows down a simulation close to a ratio of the real time\n"
20 "By default it will slow it down to real time speed\n"
21 "The ratio between simulation time and real time can be set with -r=<real_time_ratio>\n"
22 "\n"
23 "Note1: This device actually _stalls_ the simulation every <poke_period>.\n"
24 "\n"
25 "Note2: Poking incurres in quite a lot of overhead, it will be difficult \n"
26 "to keep realtimeness if the poking is 2ms or less.\n"
27 "\n"
28 "Note3: The simulation will run for one poke period before the handbrake starts.\n"
29 "So expect to see simulations to last approx. 1 poke period less than specified\n"
30 "\n\n");
31 }
32
33 handbrake_args_t *args_g;
34
cmd_trace_lvl_found(char * argv,int offset)35 static void cmd_trace_lvl_found(char * argv, int offset){
36 bs_trace_set_level(args_g->verb);
37 }
38
cmd_gdev_nbr_found(char * argv,int offset)39 static void cmd_gdev_nbr_found(char * argv, int offset){
40 bs_trace_set_prefix_dev(args_g->global_device_nbr);
41 }
42
43 static double poke_period;
cmd_poke_period_found(char * argv,int offset)44 static void cmd_poke_period_found(char * argv, int offset){
45 args_g->poke_period = poke_period;
46 }
47
48 /**
49 * Check the arguments provided in the command line: set args based on it or
50 * defaults, and check they are correct
51 */
bs_handbrake_argparse(int argc,char * argv[],handbrake_args_t * args)52 void bs_handbrake_argparse(int argc, char *argv[], handbrake_args_t *args)
53 {
54
55 args_g = args;
56 bs_args_struct_t args_struct[] = {
57 BS_BASIC_DEVICE_2G4_FAKE_OPTIONS_ARG_STRUCT,
58 { false, false , false, "p", "poke_period", 'f', (void*)&poke_period, cmd_poke_period_found, "Period in which the simulation will be stalled (50e3 =50ms)"},
59 { false, false , false, "r", "real_time_ratio", 'f', (void*)&(args->real_time_ratio),NULL, "Real timeness ratio (1); < 1: slower than real time; > 1: faster than real time"},
60 ARG_TABLE_ENDMARKER
61 };
62
63 bs_args_typical_dev_set_defaults((bs_basic_dev_args_t *)args, args_struct);
64 args->poke_period = 50e3;
65 args->real_time_ratio = 1.0;
66 static char default_phy[] ="2G4";
67
68 bs_args_parse_cmd_line(argc, argv, args_struct);
69
70 bs_args_typical_dev_post_check((bs_basic_dev_args_t *)args, args_struct, default_phy);
71 }
72