-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathsdr.c
99 lines (82 loc) · 2.41 KB
/
sdr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* multi-sdr-gps-sim generates a IQ data stream on-the-fly to simulate a
* GPS L1 baseband signal using a SDR platform like HackRF or ADLAM-Pluto.
*
* This file is part of the Github project at
* https://github.com/mictronics/multi-sdr-gps-sim.git
*
* Copyright © 2021 Mictronics
* Distributed under the MIT License.
*
*/
#include "gui.h"
#include "sdr_hackrf.h"
#include "sdr_iqfile.h"
#include "sdr_pluto.h"
#include "sdr.h"
static int no_init(void);
static void no_close(void);
static int no_run(void);
static int no_set_gain(const int);
typedef struct {
int (*init)();
void (*close)();
int (*run)();
int (*set_gain)(const int);
const char *name;
sdr_type_t sdr_type;
} sdr_handler;
static sdr_type_t current_type = SDR_NONE;
static sdr_handler sdr_handlers[] = {
{ no_init, no_close, no_run, no_set_gain, "none", SDR_NONE},
{ sdr_iqfile_init, sdr_iqfile_close, sdr_iqfile_run, no_set_gain, "iqfile", SDR_IQFILE},
#ifdef ENABLE_HACKRFSDR
{ sdr_hackrf_init, sdr_hackrf_close, sdr_hackrf_run, sdr_hackrf_set_gain, "hackrf", SDR_HACKRF},
#endif
#ifdef ENABLE_PLUTOSDR
{ sdr_pluto_init, sdr_pluto_close, sdr_pluto_run, sdr_pluto_set_gain, "plutosdr", SDR_PLUTOSDR},
#endif
{ NULL, NULL, NULL, NULL, NULL, SDR_NONE} /* must come last */
};
static int no_init() {
gui_status_wprintw(RED, "SDR type not recognized; supported SDR types are:\n");
for (int i = 0; sdr_handlers[i].name; ++i) {
gui_status_wprintw(RED, " %s\n", sdr_handlers[i].name);
}
return -1;
}
static void no_close() {
}
static int no_run() {
return -1;
}
static int no_set_gain(const int gain) {
NOTUSED(gain);
return -100;
}
static sdr_handler *current_handler(void) {
for (int i = 0; sdr_handlers[i].name; ++i) {
if (current_type == sdr_handlers[i].sdr_type) {
return &sdr_handlers[i];
}
}
return &sdr_handlers[0];
}
int sdr_init(simulator_t *simulator) {
for (int i = 0; sdr_handlers[i].name; ++i) {
if (!strcasecmp(sdr_handlers[i].name, simulator->sdr_name)) {
current_type = sdr_handlers[i].sdr_type;
simulator->sdr_type = sdr_handlers[i].sdr_type;
}
}
return current_handler()->init(simulator);
}
void sdr_close(void) {
current_handler()->close();
}
int sdr_run(void) {
return current_handler()->run();
}
int sdr_set_gain(const int gain) {
return current_handler()->set_gain(gain);
}