-
Notifications
You must be signed in to change notification settings - Fork 3
/
RigThread.cpp
116 lines (94 loc) · 2.78 KB
/
RigThread.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "SoapyAudio.hpp"
#ifdef USE_HAMLIB
RigThread::RigThread() {
terminated.store(true);
}
RigThread::~RigThread() {
}
#ifdef __APPLE__
void *RigThread::threadMain() {
terminated.store(false);
run();
return this;
};
void *RigThread::pthread_helper(void *context) {
return ((RigThread *) context)->threadMain();
};
#else
void RigThread::threadMain() {
terminated.store(false);
run();
};
#endif
void RigThread::setup(rig_model_t rig_model, std::string rig_file, int serial_rate) {
rigModel = rig_model;
rigFile = rig_file;
serialRate = serial_rate;
};
void RigThread::run() {
int retcode;
SoapySDR_log(SOAPY_SDR_DEBUG, "Rig thread starting.");
rig = rig_init(rigModel);
if (rig == NULL) {
SoapySDR_log(SOAPY_SDR_ERROR, "Rig failed to init.");
terminated.store(true);
return;
}
//provide HAMLIB_FILPATHLEN when building against Hamlib < 4.2
#ifndef HAMLIB_FILPATHLEN
#define HAMLIB_FILPATHLEN FILPATHLEN
#endif
strncpy(rig->state.rigport.pathname, rigFile.c_str(), HAMLIB_FILPATHLEN - 1);
if (serialRate > 0) // bypass for rate 0 used for USB controlled radios
rig->state.rigport.parm.serial.rate = serialRate;
retcode = rig_open(rig);
if (retcode != 0) {
char s[BUFSIZ];
snprintf(s, BUFSIZ, "Rig failed to open, rig: %d rig_rate: %d "
"rig_port: %s error: %s.",
rigModel, serialRate, rigFile.c_str(), rigerror(retcode));
SoapySDR_log(SOAPY_SDR_ERROR, s);
terminated.store(true);
return;
}
char *info_buf = (char *)rig_get_info(rig);
if (info_buf != nullptr) {
SoapySDR_logf(SOAPY_SDR_DEBUG, "Rig Info: %s", info_buf);
}
while (!terminated.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(150));
if (freqChanged.load()) {
rig_get_freq(rig, RIG_VFO_CURR, &freq);
if (freq != newFreq) {
freq = newFreq;
rig_set_freq(rig, RIG_VFO_CURR, freq);
SoapySDR_logf(SOAPY_SDR_DEBUG, "Set Rig Freq: %f", newFreq);
}
freqChanged.store(false);
} else {
rig_get_freq(rig, RIG_VFO_CURR, &freq);
}
SoapySDR_logf(SOAPY_SDR_DEBUG, "Rig Freq: %f", freq);
}
rig_close(rig);
rig_cleanup(rig);
SoapySDR_log(SOAPY_SDR_DEBUG, "Rig thread exiting.");
};
freq_t RigThread::getFrequency() {
if (freqChanged.load()) {
return newFreq;
} else {
return freq;
}
}
void RigThread::setFrequency(freq_t new_freq) {
newFreq = new_freq;
freqChanged.store(true);
}
void RigThread::terminate() {
terminated.store(true);
};
bool RigThread::isTerminated() {
return terminated.load();
}
#endif