From 09cc2dc8abb4fcf1870a851a20549529a578a39b Mon Sep 17 00:00:00 2001 From: David Date: Tue, 28 Jul 2020 05:29:07 +0930 Subject: [PATCH] first pass sending Sf info over UDP --- src/rtl_fsk.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/rtl_fsk.c b/src/rtl_fsk.c index 74ec6c9..b942d3c 100644 --- a/src/rtl_fsk.c +++ b/src/rtl_fsk.c @@ -46,6 +46,7 @@ #define DEFAULT_BUF_LENGTH (16 * 16384) #define MINIMAL_BUF_LENGTH 512 #define MAXIMAL_BUF_LENGTH (256 * 16384) +#define BUF_SZ 256 static int do_exit = 0; static uint32_t bytes_to_read = 0; @@ -74,6 +75,7 @@ void usage(void) "\t[-b output_block_size (default: 16 * 16384)]\n" "\t[-n number of samples to read (default: 0, infinite)]\n" "\t[-S force sync output (default: async)]\n" + "\t[-u hostname (optional host to send debug information to on port 8001)\n" "\tfilename (a '-' dumps bits to stdout)\n\n", DEFAULT_SAMPLE_RATE); exit(1); } @@ -99,6 +101,17 @@ static void sighandler(int signum) } #endif +static void udp_sendbuf(char buf[]) { + int n; + + /* send the message to the server */ + n = sendto(sockfd, buf, strlen(buf), 0, (const struct sockaddr *)&serveraddr, sizeof(serveraddr)); + if (n < 0) { + fprintf(stderr, "ERROR in sendto\n"); + exit(1); + } +} + static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) { unsigned char *pout; @@ -146,20 +159,23 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) if (udp_debug) { sample_counter += fsk_nin(fsk); if (sample_counter > samp_rate) { + char buf[BUF_SZ]; + size_t Ndft; /* one second has passed, lets send some debug information */ - int serverlen; - char buf[256]; - int n; sample_counter -= samp_rate; - /* send the message to the server */ - sprintf(buf, "hello\n"); - serverlen = sizeof(serveraddr); - n = sendto(sockfd, buf, strlen(buf), 0, (const struct sockaddr *)&serveraddr, serverlen); - if (n < 0) { - fprintf(stderr, "ERROR in sendto\n"); - exit(1); + + /* Print a sample of the FFT from the freq estimator */ + snprintf(buf, BUF_SZ, "{"); udp_sendbuf(buf); + snprintf(buf, BUF_SZ, "\"Sf\":["); udp_sendbuf(buf); + Ndft = fsk->Ndft; + for(i=0; iSf)[i]); udp_sendbuf(buf); + if(i