// SPDX-License-Identifier: MIT // The public header from C++ (SDRAngel, GNU Radio): compiles, links, and // std::complex buffers pass straight through. #include #include #include #include #include #include struct Sink { std::vector bodies; static void on_frame(void *user, const chirpmodem_frame *f) { if (f->status == CHIRPMODEM_FRAME_OK) static_cast(user)->bodies.emplace_back(reinterpret_cast(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(msg.data()); long n = chirpmodem_tx_frame(tx, "KD2HSG", nullptr, b, (int)msg.size(), 0, nullptr, 0); std::vector> x(100000 + n + 100000); long got = chirpmodem_tx_frame(tx, "KD2HSG", nullptr, b, (int)msg.size(), 0, reinterpret_cast(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(x.data() + k), (long)std::min(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; }