+
+#ifdef AO_SEND_MEGA
+/* Send mega sensor packet */
+static void
+ao_send_mega_sensor(void)
+{
+ __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
+
+ telemetry.generic.tick = packet->tick;
+ telemetry.generic.type = AO_TELEMETRY_MEGA_SENSOR;
+
+ telemetry.mega_sensor.accel = ao_data_accel(packet);
+ telemetry.mega_sensor.pres = ao_data_pres(packet);
+ telemetry.mega_sensor.temp = ao_data_temp(packet);
+
+#if HAS_MPU6000
+ telemetry.mega_sensor.accel_x = packet->mpu6000.accel_x;
+ telemetry.mega_sensor.accel_y = packet->mpu6000.accel_y;
+ telemetry.mega_sensor.accel_z = packet->mpu6000.accel_z;
+
+ telemetry.mega_sensor.gyro_x = packet->mpu6000.gyro_x;
+ telemetry.mega_sensor.gyro_y = packet->mpu6000.gyro_y;
+ telemetry.mega_sensor.gyro_z = packet->mpu6000.gyro_z;
+#endif
+
+#if HAS_HMC5883
+ telemetry.mega_sensor.mag_x = packet->hmc5883.x;
+ telemetry.mega_sensor.mag_y = packet->hmc5883.y;
+ telemetry.mega_sensor.mag_z = packet->hmc5883.z;
+#endif
+
+ ao_radio_send(&telemetry, sizeof (telemetry));
+}
+
+static __pdata int8_t ao_telemetry_mega_data_max;
+static __pdata int8_t ao_telemetry_mega_data_cur;
+
+/* Send mega data packet */
+static void
+ao_send_mega_data(void)
+{
+ if (--ao_telemetry_mega_data_cur <= 0) {
+ __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
+ uint8_t i;
+
+ telemetry.generic.tick = packet->tick;
+ telemetry.generic.type = AO_TELEMETRY_MEGA_DATA;
+
+ telemetry.mega_data.state = ao_flight_state;
+ telemetry.mega_data.v_batt = packet->adc.v_batt;
+ telemetry.mega_data.v_pyro = packet->adc.v_pbatt;
+
+ /* ADC range is 0-4095, so shift by four to save the high 8 bits */
+ for (i = 0; i < AO_ADC_NUM_SENSE; i++)
+ telemetry.mega_data.sense[i] = packet->adc.sense[i] >> 4;
+
+ telemetry.mega_data.ground_pres = ao_ground_pres;
+ telemetry.mega_data.ground_accel = ao_ground_accel;
+ telemetry.mega_data.accel_plus_g = ao_config.accel_plus_g;
+ telemetry.mega_data.accel_minus_g = ao_config.accel_minus_g;
+
+ telemetry.mega_data.acceleration = ao_accel;
+ telemetry.mega_data.speed = ao_speed;
+ telemetry.mega_data.height = ao_height;
+
+ ao_radio_send(&telemetry, sizeof (telemetry));
+ ao_telemetry_mega_data_cur = ao_telemetry_mega_data_max;
+ }
+}
+#endif /* AO_SEND_MEGA */
+
+#ifdef AO_SEND_METRUM
+/* Send telemetrum sensor packet */
+static void
+ao_send_metrum_sensor(void)
+{
+ __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
+
+ telemetry.generic.type = AO_TELEMETRY_METRUM_SENSOR;
+
+ telemetry.metrum_sensor.state = ao_flight_state;
+ telemetry.metrum_sensor.accel = ao_data_accel(packet);
+ telemetry.metrum_sensor.pres = ao_data_pres(packet);
+ telemetry.metrum_sensor.temp = ao_data_temp(packet);
+
+ telemetry.metrum_sensor.acceleration = ao_accel;
+ telemetry.metrum_sensor.speed = ao_speed;
+ telemetry.metrum_sensor.height = ao_height;
+
+ telemetry.metrum_sensor.v_batt = packet->adc.v_batt;
+ telemetry.metrum_sensor.sense_a = packet->adc.sense_a;
+ telemetry.metrum_sensor.sense_m = packet->adc.sense_m;
+
+ ao_radio_send(&telemetry, sizeof (telemetry));
+}
+
+static __pdata int8_t ao_telemetry_metrum_data_max;
+static __pdata int8_t ao_telemetry_metrum_data_cur;
+
+/* Send telemetrum data packet */
+static void
+ao_send_metrum_data(void)
+{
+ if (--ao_telemetry_metrum_data_cur <= 0) {
+ __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
+ uint8_t i;
+
+ telemetry.generic.tick = packet->tick;
+ telemetry.generic.type = AO_TELEMETRY_METRUM_DATA;
+
+ telemetry.metrum_data.ground_pres = ao_ground_pres;
+ telemetry.metrum_data.ground_accel = ao_ground_accel;
+ telemetry.metrum_data.accel_plus_g = ao_config.accel_plus_g;
+ telemetry.metrum_data.accel_minus_g = ao_config.accel_minus_g;
+
+ ao_radio_send(&telemetry, sizeof (telemetry));
+ ao_telemetry_metrum_data_cur = ao_telemetry_metrum_data_max;
+ }
+}
+#endif /* AO_SEND_METRUM */
+
+#ifdef AO_SEND_MINI
+
+static void
+ao_send_mini(void)
+{
+ __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
+
+ telemetry.generic.tick = packet->tick;
+ telemetry.generic.type = AO_TELEMETRY_MINI;
+
+ telemetry.mini.state = ao_flight_state;
+
+ telemetry.mini.v_batt = packet->adc.v_batt;
+ telemetry.mini.sense_a = packet->adc.sense_a;
+ telemetry.mini.sense_m = packet->adc.sense_m;
+
+ telemetry.mini.pres = ao_data_pres(packet);
+ telemetry.mini.temp = ao_data_temp(packet);
+
+ telemetry.mini.acceleration = ao_accel;
+ telemetry.mini.speed = ao_speed;
+ telemetry.mini.height = ao_height;
+
+ telemetry.mini.ground_pres = ao_ground_pres;
+
+ ao_radio_send(&telemetry, sizeof (telemetry));
+}
+
+#endif /* AO_SEND_MINI */