From eeea678d5fa1cb017e4fe86fd8b1eb89b88e4c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BENEDEK=20L=C3=A1szl=C3=B3?= Date: Fri, 14 Feb 2025 15:02:16 +0100 Subject: [PATCH] first working recording, max 1 MS/s --- src/pico-radio/main.c | 40 +++++++++++++++++++++++++++++++--------- test/fft.py | 12 ++++++++++++ test/view.py | 12 ++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100755 test/fft.py create mode 100755 test/view.py diff --git a/src/pico-radio/main.c b/src/pico-radio/main.c index 1cbec0c..a303ed3 100644 --- a/src/pico-radio/main.c +++ b/src/pico-radio/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -12,43 +13,64 @@ void capture_stop(int signal) { stop = true; } +static const uint32_t buffersize = 10000; + void get_overview_buffers(int16_t** overviewBuffers, int16_t overflow, uint32_t triggeredAt, int16_t triggered, int16_t auto_stop, uint32_t nValues) { (void)overflow; (void)triggeredAt; (void)triggered; (void)auto_stop; - fwrite(overviewBuffers[0], sizeof(int16_t), nValues, stdout); + fprintf(stderr, "nValues: %u\n", nValues); + + static float floatbuff[10000]; // TODO variable + for (unsigned i = 0; i < nValues; i++) { + floatbuff[i] = overviewBuffers[0][i]; + floatbuff[i] /= 32768; // TODO limit.h + } + fwrite(floatbuff, sizeof(float), nValues, stdout); } int main(int argc, char** argv) { (void)argc; (void)argv; - signal(SIGINT, &capture_stop); - int16_t unit = ps2000_open_unit(); - if (ps2000_set_channel(unit, PS2000_CHANNEL_A, true, false, PS2000_100MV) == 0) { - fprintf(stderr, "set channel unsuccesful!\n"); + if (ps2000_set_channel(unit, PS2000_CHANNEL_A, true, false, PS2000_10V) == 0) { + fprintf(stderr, "set_channel failed!\n"); ps2000_close_unit(unit); return 1; } if (ps2000_set_trigger(unit, PS2000_NONE, 0, 0, 0, 0) == 0) { - fprintf(stderr, "set trigger unsuccesful!\n"); + fprintf(stderr, "set_trigger failed!\n"); ps2000_close_unit(unit); return 1; } - if (ps2000_run_streaming_ns(unit, 100, PS2000_US, 100000, false, 1, 100000) == 0) { - fprintf(stderr, "run streaming unsuccesful!\n"); + if (ps2000_run_streaming_ns(unit, 1000, PS2000_NS, buffersize, false, 1, 50000) == 0) { + fprintf(stderr, "run_streaming_ns failed!\n"); ps2000_close_unit(unit); return 1; } + signal(SIGINT, &capture_stop); + while (!stop) { - ps2000_get_streaming_last_values(unit, &get_overview_buffers); + if (ps2000_get_streaming_last_values(unit, &get_overview_buffers) == 0) { + // fprintf(stderr, "callback won't be called!\n"); + } + /* + int16_t overrun = 0; + if (ps2000_overview_buffer_status(unit, &overrun) != 0) { + fprintf(stderr, "failed to check overrun!\n"); + } else if (overrun) { + fprintf(stderr, "overrun!\n"); + } + + // usleep(0); + */ } ps2000_stop(unit); diff --git a/test/fft.py b/test/fft.py new file mode 100755 index 0000000..e38a21c --- /dev/null +++ b/test/fft.py @@ -0,0 +1,12 @@ +#!/bin/env python3 + +import numpy as np +import matplotlib.pyplot as plt + +data = [] + +with open("test", "rb") as f: + data = np.fromfile(f, dtype=np.int16) + +plt.psd(data, Fs=1e6) +plt.show() diff --git a/test/view.py b/test/view.py new file mode 100755 index 0000000..4726c1b --- /dev/null +++ b/test/view.py @@ -0,0 +1,12 @@ +#!/bin/env python3 + +import numpy as np +import matplotlib.pyplot as plt + +data = [] + +with open("test", "rb") as f: + data = np.fromfile(f, dtype=np.int16) + +plt.plot(data[:10000]) +plt.show() \ No newline at end of file