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_tracing.h"
13 #include "bs_oswrap.h"
14 #include "bs_rand_main.h"
15 #include "modem_BLE_simple_args.h"
16 #include "bs_cmd_line_typical.h"
17
18 static char library_name[] = "Modem BLE_simple";
19
modem_print_post_help()20 void modem_print_post_help() {
21 fprintf(stdout,"Simplistic model of a BLE modem\n\n"
22 "This modem model includes the following configurable Rx noise sources:\n"
23 " * Analog noise figure: Noise figure of the analog part (4dB by default)\n"
24 " * Extra noise figure: Extra noise figure that may be introduced after the power\n"
25 " measurements (2dB by default)\n"
26 " * Noise floor: Noise floor of the modem. For example due to the digital dynamic\n"
27 " range. (-35dB by default). This can be seen as a SNR limit\n"
28 "\n"
29 "This modem RSSI measurements include 2 types of errors.\n"
30 " * RSSI_offset: (1) Equivalent to a RSSI production calibration offset. A value\n"
31 " will be drawn during initialization from a N(0, RSSI_offset_std),\n"
32 " and will be constant during runtime and for the whole band\n"
33 " * RSSI measurement noise: (1.5) The error in each RSSI measurement is modeled as a\n"
34 " N(RSSI_offset, RSSI_meas_noisedB_std)\n"
35 );
36 }
37
38 static mo_simple_args_t *args_g;
39 static uint device_nbr_g;
40 static double per;
41
cmd_per_found(char * argv,int offset)42 static void cmd_per_found(char * argv, int offset) {
43 if ((per < 0) || (per > 1)) {
44 bs_trace_error("modem: %i: (BLE_simple) args: PER shall be between 0 and 1 '%s'\n", device_nbr_g, per, argv);
45 }
46 args_g->Sync_prob = (1.0-per)*(double)RAND_PROB_1;
47 bs_trace_raw(9,"modem: %i: (BLE_simple) sync probability (per) set to %u/%u (%e)\n", device_nbr_g, args_g->Sync_prob, RAND_PROB_1, per);
48 }
49
50 /**
51 * Check the arguments provided in the command line: set args based on it
52 * or defaults, and check they are correct
53 */
modem_simple_argparse(int argc,char * argv[],uint d,mo_simple_args_t * args)54 void modem_simple_argparse(int argc, char *argv[], uint d, mo_simple_args_t *args)
55 {
56 args_g = args;
57 device_nbr_g = d;
58 bs_args_struct_t args_struct[] = {
59 /*manual,mandatory,switch,option,name , type, destination, callback, description */
60 { false , false , false, "PER", "per", 'f', (void*)&per, cmd_per_found, "Synchronization packet error rate (note that this is in excess of any synchronization errors due to bit errors"},
61 { false , false , false, "RSSI_offset_std", "RSSI_offset", 'f', (void*)&args->RSSI_offsetdB_std, NULL, "Standard deviation of the device RSSI measurement offset"},
62 { false , false , false, "RSSI_meas_noisedB_std", "RSSI_meas_noise", 'f', (void*)&args->RSSI_meas_noisedB_std, NULL, "Standard deviation of the device RSSI measurement noise"},
63 { false , false , false, "NFAna", "nfig", 'f', (void*)&args->NFigure_ana, NULL, "Noise figure"},
64 { false , false , false, "NFExtra", "nfigext", 'f', (void*)&args->NFigure_extra, NULL, "Extra noise figure up to the digital demodulation"},
65 { false , false , false, "NFloor", "nfloor", 'f', (void*)&args->NFloor_dig, NULL, "Digital noise floor"},
66 ARG_TABLE_ENDMARKER
67 };
68
69 //set defaults:
70 args->Sync_prob = RAND_PROB_1;
71 args->RSSI_offsetdB_std = 1.0;
72 args->RSSI_meas_noisedB_std = 1.5;
73 args->NFigure_ana = 4;
74 args->NFigure_extra = 2;
75 args->NFloor_dig = -35; //35 dB noise floor by default
76
77 char trace_prefix[50]; //this variable won't be used as soon as we get out of this function
78 snprintf(trace_prefix,50, "modem: %i: (simple) ",d);
79
80 bs_args_override_exe_name(library_name);
81 bs_override_post_help(modem_print_post_help);
82 bs_args_set_trace_prefix(trace_prefix);
83 bs_args_parse_all_cmd_line(argc, argv, args_struct);
84 }
85