Cheaper airspy matching
This commit is contained in:
1
adsbus.c
1
adsbus.c
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
5
common.c
5
common.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user