2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 static int pad_pres_total;
25 static int pad_accel_total;
26 static double pad_lat_total;
27 static double pad_lon_total;
28 static int pad_alt_total;
31 static double prev_accel;
32 static double velocity;
33 static double pad_lat;
34 static double pad_lon;
35 static double pad_alt;
37 #define NUM_PAD_SAMPLES 50
42 aoview_great_circle (double start_lat, double start_lon,
43 double end_lat, double end_lon,
44 double *dist, double *bearing)
46 double rad = M_PI / 180;
47 double earth_radius = 6371.2;
48 double lat1 = rad * start_lat;
49 double lon1 = -rad * start_lon;
50 double lat2 = rad * end_lat;
51 double lon2 = -rad * end_lon;
53 double d = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
54 double argacos = (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1));
56 if (sin(lon2-lon1) < 0)
59 crs = 2 * M_PI - acos(argacos);
60 *dist = d * earth_radius;
61 *bearing = crs * 180/M_PI;
65 aoview_state_add_deg(char *label, double deg)
70 int_part = floor (deg);
71 min = (deg - int_part) * 60.0;
72 aoview_table_add_row(label, "%d°%lf'",
78 aoview_state_notify(struct aostate *state)
82 double velocity_change;
88 double drogue_sense, main_sense;
90 if (!strcmp(state->state, "pad")) {
91 if (npad < NUM_PAD_SAMPLES) {
92 pad_accel_total += state->accel;
93 pad_pres_total += state->pres;
94 pad_lat_total += state->lat;
95 pad_lon_total += state->lon;
96 pad_alt_total += state->alt;
100 if (npad <= NUM_PAD_SAMPLES) {
101 pad_pres = pad_pres_total / npad;
102 pad_accel = pad_accel_total / npad;
103 pad_lat = pad_lat_total / npad;
104 pad_lon = pad_lon_total / npad;
105 pad_alt = pad_alt_total / npad;
108 altitude = aoview_pres_to_altitude(state->pres) - aoview_pres_to_altitude(pad_pres);
109 accel = (pad_accel - state->accel) / 264.8 * 9.80665;
110 velocity_change = (accel + prev_accel) / 2.0;
111 ticks = state->tick - prev_tick;
112 velocity -= velocity_change * (ticks / 100.0);
113 temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
114 battery = (state->batt / 32767.0 * 5.0);
115 drogue_sense = (state->drogue / 32767.0 * 15.0);
116 main_sense = (state->main / 32767.0 * 15.0);
119 prev_tick = state->tick;
120 aoview_table_start();
121 aoview_table_add_row("RSSI", "%ddB", state->rssi);
122 aoview_table_add_row("Height", "%dm", altitude);
123 aoview_table_add_row("Acceleration", "%gm/s²", accel);
124 aoview_table_add_row("Velocity", "%gm/s", velocity);
125 aoview_table_add_row("Temperature", "%g°C", temp);
126 aoview_table_add_row("Battery", "%gV", battery);
127 aoview_table_add_row("Drogue", "%gV", drogue_sense);
128 aoview_table_add_row("Main", "%gV", main_sense);
129 aoview_table_add_row("Pad altitude", "%dm", aoview_pres_to_altitude(pad_pres));
130 aoview_table_add_row("Satellites", "%d", state->nsat);
132 aoview_state_add_deg("Latitude", state->lat);
133 aoview_state_add_deg("Longitude", state->lon);
134 aoview_table_add_row("GPS alt", "%d", state->alt);
135 aoview_table_add_row("GPS time", "%02d:%02d:%02d",
136 state->gps_time.hour,
137 state->gps_time.minute,
138 state->gps_time.second);
139 aoview_great_circle(pad_lat, pad_lon, state->lat, state->lon,
141 aoview_table_add_row("Distance from pad", "%gm", dist * 1000);
142 aoview_table_add_row("Direction from pad", "%g°", bearing);
144 aoview_table_add_row("GPS", "unlocked");
146 aoview_table_finish();
150 aoview_state_init(GladeXML *xml)