mirror of
https://github.com/brmlab/osmo-tetra.git
synced 2025-06-08 09:54:09 +02:00
float2bits migrated to tetra-rx
- compatible to old mode - new streaming mode (option -s) - buffer size adjusted
This commit is contained in:
parent
dafde94bfe
commit
148973da6e
1 changed files with 110 additions and 21 deletions
125
src/tetra-rx.c
125
src/tetra-rx.c
|
@ -34,23 +34,79 @@
|
|||
#include <phy/tetra_burst_sync.h>
|
||||
#include "tetra_gsmtap.h"
|
||||
|
||||
// size of IO buffers (number of elements)
|
||||
#define BUF_SIZE 256
|
||||
|
||||
void *tetra_tall_ctx;
|
||||
|
||||
|
||||
static int process_sym_fl(float fl)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* very simplistic scheme */
|
||||
if (fl > 2)
|
||||
ret = 3;
|
||||
else if (fl > 0)
|
||||
ret = 1;
|
||||
else if (fl < -2)
|
||||
ret = -3;
|
||||
else
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void sym_int2bits(int sym, uint8_t *ret)
|
||||
{
|
||||
switch (sym) {
|
||||
case -3:
|
||||
ret[0] = 1;
|
||||
ret[1] = 1;
|
||||
break;
|
||||
case 1:
|
||||
ret[0] = 0;
|
||||
ret[1] = 0;
|
||||
break;
|
||||
case 3:
|
||||
ret[0] = 0;
|
||||
ret[1] = 1;
|
||||
break;
|
||||
case -1:
|
||||
ret[0] = 1;
|
||||
ret[1] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int opt;
|
||||
int streaming = 0;
|
||||
int opt_verbose = 0;
|
||||
|
||||
struct tetra_rx_state *trs;
|
||||
struct tetra_mac_state *tms;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]);
|
||||
exit(1);
|
||||
while ((opt = getopt(argc, argv, "sv")) != -1) {
|
||||
switch (opt) {
|
||||
case 's':
|
||||
streaming = 1;
|
||||
break;
|
||||
case 'v':
|
||||
opt_verbose = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(2);
|
||||
if (argc <= optind) {
|
||||
fprintf(stderr, "Usage: %s -s [-v] <filestream>\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tetra_gsmtap_init("localhost", 0);
|
||||
|
@ -61,19 +117,52 @@ int main(int argc, char **argv)
|
|||
trs = talloc_zero(tetra_tall_ctx, struct tetra_rx_state);
|
||||
trs->burst_cb_priv = tms;
|
||||
|
||||
while (1) {
|
||||
uint8_t buf[64];
|
||||
int len;
|
||||
fd = open(argv[optind], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
if (len < 0) {
|
||||
perror("read");
|
||||
exit(1);
|
||||
} else if (len == 0) {
|
||||
printf("EOF");
|
||||
break;
|
||||
// use old mode which uses files with 1 byte per bit
|
||||
if(streaming == 0) {
|
||||
while (1) {
|
||||
uint8_t buf[64];
|
||||
int len;
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
if (len < 0) {
|
||||
perror("read");
|
||||
exit(1);
|
||||
} else if (len == 0) {
|
||||
printf("EOF");
|
||||
break;
|
||||
}
|
||||
tetra_burst_sync_in(trs, buf, len);
|
||||
}
|
||||
}
|
||||
else { // new fast mode - we will decode the incoming file ourself
|
||||
while (1) {
|
||||
int rc;
|
||||
float fl[BUF_SIZE];
|
||||
uint8_t bits[2*BUF_SIZE];
|
||||
rc = read(fd, fl, sizeof(*fl) * BUF_SIZE);
|
||||
if (rc < 0) {
|
||||
perror("read");
|
||||
exit(1);
|
||||
} else if (rc == 0) {
|
||||
break;
|
||||
}
|
||||
rc /= sizeof(*fl);
|
||||
int i;
|
||||
for (i = 0; i < rc; ++i) {
|
||||
int sym = process_sym_fl(fl[i]);
|
||||
sym_int2bits(sym, bits + i*2);
|
||||
if (opt_verbose) {
|
||||
printf("%1u%1u", bits[2*i + 0], bits[2*i + 1]);
|
||||
}
|
||||
}
|
||||
tetra_burst_sync_in(trs, bits, rc * 2);
|
||||
}
|
||||
tetra_burst_sync_in(trs, buf, len);
|
||||
}
|
||||
|
||||
talloc_free(trs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue