Cheaper airspy matching

This commit is contained in:
Ian Gulliver
2016-02-14 07:11:26 +00:00
parent 51690ba0df
commit f7bee3ce44
4 changed files with 13 additions and 13 deletions

View File

@@ -131,7 +131,6 @@ int loop(int bfd) {
buf_alias(&tmp, &buf);
while (airspy_adsb_parse(&tmp, &packet)) {
buf_alias(&buf, &tmp);
fprintf(stderr, "packet!\n");
}
if (buf.length == BUF_LEN) {

View File

@@ -1,20 +1,20 @@
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "airspy_adsb.h"
bool airspy_adsb_parse(struct buf *buf, struct packet *packet) {
if (buf->length < 35) {
// Minimum frame length
if (buf->length < 1 || *buf_at(buf, 0) != '*') {
return false;
}
if (buf->buf[buf->start] != '*') {
return false;
if (buf->length >= 35 && *buf_at(buf, 34) == '\n') {
buf_consume(buf, 35);
return true;
}
char *last = memchr(&buf->buf[buf->start], '\n', buf->length);
if (!last) {
return false;
if (buf->length >= 49 && *buf_at(buf, 48) == '\n') {
buf_consume(buf, 49);
return true;
}
buf_consume(buf, last - &buf->buf[buf->start] + 1);
return true;
return false;
}

View File

@@ -21,13 +21,12 @@ void buf_alias(struct buf *to, struct buf *from) {
ssize_t buf_fill(struct buf *buf, int fd) {
if (buf->start + buf->length == BUF_LEN) {
assert(buf->start > 0);
memmove(buf->buf, &buf->buf[buf->start], buf->length);
memmove(buf->buf, buf_at(buf, 0), buf->length);
buf->start = 0;
}
size_t space = BUF_LEN - buf->length - buf->start;
size_t end = buf->start + buf->length;
ssize_t in = read(fd, &buf->buf[end], space);
ssize_t in = read(fd, buf_at(buf, buf->length), space);
if (in < 0) {
return in;
}

View File

@@ -25,6 +25,8 @@ struct packet {
};
#define buf_at(buff, at) (&(buff)->buf[(buff)->start + (at)])
void buf_init(struct buf *, char *, char *);
void buf_alias(struct buf *, struct buf *);