1 sec updates over UDP

master
David 2020-07-27 17:35:39 +09:30
parent 502bd31d3d
commit f1250de7be
1 changed files with 18 additions and 13 deletions

View File

@ -59,6 +59,8 @@ static int sockfd;
static struct sockaddr_in serveraddr; static struct sockaddr_in serveraddr;
static char hostname[256]; static char hostname[256];
static int portno = 8001; static int portno = 8001;
static uint32_t sample_counter;
static uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
void usage(void) void usage(void)
{ {
@ -142,19 +144,23 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
rtlsdr_cancel_async(dev); rtlsdr_cancel_async(dev);
} }
if (udp_debug) { if (udp_debug) {
/* TODO: some sort of rate limiting on messages, based on sample rate, e.g. once per second */ sample_counter += fsk_nin(fsk);
int serverlen; if (sample_counter > samp_rate) {
char buf[256]; /* one second has passed, lets send some debug information */
int n; int serverlen;
/* send the message to the server */ char buf[256];
sprintf(buf, "hello\n"); int n;
serverlen = sizeof(serveraddr); sample_counter -= samp_rate;
n = sendto(sockfd, buf, strlen(buf), 0, (const struct sockaddr *)&serveraddr, serverlen); /* send the message to the server */
if (n < 0) { sprintf(buf, "hello\n");
fprintf(stderr, "ERROR in sendto\n"); serverlen = sizeof(serveraddr);
exit(1); n = sendto(sockfd, buf, strlen(buf), 0, (const struct sockaddr *)&serveraddr, serverlen);
if (n < 0) {
fprintf(stderr, "ERROR in sendto\n");
exit(1);
}
fprintf(stderr,"UDP message sent to %s:%d\n", hostname, portno);
} }
fprintf(stderr,"UDP message sent to %s:%d\n", hostname, portno);
} }
} }
@ -182,7 +188,6 @@ int main(int argc, char **argv)
int dev_index = 0; int dev_index = 0;
int dev_given = 0; int dev_given = 0;
uint32_t frequency = 100000000; uint32_t frequency = 100000000;
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:S:u:")) != -1) { while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:S:u:")) != -1) {
switch (opt) { switch (opt) {