COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
usrp_lib.h File Reference
Include dependency graph for usrp_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  usrp_handle
 

Macros

#define USRP_BAUD   19200
 
#define USRP_BITS   8
 
#define USRP_PARITY   0
 
#define USRP_STOPBITS   1
 
#define USRP_CHANNEL_A   0
 
#define USRP_CHANNEL_B   1
 
#define USRP_CHANNEL_SWAP   2
 
#define USRP_DATAMODE_OFF   0
 
#define USRP_DATAMODE_ON   1
 
#define USRP_9600MODE_OFF   0
 
#define USRP_9600MODE_ON   1
 
#define USRP_MODE_LSB   0
 
#define USRP_MODE_USB   1
 
#define USRP_MODE_AM   2
 
#define USRP_MODE_CW   3
 
#define USRP_MODE_RTTY   4
 
#define USRP_MODE_FM   5
 
#define USRP_MODE_CWR   7
 
#define USRP_MODE_RTTYR   8
 
#define USRP_MODE_DV   17
 
#define USRP_FILTER_1   1
 
#define USRP_FILTER_2   2
 
#define USRP_FILTER_3   3
 

Functions

int32_t usrp_connect (string device, uint16_t port, usrp_handle &handle)
 
int32_t usrp_disconnect (usrp_handle &handle)
 
int32_t usrp_send (usrp_handle &handle, std::string &data)
 
uint8_t usrp_byte (vector< uint8_t > response)
 
uint8_t usrp_freq2band (double frequency)
 
int32_t usrp_check_address (usrp_handle &handle)
 
int32_t usrp_set_channel (usrp_handle &handle, uint8_t channelnum)
 
int32_t usrp_set_frequency (usrp_handle &handle, double frequency)
 
int32_t usrp_get_frequency (usrp_handle &handle)
 
int32_t usrp_set_freqband (usrp_handle &handle, uint8_t mode)
 
int32_t usrp_get_freqband (usrp_handle &handle)
 
int32_t usrp_set_bandpass (usrp_handle &handle, double bandpass)
 
int32_t usrp_get_bandpass (usrp_handle &handle)
 
int32_t usrp_set_mode (usrp_handle &handle, uint8_t opmode)
 
int32_t usrp_set_mode (usrp_handle &handle, uint8_t opmode, uint8_t filtband)
 
int32_t usrp_get_mode (usrp_handle &handle)
 
int32_t usrp_set_rfgain (usrp_handle &handle, uint8_t rfgain)
 
int32_t usrp_get_rfgain (usrp_handle &handle)
 
int32_t usrp_set_rfpower (usrp_handle &handle, float power)
 
int32_t usrp_get_rfpower (usrp_handle &handle)
 
int32_t usrp_set_squelch (usrp_handle &handle, uint8_t squelch)
 
int32_t usrp_get_squelch (usrp_handle &handle)
 
int32_t usrp_set_datamode (usrp_handle &handle, uint8_t mode)
 
int32_t usrp_get_datamode (usrp_handle &handle)
 
int32_t usrp_set_bps9600mode (usrp_handle &handle, uint8_t mode)
 
int32_t usrp_get_bps9600mode (usrp_handle &handle)
 
int32_t usrp_get_smeter (usrp_handle &handle)
 
int32_t usrp_get_rfmeter (usrp_handle &handle)
 
int32_t usrp_get_swrmeter (usrp_handle &handle)
 
int32_t usrp_get_alcmeter (usrp_handle &handle)
 
int32_t usrp_get_compmeter (usrp_handle &handle)
 
int32_t usrp_get_record (usrp_handle &handle)
 
int32_t usrp_set_record (usrp_handle &handle, uint8_t record)
 

Macro Definition Documentation

#define USRP_BAUD   19200
#define USRP_BITS   8
#define USRP_PARITY   0
#define USRP_STOPBITS   1
#define USRP_CHANNEL_A   0
#define USRP_CHANNEL_B   1
#define USRP_CHANNEL_SWAP   2
#define USRP_DATAMODE_OFF   0
#define USRP_DATAMODE_ON   1
#define USRP_9600MODE_OFF   0
#define USRP_9600MODE_ON   1
#define USRP_MODE_LSB   0
#define USRP_MODE_USB   1
#define USRP_MODE_AM   2
#define USRP_MODE_CW   3
#define USRP_MODE_RTTY   4
#define USRP_MODE_FM   5
#define USRP_MODE_CWR   7
#define USRP_MODE_RTTYR   8
#define USRP_MODE_DV   17
#define USRP_FILTER_1   1
#define USRP_FILTER_2   2
#define USRP_FILTER_3   3

Function Documentation

int32_t usrp_connect ( string  device,
uint16_t  port,
usrp_handle handle 
)
34 {
35  int32_t iretn;
36 
37  iretn = socket_open(&handle.socket, NetworkType::UDP, device.c_str(), 10003, SOCKET_TALK, true, 2000000);
38 
39  if (iretn < 0)
40  {
41  return (iretn);
42  }
43 
44  handle.port = port;
45 
46  return iretn;
47 }
static string port
Definition: add_radio.cpp:16
uint16_t port
Definition: usrp_lib.h:72
Agent socket using Unicast UDP.
int iretn
Definition: rw_test.cpp:37
#define SOCKET_TALK
Talk followed by optional listen (sendto address)
Definition: socketlib.h:82
socket_channel socket
Definition: usrp_lib.h:71
int32_t socket_open(socket_channel *channel, NetworkType ntype, const char *address, uint16_t port, uint16_t role, bool blocking, uint32_t usectimeo, uint32_t rcvbuf, uint32_t sndbuf)
Open UDP socket.
Definition: socketlib.cpp:51
static string device
Definition: ax25_recv.cpp:39
int32_t usrp_disconnect ( usrp_handle handle)
50 {
51  int iretn;
52 
53  iretn = socket_close(&handle.socket);
54  return iretn;
55 }
int32_t socket_close(socket_channel *channel)
Close socket.
Definition: socketlib.cpp:509
int iretn
Definition: rw_test.cpp:37
socket_channel socket
Definition: usrp_lib.h:71
int32_t usrp_send ( usrp_handle handle,
std::string &  data 
)
uint8_t usrp_byte ( vector< uint8_t >  response)
70 {
71  uint8_t result = 0.;
72  for (size_t i=0; i<2; ++i)
73  {
74  result *= 100.;
75  result += 10. * (response[i] >> 4) + (response[i] % 16);
76  }
77 
78  return result;
79 }
int i
Definition: rw_test.cpp:37
uint8_t usrp_freq2band ( double  frequency)
82 {
83  uint8_t freqband;
84 
85  if (frequency < 1.8e6)
86  {
87  freqband = 14;
88  }
89  else if (frequency < 2.0e6)
90  {
91  freqband = 1;
92  }
93  else if (frequency >= 3.4e6 && frequency < 4.1e6)
94  {
95  freqband = 2;
96  }
97  else if (frequency >= 6.9e6 && frequency < 7.5e6)
98  {
99  freqband = 3;
100  }
101  else if (frequency >= 9.9e6 && frequency < 10.5e6)
102  {
103  freqband = 4;
104  }
105  else if (frequency >= 13.9e6 && frequency < 14.5e6)
106  {
107  freqband = 5;
108  }
109  else if (frequency >= 17.9e6 && frequency < 18.5e6)
110  {
111  freqband = 6;
112  }
113  else if (frequency >= 20.9e6 && frequency < 21.5e6)
114  {
115  freqband = 7;
116  }
117  else if (frequency >= 24.4e6 && frequency < 25.1e6)
118  {
119  freqband = 8;
120  }
121  else if (frequency >= 28.0e6 && frequency < 30.0e6)
122  {
123  freqband = 9;
124  }
125  else if (frequency >= 50.0e6 && frequency <= 54.0e6)
126  {
127  freqband = 10;
128  }
129  else if (frequency >= 108.0e6 && frequency <= 174.0e6)
130  {
131  freqband = 11;
132  }
133  else if (frequency >= 420.0e6 && frequency <= 480.0e6)
134  {
135  freqband = 12;
136  }
137  else if (frequency >= 1240.0e6 && frequency <1320.0e6)
138  {
139  freqband = 13;
140  }
141  else
142  {
143  freqband = 14;
144  }
145  return freqband;
146 }
int32_t usrp_check_address ( usrp_handle handle)
int32_t usrp_set_channel ( usrp_handle handle,
uint8_t  channelnum 
)
int32_t usrp_set_frequency ( usrp_handle handle,
double  frequency 
)
227 {
228  int32_t iretn = 0;
229 
230  string data = "downlink_freq " + to_unsigned(frequency);
231 
232  iretn = usrp_send(handle, data);
233  if (iretn < 0)
234  {
235  handle.frequency = 0.;
236  handle.freqband = 0;
237  return iretn;
238  }
239 
240  handle.frequency = stof(data);
241 
242  if (handle.frequency < 1.8e6)
243  {
244  handle.freqband = 14;
245  }
246  else if (handle.frequency < 2.0e6)
247  {
248  handle.freqband = 1;
249  }
250  else if (handle.frequency >= 3.4e6 && handle.frequency < 4.1e6)
251  {
252  handle.freqband = 2;
253  }
254  else if (handle.frequency >= 6.9e6 && handle.frequency < 7.5e6)
255  {
256  handle.freqband = 3;
257  }
258  else if (handle.frequency >= 9.9e6 && handle.frequency < 10.5e6)
259  {
260  handle.freqband = 4;
261  }
262  else if (handle.frequency >= 13.9e6 && handle.frequency < 14.5e6)
263  {
264  handle.freqband = 5;
265  }
266  else if (handle.frequency >= 17.9e6 && handle.frequency < 18.5e6)
267  {
268  handle.freqband = 6;
269  }
270  else if (handle.frequency >= 20.9e6 && handle.frequency < 21.5e6)
271  {
272  handle.freqband = 7;
273  }
274  else if (handle.frequency >= 24.4e6 && handle.frequency < 25.1e6)
275  {
276  handle.freqband = 8;
277  }
278  else if (handle.frequency >= 28.0e6 && handle.frequency < 30.0e6)
279  {
280  handle.freqband = 9;
281  }
282  else if (handle.frequency >= 50.0e6 && handle.frequency <= 54.0e6)
283  {
284  handle.freqband = 10;
285  }
286  else if (handle.frequency >= 108.0e6 && handle.frequency <= 174.0e6)
287  {
288  handle.freqband = 11;
289  }
290  else if (handle.frequency >= 420.0e6 && handle.frequency <= 480.0e6)
291  {
292  handle.freqband = 12;
293  }
294  else if (handle.frequency >= 1240.0e6 && handle.frequency <1320.0e6)
295  {
296  handle.freqband = 13;
297  }
298  else
299  {
300  handle.freqband = 14;
301  }
302 
303  return 0;
304 }
int32_t usrp_send(usrp_handle &handle, string &data)
Definition: usrp_lib.cpp:57
int iretn
Definition: rw_test.cpp:37
string to_unsigned(uint64_t value, uint16_t digits, bool zerofill)
Definition: stringlib.cpp:265
uint8_t freqband
Definition: usrp_lib.h:75
double frequency
Definition: usrp_lib.h:93
int32_t usrp_get_frequency ( usrp_handle handle)
149 {
150  int32_t iretn;
151 
152  string data = "downlink_freq 0";
153 
154  iretn = usrp_send(handle, data);
155  if (iretn < 1)
156  {
157  handle.frequency = 0.;
158  handle.freqband = 0;
159  return iretn;
160  }
161 
162  handle.frequency = stof(data);
163 
164  if (handle.frequency < 1.8e6)
165  {
166  handle.freqband = 14;
167  }
168  else if (handle.frequency < 2.0e6)
169  {
170  handle.freqband = 1;
171  }
172  else if (handle.frequency >= 3.4e6 && handle.frequency < 4.1e6)
173  {
174  handle.freqband = 2;
175  }
176  else if (handle.frequency >= 6.9e6 && handle.frequency < 7.5e6)
177  {
178  handle.freqband = 3;
179  }
180  else if (handle.frequency >= 9.9e6 && handle.frequency < 10.5e6)
181  {
182  handle.freqband = 4;
183  }
184  else if (handle.frequency >= 13.9e6 && handle.frequency < 14.5e6)
185  {
186  handle.freqband = 5;
187  }
188  else if (handle.frequency >= 17.9e6 && handle.frequency < 18.5e6)
189  {
190  handle.freqband = 6;
191  }
192  else if (handle.frequency >= 20.9e6 && handle.frequency < 21.5e6)
193  {
194  handle.freqband = 7;
195  }
196  else if (handle.frequency >= 24.4e6 && handle.frequency < 25.1e6)
197  {
198  handle.freqband = 8;
199  }
200  else if (handle.frequency >= 28.0e6 && handle.frequency < 30.0e6)
201  {
202  handle.freqband = 9;
203  }
204  else if (handle.frequency >= 50.0e6 && handle.frequency <= 54.0e6)
205  {
206  handle.freqband = 10;
207  }
208  else if (handle.frequency >= 108.0e6 && handle.frequency <= 174.0e6)
209  {
210  handle.freqband = 11;
211  }
212  else if (handle.frequency >= 420.0e6 && handle.frequency <= 480.0e6)
213  {
214  handle.freqband = 12;
215  }
216  else if (handle.frequency >= 1240.0e6 && handle.frequency <1320.0e6)
217  {
218  handle.freqband = 13;
219  }
220  else
221  {
222  handle.freqband = 14;
223  }
224  return iretn;
225 }
int32_t usrp_send(usrp_handle &handle, string &data)
Definition: usrp_lib.cpp:57
int iretn
Definition: rw_test.cpp:37
uint8_t freqband
Definition: usrp_lib.h:75
double frequency
Definition: usrp_lib.h:93
int32_t usrp_set_freqband ( usrp_handle handle,
uint8_t  mode 
)
int32_t usrp_get_freqband ( usrp_handle handle)
int32_t usrp_set_bandpass ( usrp_handle handle,
double  bandpass 
)
int32_t usrp_get_bandpass ( usrp_handle handle)
int32_t usrp_set_mode ( usrp_handle handle,
uint8_t  opmode 
)
int32_t usrp_set_mode ( usrp_handle handle,
uint8_t  opmode,
uint8_t  filtband 
)
int32_t usrp_get_mode ( usrp_handle handle)
int32_t usrp_set_rfgain ( usrp_handle handle,
uint8_t  rfgain 
)
int32_t usrp_get_rfgain ( usrp_handle handle)
int32_t usrp_set_rfpower ( usrp_handle handle,
float  power 
)
int32_t usrp_get_rfpower ( usrp_handle handle)
int32_t usrp_set_squelch ( usrp_handle handle,
uint8_t  squelch 
)
int32_t usrp_get_squelch ( usrp_handle handle)
int32_t usrp_set_datamode ( usrp_handle handle,
uint8_t  mode 
)
int32_t usrp_get_datamode ( usrp_handle handle)
int32_t usrp_set_bps9600mode ( usrp_handle handle,
uint8_t  mode 
)
int32_t usrp_get_bps9600mode ( usrp_handle handle)
int32_t usrp_get_smeter ( usrp_handle handle)
int32_t usrp_get_rfmeter ( usrp_handle handle)
int32_t usrp_get_swrmeter ( usrp_handle handle)
int32_t usrp_get_alcmeter ( usrp_handle handle)
int32_t usrp_get_compmeter ( usrp_handle handle)
int32_t usrp_get_record ( usrp_handle handle)
307 {
308  int32_t iretn = 0;
309 
310  string data = "record 2";
311 
312  iretn = usrp_send(handle, data);
313  if (iretn < 0)
314  {
315  return iretn;
316  }
317 
318  handle.record = stoi(data);
319  return iretn;
320 }
int32_t usrp_send(usrp_handle &handle, string &data)
Definition: usrp_lib.cpp:57
uint8_t record
Definition: usrp_lib.h:69
int iretn
Definition: rw_test.cpp:37
int32_t usrp_set_record ( usrp_handle handle,
uint8_t  record 
)
323 {
324  int32_t iretn = 0;
325 
326  string data;
327  if (record)
328  {
329  data = "record 1";
330  iretn = usrp_send(handle, data);
331  }
332  else {
333  data = "record 0";
334  iretn = usrp_send(handle, data);
335  }
336 
337  if (iretn < 0)
338  {
339  return iretn;
340  }
341 
342  handle.record = record;
343  return iretn;
344 }
int32_t usrp_send(usrp_handle &handle, string &data)
Definition: usrp_lib.cpp:57
uint8_t record
Definition: usrp_lib.h:69
int iretn
Definition: rw_test.cpp:37