Add raw input support.
This commit is contained in:
4
Makefile
4
Makefile
@@ -11,5 +11,5 @@ clean:
|
|||||||
%.o: %.c *.h
|
%.o: %.c *.h
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
adsbus: adsbus.o backend.o client.o airspy_adsb.o beast.o json.o stats.o common.o
|
adsbus: adsbus.o backend.o client.o airspy_adsb.o beast.o json.o raw.o stats.o common.o
|
||||||
$(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o client.o airspy_adsb.o beast.o json.o stats.o common.o $(LIBS)
|
$(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o client.o airspy_adsb.o beast.o json.o raw.o stats.o common.o $(LIBS)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void airspy_adsb_init() {
|
|||||||
|
|
||||||
static bool airspy_adsb_parse_mode_s_short(struct buf *buf, struct packet *packet, struct airspy_adsb_parser_state *state) {
|
static bool airspy_adsb_parse_mode_s_short(struct buf *buf, struct packet *packet, struct airspy_adsb_parser_state *state) {
|
||||||
struct airspy_adsb_mode_s_short_overlay *short_overlay = (struct airspy_adsb_mode_s_short_overlay *) buf_at(buf, 0);
|
struct airspy_adsb_mode_s_short_overlay *short_overlay = (struct airspy_adsb_mode_s_short_overlay *) buf_at(buf, 0);
|
||||||
if (buf->length < 35 ||
|
if (buf->length < sizeof(*short_overlay) ||
|
||||||
short_overlay->asterisk != '*' ||
|
short_overlay->asterisk != '*' ||
|
||||||
short_overlay->semicolon != ';' ||
|
short_overlay->semicolon != ';' ||
|
||||||
short_overlay->cr != '\r' ||
|
short_overlay->cr != '\r' ||
|
||||||
@@ -66,7 +66,7 @@ static bool airspy_adsb_parse_mode_s_short(struct buf *buf, struct packet *packe
|
|||||||
|
|
||||||
static bool airspy_adsb_parse_mode_s_long(struct buf *buf, struct packet *packet, struct airspy_adsb_parser_state *state) {
|
static bool airspy_adsb_parse_mode_s_long(struct buf *buf, struct packet *packet, struct airspy_adsb_parser_state *state) {
|
||||||
struct airspy_adsb_mode_s_long_overlay *long_overlay = (struct airspy_adsb_mode_s_long_overlay *) buf_at(buf, 0);
|
struct airspy_adsb_mode_s_long_overlay *long_overlay = (struct airspy_adsb_mode_s_long_overlay *) buf_at(buf, 0);
|
||||||
if (buf->length < 49 ||
|
if (buf->length < sizeof(*long_overlay) ||
|
||||||
long_overlay->asterisk != '*' ||
|
long_overlay->asterisk != '*' ||
|
||||||
long_overlay->semicolon != ';' ||
|
long_overlay->semicolon != ';' ||
|
||||||
long_overlay->cr != '\r' ||
|
long_overlay->cr != '\r' ||
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "airspy_adsb.h"
|
#include "airspy_adsb.h"
|
||||||
#include "beast.h"
|
#include "beast.h"
|
||||||
|
#include "raw.h"
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
|
|
||||||
@@ -33,6 +35,10 @@ struct parser {
|
|||||||
.name = "beast",
|
.name = "beast",
|
||||||
.parse = beast_parse,
|
.parse = beast_parse,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "raw",
|
||||||
|
.parse = raw_parse,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
#define NUM_PARSERS (sizeof(parsers) / sizeof(*parsers))
|
#define NUM_PARSERS (sizeof(parsers) / sizeof(*parsers))
|
||||||
|
|
||||||
|
|||||||
64
raw.c
Normal file
64
raw.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "raw.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct __attribute__((packed)) raw_mode_s_short_overlay {
|
||||||
|
char asterisk;
|
||||||
|
char payload[14];
|
||||||
|
char semicolon;
|
||||||
|
char lf;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __attribute__((packed)) raw_mode_s_long_overlay {
|
||||||
|
char asterisk;
|
||||||
|
char payload[28];
|
||||||
|
char semicolon;
|
||||||
|
char lf;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void raw_init() {
|
||||||
|
assert(sizeof(struct raw_mode_s_short_overlay) < BUF_LEN_MAX);
|
||||||
|
assert(sizeof(struct raw_mode_s_long_overlay) < BUF_LEN_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool raw_parse_mode_s_short(struct buf *buf, struct packet *packet) {
|
||||||
|
struct raw_mode_s_short_overlay *short_overlay = (struct raw_mode_s_short_overlay *) buf_at(buf, 0);
|
||||||
|
if (buf->length < sizeof(*short_overlay) ||
|
||||||
|
short_overlay->asterisk != '*' ||
|
||||||
|
short_overlay->semicolon != ';' ||
|
||||||
|
short_overlay->lf != '\n') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
packet->type = MODE_S_SHORT;
|
||||||
|
hex_to_bin(packet->payload, short_overlay->payload, sizeof(short_overlay->payload) / 2);
|
||||||
|
buf_consume(buf, sizeof(*short_overlay));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool raw_parse_mode_s_long(struct buf *buf, struct packet *packet) {
|
||||||
|
struct raw_mode_s_long_overlay *long_overlay = (struct raw_mode_s_long_overlay *) buf_at(buf, 0);
|
||||||
|
if (buf->length < sizeof(*long_overlay) ||
|
||||||
|
long_overlay->asterisk != '*' ||
|
||||||
|
long_overlay->semicolon != ';' ||
|
||||||
|
long_overlay->lf != '\n') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
packet->type = MODE_S_LONG;
|
||||||
|
hex_to_bin(packet->payload, long_overlay->payload, sizeof(long_overlay->payload) / 2);
|
||||||
|
buf_consume(buf, sizeof(*long_overlay));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool raw_parse(struct backend *backend, struct packet *packet) {
|
||||||
|
struct buf *buf = &backend->buf;
|
||||||
|
|
||||||
|
return (
|
||||||
|
raw_parse_mode_s_short(buf, packet) ||
|
||||||
|
raw_parse_mode_s_long(buf, packet));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user