This repository has been archived by the owner on Jun 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
sdr.h
52 lines (44 loc) · 1.62 KB
/
sdr.h
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
// $Id: sdr.h,v 1.8 2018/07/06 06:13:36 karn Exp $
// Interfaces to the Software Defined Radio front end hardware
// Right now these are somewhat specific to the AMSAT UK Funcube Dongle, and they
// need to be generalized to other hardware without losing the specific features
// of each device, e.g., the specific analog gain parameters
// Copyright 2018, Phil Karn KA9Q
#ifndef _SDR_H
#define _SDR_H 1
#include <stdint.h>
void closedown(int);
// Sent in each RTP packet right after header
// NB! because we just copy this into the network stream, it's important that the compiler
// not add any extra padding.
// To avoid this, the size must be a multiple of 8, the size of a double and long long
struct status {
long long timestamp; // Nanoseconds since GPS epoch 6 Jan 1980 00:00:00 UTC
double frequency;
uint32_t samprate;
uint8_t lna_gain;
uint8_t mixer_gain;
uint8_t if_gain;
uint8_t unused; // pad to 16 bytes
};
static inline unsigned char *ntoh_status(struct status *status,unsigned char *data){
// Host byte order
status->timestamp = *(long long *)data;
status->frequency = *(double *)&data[8];
status->samprate = *(uint32_t *)&data[16];
status->lna_gain = data[20];
status->mixer_gain = data[21];
status->if_gain = data[22];
return data + 24;
}
static inline unsigned char *hton_status(unsigned char *data,struct status *status){
// Host byte order
*(long long *)data = status->timestamp;
*(double *)&data[8] = status->frequency;
*(uint32_t *)&data[16] = status->samprate;
data[20] = status->lna_gain;
data[21] = status->mixer_gain;
data[22] = status->if_gain;
return data + 24;
}
#endif