Track MRAR data per-aircraft and emit in aircraft.json
This commit is contained in:
parent
95ab1c0faa
commit
e0f794b1a5
36
net_io.c
36
net_io.c
|
|
@ -1612,6 +1612,29 @@ static const char *nav_altitude_source_enum_string(nav_altitude_source_t src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *mrar_source_enum_string(mrar_source_t src)
|
||||||
|
{
|
||||||
|
switch (src) {
|
||||||
|
case MRAR_SOURCE_INVALID: return "invalid";
|
||||||
|
case MRAR_SOURCE_INS: return "ins";
|
||||||
|
case MRAR_SOURCE_GNSS: return "gnss";
|
||||||
|
case MRAR_SOURCE_DMEDME: return "dmedme";
|
||||||
|
case MRAR_SOURCE_VORDME: return "vordme";
|
||||||
|
default: return "reserved";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *hazard_enum_string(hazard_t hazard)
|
||||||
|
{
|
||||||
|
switch (hazard) {
|
||||||
|
case HAZARD_NIL: return "nil";
|
||||||
|
case HAZARD_LIGHT: return "light";
|
||||||
|
case HAZARD_MODERATE: return "moderate";
|
||||||
|
case HAZARD_SEVERE: return "severe";
|
||||||
|
default: return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *generateAircraftJson(const char *url_path, int *len) {
|
char *generateAircraftJson(const char *url_path, int *len) {
|
||||||
uint64_t now = mstime();
|
uint64_t now = mstime();
|
||||||
struct aircraft *a;
|
struct aircraft *a;
|
||||||
|
|
@ -1715,12 +1738,23 @@ char *generateAircraftJson(const char *url_path, int *len) {
|
||||||
p = safe_snprintf(p, end, ",\"gva\":%u", a->gva);
|
p = safe_snprintf(p, end, ",\"gva\":%u", a->gva);
|
||||||
if (trackDataValid(&a->sda_valid))
|
if (trackDataValid(&a->sda_valid))
|
||||||
p = safe_snprintf(p, end, ",\"sda\":%u", a->sda);
|
p = safe_snprintf(p, end, ",\"sda\":%u", a->sda);
|
||||||
|
if (trackDataValid(&a->mrar_source_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"mrar_source\":\"%s\"", mrar_source_enum_string(a->mrar_source));
|
||||||
|
if (trackDataValid(&a->wind_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"wind_speed\":%.0f,\"wind_dir\":%.1f", a->wind_speed, a->wind_dir);
|
||||||
|
if (trackDataValid(&a->temperature_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"temperature\":%.2f", a->temperature);
|
||||||
|
if (trackDataValid(&a->pressure_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"pressure\":%.0f", a->pressure);
|
||||||
|
if (trackDataValid(&a->turbulence_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"turbulence\":\"%s\"", hazard_enum_string(a->turbulence));
|
||||||
|
if (trackDataValid(&a->humidity_valid))
|
||||||
|
p = safe_snprintf(p, end, ",\"humidity\":%.1f", a->humidity);
|
||||||
if (a->modeA_hit)
|
if (a->modeA_hit)
|
||||||
p = safe_snprintf(p, end, ",\"modea\":true");
|
p = safe_snprintf(p, end, ",\"modea\":true");
|
||||||
if (a->modeC_hit)
|
if (a->modeC_hit)
|
||||||
p = safe_snprintf(p, end, ",\"modec\":true");
|
p = safe_snprintf(p, end, ",\"modec\":true");
|
||||||
|
|
||||||
|
|
||||||
p = safe_snprintf(p, end, ",\"mlat\":");
|
p = safe_snprintf(p, end, ",\"mlat\":");
|
||||||
p = append_flags(p, end, a, SOURCE_MLAT);
|
p = append_flags(p, end, a, SOURCE_MLAT);
|
||||||
p = safe_snprintf(p, end, ",\"tisb\":");
|
p = safe_snprintf(p, end, ",\"tisb\":");
|
||||||
|
|
|
||||||
37
track.c
37
track.c
|
|
@ -130,6 +130,12 @@ static struct aircraft *trackCreateAircraft(struct modesMessage *mm) {
|
||||||
F(sil, 60, 70); // ADS-B only
|
F(sil, 60, 70); // ADS-B only
|
||||||
F(gva, 60, 70); // ADS-B only
|
F(gva, 60, 70); // ADS-B only
|
||||||
F(sda, 60, 70); // ADS-B only
|
F(sda, 60, 70); // ADS-B only
|
||||||
|
F(mrar_source, 60, 70); // Comm-B only
|
||||||
|
F(wind, 60, 70); // Comm-B only
|
||||||
|
F(temperature, 60, 70); // Comm-B only
|
||||||
|
F(pressure, 60, 70); // Comm-B only
|
||||||
|
F(turbulence, 60, 70); // Comm-B only
|
||||||
|
F(humidity, 60, 70); // Comm-B only
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
Modes.stats_current.unique_aircraft++;
|
Modes.stats_current.unique_aircraft++;
|
||||||
|
|
@ -1237,6 +1243,31 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
|
||||||
a->sda = mm->accuracy.sda;
|
a->sda = mm->accuracy.sda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mm->mrar_source_valid && accept_data(&a->mrar_source_valid, mm->source)) {
|
||||||
|
a->mrar_source = mm->mrar_source;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm->wind_valid && accept_data(&a->wind_valid, mm->source)) {
|
||||||
|
a->wind_speed = mm->wind_speed;
|
||||||
|
a->wind_dir = mm->wind_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm->temperature_valid && accept_data(&a->temperature_valid, mm->source)) {
|
||||||
|
a->temperature = mm->temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm->pressure_valid && accept_data(&a->pressure_valid, mm->source)) {
|
||||||
|
a->pressure = mm->pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm->turbulence_valid && accept_data(&a->turbulence_valid, mm->source)) {
|
||||||
|
a->turbulence = mm->turbulence;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm->humidity_valid && accept_data(&a->humidity_valid, mm->source)) {
|
||||||
|
a->humidity = mm->humidity;
|
||||||
|
}
|
||||||
|
|
||||||
// Now handle derived data
|
// Now handle derived data
|
||||||
|
|
||||||
// derive geometric altitude if we have baro + delta
|
// derive geometric altitude if we have baro + delta
|
||||||
|
|
@ -1400,6 +1431,12 @@ static void trackRemoveStaleAircraft(uint64_t now)
|
||||||
EXPIRE(sil);
|
EXPIRE(sil);
|
||||||
EXPIRE(gva);
|
EXPIRE(gva);
|
||||||
EXPIRE(sda);
|
EXPIRE(sda);
|
||||||
|
EXPIRE(mrar_source);
|
||||||
|
EXPIRE(wind);
|
||||||
|
EXPIRE(temperature);
|
||||||
|
EXPIRE(pressure);
|
||||||
|
EXPIRE(turbulence);
|
||||||
|
EXPIRE(humidity);
|
||||||
#undef EXPIRE
|
#undef EXPIRE
|
||||||
prev = a; a = a->next;
|
prev = a; a = a->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
track.h
16
track.h
|
|
@ -226,6 +226,22 @@ struct aircraft {
|
||||||
unsigned gva : 2; // GVA from opstatus
|
unsigned gva : 2; // GVA from opstatus
|
||||||
unsigned sda : 2; // SDA from opstatus
|
unsigned sda : 2; // SDA from opstatus
|
||||||
|
|
||||||
|
// data extracted from MRAR
|
||||||
|
data_validity mrar_source_valid;
|
||||||
|
data_validity wind_valid; // speed and direction
|
||||||
|
data_validity pressure_valid;
|
||||||
|
data_validity temperature_valid;
|
||||||
|
data_validity turbulence_valid;
|
||||||
|
data_validity humidity_valid;
|
||||||
|
|
||||||
|
mrar_source_t mrar_source;
|
||||||
|
float wind_speed;
|
||||||
|
float wind_dir;
|
||||||
|
float pressure;
|
||||||
|
float temperature;
|
||||||
|
hazard_t turbulence;
|
||||||
|
float humidity;
|
||||||
|
|
||||||
int modeA_hit; // did our squawk match a possible mode A reply in the last check period?
|
int modeA_hit; // did our squawk match a possible mode A reply in the last check period?
|
||||||
int modeC_hit; // did our altitude match a possible mode C reply in the last check period?
|
int modeC_hit; // did our altitude match a possible mode C reply in the last check period?
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue