{
double rad = M_PI / 180;
double earth_radius = 6371.2;
- double a = (90 - start_lat) * rad;
- double b = (90 - end_lat) * rad;
- double phi = (end_lon - start_lon) * rad;
- double cosr = cos(a) * cos(b) + sin(a) * sin(b) * cos(phi);
- double r = acos(cosr);
- double rdist = earth_radius * r;
- double sinth = sin(phi) * sin(b) / sin(r);
- double th = asin(sinth) / rad;
- *dist = rdist;
- *bearing = th;
+ double lat1 = rad * start_lat;
+ double lon1 = -rad * start_lon;
+ double lat2 = rad * end_lat;
+ double lon2 = -rad * end_lon;
+
+ double d = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
+ double argacos = (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1));
+ double crs;
+ if (sin(lon2-lon1) < 0)
+ crs = acos(argacos);
+ else
+ crs = 2 * M_PI - acos(argacos);
+ *dist = d * earth_radius;
+ *bearing = crs * 180/M_PI;
+}
+
+static void
+aoview_state_add_deg(char *label, double deg)
+{
+ double int_part;
+ double min;
+
+ int_part = floor (deg);
+ min = (deg - int_part) * 60.0;
+ aoview_table_add_row(label, "%d°%lf'",
+ (int) int_part, min);
+
}
void
int ticks;
double dist;
double bearing;
+ double temp;
+ double battery;
+ double drogue_sense, main_sense;
if (!strcmp(state->state, "pad")) {
if (npad < NUM_PAD_SAMPLES) {
velocity_change = (accel + prev_accel) / 2.0;
ticks = state->tick - prev_tick;
velocity -= velocity_change * (ticks / 100.0);
+ temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
+ battery = (state->batt / 32767.0 * 5.0);
+ drogue_sense = (state->drogue / 32767.0 * 15.0);
+ main_sense = (state->main / 32767.0 * 15.0);
prev_accel = accel;
prev_tick = state->tick;
- printf ("Pad altitude: %dm\n", aoview_pres_to_altitude(pad_pres));
- printf ("AGL: %dm\n", altitude);
- printf ("Acceleration: %gm/s²\n", accel);
- printf ("Velocity: %gm/s\n", velocity);
- printf ("Lat: %g\n", state->lat);
- printf ("Lon: %g\n", state->lon);
- printf ("GPS alt: %d\n", state->alt);
- aoview_great_circle(pad_lat, pad_lon, state->lat, state->lon,
- &dist, &bearing);
- printf ("Course: %gkm %g°\n", dist, bearing);
+ aoview_table_start();
+ aoview_table_add_row("RSSI", "%ddB", state->rssi);
+ aoview_table_add_row("Height", "%dm", altitude);
+ aoview_table_add_row("Acceleration", "%gm/s²", accel);
+ aoview_table_add_row("Velocity", "%gm/s", velocity);
+ aoview_table_add_row("Temperature", "%g°C", temp);
+ aoview_table_add_row("Battery", "%gV", battery);
+ aoview_table_add_row("Drogue", "%gV", drogue_sense);
+ aoview_table_add_row("Main", "%gV", main_sense);
+ aoview_table_add_row("Pad altitude", "%dm", aoview_pres_to_altitude(pad_pres));
+ aoview_table_add_row("Satellites", "%d", state->nsat);
+ if (state->locked) {
+ aoview_state_add_deg("Latitude", state->lat);
+ aoview_state_add_deg("Longitude", state->lon);
+ aoview_table_add_row("GPS alt", "%d", state->alt);
+ aoview_table_add_row("GPS time", "%02d:%02d:%02d",
+ state->gps_time.hour,
+ state->gps_time.minute,
+ state->gps_time.second);
+ aoview_great_circle(pad_lat, pad_lon, state->lat, state->lon,
+ &dist, &bearing);
+ aoview_table_add_row("Distance from pad", "%gm", dist * 1000);
+ aoview_table_add_row("Direction from pad", "%g°", bearing);
+ } else {
+ aoview_table_add_row("GPS", "unlocked");
+ }
+ aoview_table_finish();
}
void