1 /*
2 * Copyright 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <string.h>
7 #include "bs_tracing.h"
8 #include "bs_pc_2G4.h"
9 #include "bs_types.h"
10 #include "bs_burstint_args.h"
11
12 /**
13 * Generate bursts of interference of a given <type> centered
14 * in a given <center_freq> lasting from <timestart> to <timeend>
15 */
16
17 static bs_time_t offset;
18
offset_time(bs_time_t time)19 static bs_time_t offset_time(bs_time_t time) {
20 bs_time_t phy_time;
21 if (time != TIME_NEVER) {
22 phy_time = (bs_time_t)time + offset;
23 } else {
24 phy_time = TIME_NEVER;
25 }
26 return phy_time;
27 }
28
clean_up()29 static uint8_t clean_up() {
30 bs_trace_raw(8, "Cleaning up\n");
31 p2G4_dev_disconnect_c();
32 return 0;
33 }
34
main(int argc,char * argv[])35 int main(int argc, char *argv[]) {
36 bs_trace_register_cleanup_function(clean_up);
37
38 burstint_args_t args;
39
40 bs_burstint_argsparse(argc, argv, &args);
41 offset = args.start_offset;
42
43 bs_trace_raw(9,"Connecting...\n");
44 p2G4_dev_initcom_c(args.device_nbr, args.s_id, args.p_id, NULL);
45
46 bs_time_t time = 0;
47 p2G4_tx_t tx_s;
48 p2G4_tx_done_t tx_done_s;
49 memset(&tx_s, 0, sizeof(tx_s));
50
51 tx_s.radio_params.modulation = args.type;
52 tx_s.packet_size = 0;
53 tx_s.phy_address = 0;
54 tx_s.radio_params.center_freq = args.center_freq;
55 tx_s.power_level = args.powerdBm;
56 tx_s.abort.abort_time = TIME_NEVER;
57 tx_s.abort.recheck_time = TIME_NEVER;
58
59 for (int i = 0; i < args.n_times_start; i ++) {
60 if (args.times_end[i] <= args.times_start[i]) {
61 bs_trace_error_line("End times need to be bigger than starting times (index %i: %i <= %i)\n",
62 i, args.times_end[i], args.times_start[i]);
63 }
64 if (args.times_start[i] <= time) {
65 bs_trace_error_line("The list of times needs to be ordered (index %i: %i <= %i)\n",
66 i, args.times_start[i], time);
67 }
68
69 time = args.times_start[i];
70 tx_s.start_time = offset_time(args.times_start[i]);
71 tx_s.end_time = offset_time(args.times_end[i]);
72
73 int ret_val = p2G4_dev_req_tx_c_b(&tx_s, NULL, &tx_done_s);
74 if (ret_val) {
75 bs_trace_raw_manual_time(3, time, "The phy disconnected\n");
76 break;
77 }
78
79 time = args.times_end[i];
80 }
81
82 bs_trace_raw(9,"Disconnecting...\n");
83 p2G4_dev_disconnect_c();
84
85 return 0;
86 }
87