MLAT (width and frequency) and RSSI (width) scaling working.
This commit is contained in:
@@ -7,8 +7,7 @@
|
|||||||
#include "airspy_adsb.h"
|
#include "airspy_adsb.h"
|
||||||
|
|
||||||
struct airspy_adsb_parser_state {
|
struct airspy_adsb_parser_state {
|
||||||
uint64_t mlat_timestamp_last;
|
struct mlat_state mlat_state;
|
||||||
uint64_t mlat_timestamp_generation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool airspy_adsb_parse_common(char *, struct packet *, struct airspy_adsb_parser_state *);
|
static bool airspy_adsb_parse_common(char *, struct packet *, struct airspy_adsb_parser_state *);
|
||||||
@@ -60,7 +59,7 @@ static bool airspy_adsb_parse_common(char *in, struct packet *packet, struct air
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint16_t mlat_mhz = 2 * hex_to_int(&in[9], 1);
|
uint16_t mlat_mhz = 2 * hex_to_int(&in[9], 1);
|
||||||
packet->mlat_timestamp = hex_to_int(in, 4) * (MLAT_MHZ / mlat_mhz);
|
packet->mlat_timestamp = mlat_timestamp_scale_in(hex_to_int(in, 4), UINT32_MAX, mlat_mhz, &state->mlat_state);
|
||||||
packet->rssi = hex_to_int(&in[12], 2) * (RSSI_MAX / UINT16_MAX);
|
packet->rssi = rssi_scale_in(hex_to_int(&in[12], 2), UINT16_MAX);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
28
common.c
28
common.c
@@ -7,6 +7,10 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MLAT_MHZ 120
|
||||||
|
#define RSSI_MAX UINT32_MAX
|
||||||
|
|
||||||
|
|
||||||
void buf_init(struct buf *buf) {
|
void buf_init(struct buf *buf) {
|
||||||
buf->start = 0;
|
buf->start = 0;
|
||||||
buf->length = 0;
|
buf->length = 0;
|
||||||
@@ -40,6 +44,30 @@ void buf_consume(struct buf *buf, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t mlat_timestamp_scale_mhz_in(uint64_t timestamp, uint32_t mhz) {
|
||||||
|
return timestamp * (MLAT_MHZ / mhz);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t mlat_timestamp_scale_width_in(uint64_t timestamp, uint64_t max, struct mlat_state *state) {
|
||||||
|
if (timestamp < state->timestamp_last) {
|
||||||
|
// Counter reset
|
||||||
|
state->timestamp_generation += max;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->timestamp_last = timestamp;
|
||||||
|
return state->timestamp_generation + timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t mlat_timestamp_scale_in(uint64_t timestamp, uint64_t max, uint16_t mhz, struct mlat_state *state) {
|
||||||
|
return mlat_timestamp_scale_mhz_in(mlat_timestamp_scale_width_in(timestamp, max, state), mhz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t rssi_scale_in(uint32_t value, uint32_t max) {
|
||||||
|
return value * (RSSI_MAX / max);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint8_t hex_table[256] = {0};
|
static uint8_t hex_table[256] = {0};
|
||||||
|
|
||||||
void hex_init() {
|
void hex_init() {
|
||||||
|
|||||||
17
common.h
17
common.h
@@ -34,8 +34,6 @@ void buf_consume(struct buf *, size_t);
|
|||||||
|
|
||||||
//////// packet
|
//////// packet
|
||||||
|
|
||||||
#define MLAT_MHZ 120
|
|
||||||
#define RSSI_MAX UINT32_MAX
|
|
||||||
#define DATA_LEN_MAX 14
|
#define DATA_LEN_MAX 14
|
||||||
struct packet {
|
struct packet {
|
||||||
enum {
|
enum {
|
||||||
@@ -49,6 +47,21 @@ struct packet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////// mlat
|
||||||
|
|
||||||
|
struct mlat_state {
|
||||||
|
uint64_t timestamp_last;
|
||||||
|
uint64_t timestamp_generation;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint64_t mlat_timestamp_scale_in(uint64_t, uint64_t, uint16_t, struct mlat_state *);
|
||||||
|
|
||||||
|
|
||||||
|
//////// rssi
|
||||||
|
|
||||||
|
uint32_t rssi_scale_in(uint32_t, uint32_t);
|
||||||
|
|
||||||
|
|
||||||
//////// hex
|
//////// hex
|
||||||
|
|
||||||
void hex_init();
|
void hex_init();
|
||||||
|
|||||||
Reference in New Issue
Block a user