Clean up buf silliness.

This commit is contained in:
Ian Gulliver
2016-02-14 20:35:43 +00:00
parent d660117f7a
commit 93558c0a23
4 changed files with 31 additions and 34 deletions

View File

@@ -5,14 +5,21 @@
#include "airspy_adsb.h"
bool airspy_adsb_parse(struct buf *buf, struct packet *packet) {
if (buf->length < 1 || *buf_at(buf, 0) != '*') {
if (buf->length < 35 ||
buf_chr(buf, 0) != '*') {
return false;
}
if (buf->length >= 35 && *buf_at(buf, 34) == '\n') {
if (buf->length >= 35 &&
buf_chr(buf, 34) == '\n' &&
buf_chr(buf, 15) == ';') {
packet->type = MODE_S_SHORT;
buf_consume(buf, 35);
return true;
}
if (buf->length >= 49 && *buf_at(buf, 48) == '\n') {
if (buf->length >= 49 &&
buf_chr(buf, 48) == '\n' &&
buf_chr(buf, 29) == ';') {
packet->type = MODE_S_LONG;
buf_consume(buf, 49);
return true;
}