2 * Copyright © 2011 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.
19 #include "ao_product.h"
21 static __pdata uint16_t ao_telemetry_interval;
22 static __pdata int8_t ao_telemetry_config_max;
23 static __pdata int8_t ao_telemetry_config_cur;
25 static __pdata int8_t ao_telemetry_loc_cur;
26 static __pdata int8_t ao_telemetry_sat_cur;
28 static __pdata uint8_t ao_rdf = 0;
29 static __pdata uint16_t ao_rdf_time;
31 #define AO_RDF_INTERVAL_TICKS AO_SEC_TO_TICKS(5)
32 #define AO_RDF_LENGTH_MS 500
34 #if defined(TELEMETRUM_V_0_1) || defined(TELEMETRUM_V_0_2) || defined(TELEMETRUM_V_1_0) || defined(TELEMETRUM_V_1_1)
35 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELEMETRUM
38 #if defined(TELEMINI_V_1_0)
39 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELEMINI
42 #if defined(TELENANO_V_0_1)
43 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELENANO
46 static __xdata union ao_telemetry_all telemetry;
48 /* Send sensor packet */
53 sample = ao_sample_adc;
55 telemetry.generic.tick = ao_adc_ring[sample].tick;
56 telemetry.generic.type = AO_TELEMETRY_SENSOR;
58 telemetry.sensor.state = ao_flight_state;
60 telemetry.sensor.accel = ao_adc_ring[sample].accel;
62 telemetry.sensor.accel = 0;
64 telemetry.sensor.pres = ao_adc_ring[sample].pres;
65 telemetry.sensor.temp = ao_adc_ring[sample].temp;
66 telemetry.sensor.v_batt = ao_adc_ring[sample].v_batt;
68 telemetry.sensor.sense_d = ao_adc_ring[sample].sense_d;
69 telemetry.sensor.sense_m = ao_adc_ring[sample].sense_m;
71 telemetry.sensor.sense_d = 0;
72 telemetry.sensor.sense_m = 0;
75 telemetry.sensor.acceleration = ao_accel;
76 telemetry.sensor.speed = ao_speed;
77 telemetry.sensor.height = ao_height;
79 telemetry.sensor.ground_pres = ao_ground_pres;
81 telemetry.sensor.ground_accel = ao_ground_accel;
82 telemetry.sensor.accel_plus_g = ao_config.accel_plus_g;
83 telemetry.sensor.accel_minus_g = ao_config.accel_minus_g;
85 telemetry.sensor.ground_accel = 0;
86 telemetry.sensor.accel_plus_g = 0;
87 telemetry.sensor.accel_minus_g = 0;
90 ao_radio_send(&telemetry, sizeof (telemetry));
94 ao_send_configuration(void)
96 if (--ao_telemetry_config_cur <= 0)
98 telemetry.generic.type = AO_TELEMETRY_CONFIGURATION;
99 telemetry.configuration.device = AO_idProduct_NUMBER;
100 telemetry.configuration.flight = ao_flight_number;
101 telemetry.configuration.config_major = AO_CONFIG_MAJOR;
102 telemetry.configuration.config_minor = AO_CONFIG_MINOR;
103 telemetry.configuration.apogee_delay = ao_config.apogee_delay;
104 telemetry.configuration.main_deploy = ao_config.main_deploy;
105 telemetry.configuration.flight_log_max = ao_config.flight_log_max >> 10;
106 memcpy (telemetry.configuration.callsign,
109 memcpy (telemetry.configuration.version,
112 ao_radio_send(&telemetry, sizeof (telemetry));
113 ao_telemetry_config_cur = ao_telemetry_config_max;
119 ao_send_location(void)
121 if (--ao_telemetry_loc_cur <= 0)
123 telemetry.generic.type = AO_TELEMETRY_LOCATION;
124 ao_mutex_get(&ao_gps_mutex);
125 memcpy(&telemetry.location.flags,
128 ao_mutex_put(&ao_gps_mutex);
129 ao_radio_send(&telemetry, sizeof (telemetry));
130 ao_telemetry_loc_cur = ao_telemetry_config_max;
135 ao_send_satellite(void)
137 if (--ao_telemetry_sat_cur <= 0)
139 telemetry.generic.type = AO_TELEMETRY_SATELLITE;
140 ao_mutex_get(&ao_gps_mutex);
141 telemetry.satellite.channels = ao_gps_tracking_data.channels;
142 memcpy(&telemetry.satellite.sats,
143 &ao_gps_tracking_data.sats,
144 AO_MAX_GPS_TRACKING * sizeof (struct ao_telemetry_satellite_info));
145 ao_mutex_put(&ao_gps_mutex);
146 ao_radio_send(&telemetry, sizeof (telemetry));
147 ao_telemetry_sat_cur = ao_telemetry_config_max;
159 while (!ao_flight_number)
160 ao_sleep(&ao_flight_number);
162 telemetry.generic.serial = ao_serial_number;
164 while (ao_telemetry_interval == 0)
165 ao_sleep(&telemetry);
166 time = ao_rdf_time = ao_time();
167 while (ao_telemetry_interval) {
171 ao_send_configuration();
177 (int16_t) (ao_time() - ao_rdf_time) >= 0)
179 ao_rdf_time = ao_time() + AO_RDF_INTERVAL_TICKS;
180 ao_radio_rdf(AO_RDF_LENGTH_MS);
182 time += ao_telemetry_interval;
183 delay = time - ao_time();
193 ao_telemetry_set_interval(uint16_t interval)
195 ao_telemetry_interval = interval;
196 ao_telemetry_config_max = AO_SEC_TO_TICKS(1) / interval;
197 ao_telemetry_config_cur = 1;
199 ao_telemetry_loc_cur = 1;
200 if (ao_telemetry_config_max > ao_telemetry_loc_cur)
201 ao_telemetry_loc_cur++;
202 ao_telemetry_sat_cur = ao_telemetry_loc_cur;
203 if (ao_telemetry_config_max > ao_telemetry_sat_cur)
204 ao_telemetry_sat_cur++;
206 ao_wakeup(&telemetry);
210 ao_rdf_set(uint8_t rdf)
214 ao_radio_rdf_abort();
216 ao_rdf_time = ao_time();
219 __xdata struct ao_task ao_telemetry_task;
224 ao_add_task(&ao_telemetry_task, ao_telemetry, "telemetry");