MLAT (width and frequency) and RSSI (width) scaling working.

This commit is contained in:
Ian Gulliver
2016-02-15 22:01:32 +00:00
parent bae4398a61
commit cbae234327
3 changed files with 46 additions and 6 deletions

View File

@@ -7,8 +7,7 @@
#include "airspy_adsb.h"
struct airspy_adsb_parser_state {
uint64_t mlat_timestamp_last;
uint64_t mlat_timestamp_generation;
struct mlat_state mlat_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;
}
uint16_t mlat_mhz = 2 * hex_to_int(&in[9], 1);
packet->mlat_timestamp = hex_to_int(in, 4) * (MLAT_MHZ / mlat_mhz);
packet->rssi = hex_to_int(&in[12], 2) * (RSSI_MAX / UINT16_MAX);
packet->mlat_timestamp = mlat_timestamp_scale_in(hex_to_int(in, 4), UINT32_MAX, mlat_mhz, &state->mlat_state);
packet->rssi = rssi_scale_in(hex_to_int(&in[12], 2), UINT16_MAX);
return true;
}

View File

@@ -7,6 +7,10 @@
#include "common.h"
#define MLAT_MHZ 120
#define RSSI_MAX UINT32_MAX
void buf_init(struct buf *buf) {
buf->start = 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};
void hex_init() {

View File

@@ -34,8 +34,6 @@ void buf_consume(struct buf *, size_t);
//////// packet
#define MLAT_MHZ 120
#define RSSI_MAX UINT32_MAX
#define DATA_LEN_MAX 14
struct packet {
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
void hex_init();