-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccsds-modem.h
128 lines (101 loc) · 3.1 KB
/
ccsds-modem.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
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
117
118
119
120
121
122
123
124
125
126
127
128
/*
Copyright (C) 2021 Gonzalo José Carracedo Carballal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>
*/
#ifndef _CCSDS_MODEM_H
#define _CCSDS_MODEM_H
#include "ccsds-tc.h"
#include "correlator.h"
#include <stdint.h>
#define CCSDS_MODEM_DEFAULT_RATE 6
#define CCSDS_MODEM_DEFAULT_BLOCK_LEN CCSDS_TC_BLOCK_LENGTH_1115
#define CCSDS_MODEM_DEFAULT_ITERS 1
#define CCSDS_MODEM_DEFAULT_SYNC_SNR 80.
#define CCSDS_MODEM_DEFAULT_EBN0 0.6310
#define CCSDS_MODEM_DEFAULT_CHANNEL true
struct ccsds_modem_params {
unsigned int rate_inv;
enum ccsds_tc_decoder_block_length block_len;
unsigned int iters;
float sync_snr;
float EbN0;
bool q_channel;
};
#define ccsds_modem_params_INITIALIZER \
{ \
CCSDS_MODEM_DEFAULT_RATE, \
CCSDS_MODEM_DEFAULT_BLOCK_LEN, \
CCSDS_MODEM_DEFAULT_ITERS, \
CCSDS_MODEM_DEFAULT_SYNC_SNR, \
CCSDS_MODEM_DEFAULT_EBN0, \
CCSDS_MODEM_DEFAULT_CHANNEL \
}
struct ccsds_modem {
struct ccsds_modem_params params;
correlator_t sync_corr;
ccsds_tc_decoder_t decoder;
bool syncing;
/* Precalculated variables */
softbit_t *buffer;
float complex *syncbuf;
const softbit_t *y;
unsigned int p, q;
unsigned int sync_len;
float polarity;
unsigned int frame_size;
unsigned int block_size;
unsigned int enc_size;
uint8_t *frame_bytes;
};
typedef struct ccsds_modem ccsds_modem_t;
ccsds_modem_t *ccsds_modem_new(const struct ccsds_modem_params *params);
bool ccsds_modem_feed(
ccsds_modem_t *self,
const float complex *x,
unsigned int L);
CCSDS_TC_INLINE const softbit_t *
ccsds_modem_get_frame_bits(const ccsds_modem_t *self)
{
return self->y;
}
CCSDS_TC_INLINE unsigned int
ccsds_modem_get_block_length(const ccsds_modem_t *self)
{
return self->block_size;
}
CCSDS_TC_INLINE float
ccsds_modem_get_error_rate(const ccsds_modem_t *self)
{
unsigned int i, count;
unsigned int block_size = ccsds_modem_get_block_length(self);
bool b1, b2;
count = 0;
for (i = 0; i < block_size; ++i) {
b2 = self->y[i] > 0;
b1 = self->buffer[i * self->params.rate_inv] > 0;
if (b1 != b2)
++count;
}
return (float) count / (float) block_size;
}
CCSDS_TC_INLINE const uint8_t *
ccsds_modem_get_frame_data(const ccsds_modem_t *self)
{
return self->frame_bytes;
}
CCSDS_TC_INLINE unsigned int
ccsds_modem_get_frame_length(const ccsds_modem_t *self)
{
return self->block_size >> 3;
}
void ccsds_modem_destroy(ccsds_modem_t *self);
#endif /* _CCSDS_MODEM */