Skip to content

Commit c31953c

Browse files
committed
first pass simultaneous two raw date mode tx/rx
1 parent 42fa3a4 commit c31953c

File tree

4 files changed

+111
-10
lines changed

4 files changed

+111
-10
lines changed

README_freedv.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The current demo programs are as follows:
3434
| [freedv_700d_rx.py](demo/freedv_700d_rx.py) | Receive a voice signal using the FreeDV API in Python |
3535
| [freedv_datac1_tx.c](demo/freedv_datac1_tx.c) | Transmit raw data frames using the FreeDV API |
3636
| [freedv_datac1_rx.c](demo/freedv_datac1_rx.c) | Receive raw data frames using the FreeDV API |
37+
| [freedv_datac0c1_tx.c](demo/freedv_datac0c1_tx.c) | Transmit two types of raw data frames using the FreeDV API |
38+
| [freedv_datac0c1_rx.c](demo/freedv_datac0c1_rx.c) | Receive two types of raw data frames using the FreeDV API |
3739

3840
So also [freedv_api.h](src/freedv_api.h) and [freedv_api.c](src/freedv_api.c) for the full list of API functions. Only a small set of these functions are needed for basic FreeDV use, please see the demo programs for minimal examples.
3941

demo/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ add_executable(freedv_datac1_tx freedv_datac1_tx.c)
1111
target_link_libraries(freedv_datac1_tx codec2)
1212
add_executable(freedv_datac1_rx freedv_datac1_rx.c)
1313
target_link_libraries(freedv_datac1_rx codec2)
14+
add_executable(freedv_datac0c1_tx freedv_datac0c1_tx.c)
15+
target_link_libraries(freedv_datac0c1_tx codec2)
1416
add_executable(freedv_datac0c1_rx freedv_datac0c1_rx.c)
1517
target_link_libraries(freedv_datac0c1_rx codec2)

demo/freedv_datac0c1_rx.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
AUTHOR......: David Rowe
55
DATE CREATED: Dec 2021
66
7-
Demonstrates receiving frames of raw data bytes using the FreeDV API. Two
8-
parallel receivers are running, so we can receive either DATAC0 or DATAC1
9-
frames.
10-
11-
See freedv_datac0c1_tx.c for instructions.
7+
Demonstrates receiving frames of raw data bytes using the FreeDV
8+
API. Two parallel receivers are running, so we can receive either
9+
DATAC0 or DATAC1 frames. Demonstrates a common use case for HF data
10+
- the ability to receive signalling as well as payload data frames.
11+
12+
usage:
13+
cd codec2/build_linux
14+
./demo/freedv_datacc01_tx | ./demo/freedv_datac0c1_rx
1215
1316
\*---------------------------------------------------------------------------*/
1417

@@ -69,18 +72,19 @@ int main(int argc, char *argv[]) {
6972
int c1_frames = 0;
7073

7174
short buf[NBUF];
72-
75+
76+
// read a fixed buffer from stdin, use that to fill c0 and c1 demod_in buffers
7377
while(fread(buf, sizeof(short), NBUF, stdin) == NBUF) {
7478

79+
if (run_receiver(freedv_c0, buf, demod_in_c0, &n_c0, bytes_out_c0)) {
80+
fprintf(stderr, "DATAC0 frame received!\n");
81+
c0_frames++;
82+
}
7583
if (run_receiver(freedv_c1, buf, demod_in_c1, &n_c1, bytes_out_c1)) {
7684
fprintf(stderr, "DATAC1 frame received!\n");
7785
c1_frames++;
7886
}
7987

80-
if (run_receiver(freedv_c0, buf, demod_in_c0, &n_c0, bytes_out_c0)) {
81-
fprintf(stderr, "DATAC0 frame received!\n");
82-
c1_frames++;
83-
}
8488
}
8589

8690
fprintf(stderr, "DATAC0 Frames: %d\n", c0_frames);

demo/freedv_datac0c1_tx.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*---------------------------------------------------------------------------*\
2+
3+
FILE........: freedv_datac0c1_tx.c
4+
AUTHOR......: David Rowe
5+
DATE CREATED: Dec 2021
6+
7+
Transmitting alternate frames of two different raw data modes. See
8+
freedv_datac0c1_rx.c
9+
10+
\*---------------------------------------------------------------------------*/
11+
12+
/*
13+
Copyright (C) 2021 David Rowe
14+
15+
All rights reserved.
16+
17+
This program is free software; you can redistribute it and/or modify
18+
it under the terms of the GNU Lesser General Public License version 2.1, as
19+
published by the Free Software Foundation. This program is
20+
distributed in the hope that it will be useful, but WITHOUT ANY
21+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
22+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
23+
License for more details.
24+
25+
You should have received a copy of the GNU Lesser General Public License
26+
along with this program; if not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
29+
#include <assert.h>
30+
#include <stdlib.h>
31+
#include <stdio.h>
32+
#include <stdint.h>
33+
34+
#include "freedv_api.h"
35+
#include "ofdm_internal.h"
36+
37+
void send_burst(struct freedv *freedv);
38+
39+
int main(void) {
40+
struct freedv *freedv_c0, *freedv_c1;
41+
42+
freedv_c0 = freedv_open(FREEDV_MODE_DATAC0); assert(freedv_c0 != NULL);
43+
freedv_c1 = freedv_open(FREEDV_MODE_DATAC1); assert(freedv_c1 != NULL);
44+
45+
for(int b=0; b<10; b++) {
46+
send_burst(freedv_c0);
47+
send_burst(freedv_c1);
48+
}
49+
50+
freedv_close(freedv_c0);
51+
freedv_close(freedv_c1);
52+
53+
return 0;
54+
}
55+
56+
57+
void send_burst(struct freedv *freedv) {
58+
size_t bits_per_frame = freedv_get_bits_per_modem_frame(freedv);
59+
size_t bytes_per_modem_frame = bits_per_frame/8;
60+
size_t payload_bytes_per_modem_frame = bytes_per_modem_frame - 2; /* 16 bits used for the CRC */
61+
size_t n_mod_out = freedv_get_n_tx_modem_samples(freedv);
62+
uint8_t bytes_in[bytes_per_modem_frame];
63+
short mod_out_short[n_mod_out];
64+
65+
/* generate a test frame */
66+
uint8_t testframe_bits[bits_per_frame];
67+
ofdm_generate_payload_data_bits(testframe_bits, bits_per_frame);
68+
freedv_pack(bytes_in, testframe_bits, bits_per_frame);
69+
70+
/* send preamble */
71+
int n_preamble = freedv_rawdatapreambletx(freedv, mod_out_short);
72+
fwrite(mod_out_short, sizeof(short), n_preamble, stdout);
73+
74+
/* The raw data modes require a CRC in the last two bytes */
75+
uint16_t crc16 = freedv_gen_crc16(bytes_in, payload_bytes_per_modem_frame);
76+
bytes_in[bytes_per_modem_frame-2] = crc16 >> 8;
77+
bytes_in[bytes_per_modem_frame-1] = crc16 & 0xff;
78+
79+
/* modulate and send a data frame */
80+
freedv_rawdatatx(freedv, mod_out_short, bytes_in);
81+
fwrite(mod_out_short, sizeof(short), n_mod_out, stdout);
82+
83+
/* send postamble */
84+
int n_postamble = freedv_rawdatapostambletx(freedv, mod_out_short);
85+
fwrite(mod_out_short, sizeof(short), n_postamble, stdout);
86+
87+
/* create some silence between bursts */
88+
int inter_burst_delay_ms = 200;
89+
int samples_delay = FREEDV_FS_8000*inter_burst_delay_ms/1000;
90+
short sil_short[samples_delay];
91+
for(int i=0; i<samples_delay; i++) sil_short[i] = 0;
92+
fwrite(sil_short, sizeof(short), samples_delay, stdout);
93+
}

0 commit comments

Comments
 (0)