You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
55 lines
2.0 KiB
// SPDX-License-Identifier: MIT |
|
// The public header from C++ (SDRAngel, GNU Radio): compiles, links, and |
|
// std::complex<float> buffers pass straight through. |
|
#include <chirpmodem.h> |
|
#include <complex> |
|
#include <cstdio> |
|
#include <cstring> |
|
#include <string> |
|
#include <vector> |
|
|
|
struct Sink { |
|
std::vector<std::string> bodies; |
|
static void on_frame(void *user, const chirpmodem_frame *f) |
|
{ |
|
if (f->status == CHIRPMODEM_FRAME_OK) |
|
static_cast<Sink *>(user)->bodies.emplace_back(reinterpret_cast<const char *>(f->body), |
|
f->body_len); |
|
} |
|
}; |
|
|
|
int main() |
|
{ |
|
chirpmodem_tx_config tc; |
|
chirpmodem_tx_config_init(&tc); |
|
tc.fs = 1e6; |
|
tc.if_offset = 250e3; |
|
int err = 0; |
|
chirpmodem_tx *tx = chirpmodem_tx_new(&tc, &err); |
|
if (!tx) { |
|
std::printf("tx: %s\n", chirpmodem_strerror(err)); |
|
return 1; |
|
} |
|
const std::string msg = "hello from C++"; |
|
const uint8_t *b = reinterpret_cast<const uint8_t *>(msg.data()); |
|
long n = chirpmodem_tx_frame(tx, "KD2HSG", nullptr, b, (int)msg.size(), 0, nullptr, 0); |
|
std::vector<std::complex<float>> x(100000 + n + 100000); |
|
long got = chirpmodem_tx_frame(tx, "KD2HSG", nullptr, b, (int)msg.size(), 0, |
|
reinterpret_cast<float *>(x.data() + 100000), n); |
|
|
|
Sink sink; |
|
chirpmodem_rx_config rc; |
|
chirpmodem_rx_config_init(&rc); |
|
rc.on_frame = &Sink::on_frame; |
|
rc.user = &sink; |
|
chirpmodem_rx *rx = chirpmodem_rx_new(&rc, &err); |
|
for (size_t k = 0; k < x.size(); k += 8192) |
|
chirpmodem_rx_push(rx, reinterpret_cast<const float *>(x.data() + k), |
|
(long)std::min<size_t>(8192, x.size() - k), CHIRPMODEM_CF32); |
|
chirpmodem_rx_finish(rx); |
|
chirpmodem_rx_free(rx); |
|
chirpmodem_tx_free(tx); |
|
bool ok = got == n && sink.bodies.size() == 1 && sink.bodies[0] == msg; |
|
std::printf("C++ consumer: %s\n", ok ? "ok" : "FAILED"); |
|
return ok ? 0 : 1; |
|
}
|
|
|