Switch from GPLv2 to GPLv2+
[fw/altos] / src / kernel / ao_telemetry.c
index 868b3260a52ae9f7fd4362a4a49264dfdcff007d..e70791792d5644c30ab5745ee2d8a7966648beda 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -75,6 +76,13 @@ static __pdata uint16_t ao_aprs_time;
 
 static __xdata union ao_telemetry_all  telemetry;
 
+static void
+ao_telemetry_send(void)
+{
+       ao_radio_send(&telemetry, sizeof (telemetry));
+       ao_delay(1);
+}
+
 #if defined AO_TELEMETRY_SENSOR
 /* Send sensor packet */
 static void
@@ -117,7 +125,7 @@ ao_send_sensor(void)
        telemetry.sensor.accel_minus_g = 0;
 #endif
 
-       ao_radio_send(&telemetry, sizeof (telemetry));
+       ao_telemetry_send();
 }
 #endif
 
@@ -133,7 +141,9 @@ ao_send_mega_sensor(void)
        telemetry.generic.tick = packet->tick;
        telemetry.generic.type = AO_TELEMETRY_MEGA_SENSOR;
 
+#if HAS_MPU6000
        telemetry.mega_sensor.orient = ao_sample_orient;
+#endif
        telemetry.mega_sensor.accel = ao_data_accel(packet);
        telemetry.mega_sensor.pres = ao_data_pres(packet);
        telemetry.mega_sensor.temp = ao_data_temp(packet);
@@ -154,7 +164,7 @@ ao_send_mega_sensor(void)
        telemetry.mega_sensor.mag_z = packet->hmc5883.z;
 #endif
 
-       ao_radio_send(&telemetry, sizeof (telemetry));
+       ao_telemetry_send();
 }
 
 static __pdata int8_t ao_telemetry_mega_data_max;
@@ -188,8 +198,8 @@ ao_send_mega_data(void)
                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;
+               ao_telemetry_send();
        }
 }
 #endif /* AO_SEND_MEGA */
@@ -219,7 +229,7 @@ ao_send_metrum_sensor(void)
        telemetry.metrum_sensor.sense_a = packet->adc.sense_a;
        telemetry.metrum_sensor.sense_m = packet->adc.sense_m;
 
-       ao_radio_send(&telemetry, sizeof (telemetry));
+       ao_telemetry_send();
 }
 
 static __pdata int8_t ao_telemetry_metrum_data_max;
@@ -246,8 +256,8 @@ ao_send_metrum_data(void)
                telemetry.metrum_data.accel_minus_g = 2;
 #endif
 
-               ao_radio_send(&telemetry, sizeof (telemetry));
                ao_telemetry_metrum_data_cur = ao_telemetry_metrum_data_max;
+               ao_telemetry_send();
        }
 }
 #endif /* AO_SEND_METRUM */
@@ -277,7 +287,7 @@ ao_send_mini(void)
 
        telemetry.mini.ground_pres = ao_ground_pres;
 
-       ao_radio_send(&telemetry, sizeof (telemetry));
+       ao_telemetry_send();
 }
 
 #endif /* AO_SEND_MINI */
@@ -314,8 +324,8 @@ ao_send_configuration(void)
                ao_xmemcpy (telemetry.configuration.version,
                            CODE_TO_XDATA(ao_version),
                            AO_MAX_VERSION);
-               ao_radio_send(&telemetry, sizeof (telemetry));
                ao_telemetry_config_cur = ao_telemetry_config_max;
+               ao_telemetry_send();
        }
 }
 
@@ -337,8 +347,8 @@ ao_send_location(void)
                       27);
                telemetry.location.tick = ao_gps_tick;
                ao_mutex_put(&ao_gps_mutex);
-               ao_radio_send(&telemetry, sizeof (telemetry));
                ao_telemetry_loc_cur = ao_telemetry_gps_max;
+               ao_telemetry_send();
        }
 }
 
@@ -354,8 +364,8 @@ ao_send_satellite(void)
                       &ao_gps_tracking_data.sats,
                       AO_MAX_GPS_TRACKING * sizeof (struct ao_telemetry_satellite_info));
                ao_mutex_put(&ao_gps_mutex);
-               ao_radio_send(&telemetry, sizeof (telemetry));
                ao_telemetry_sat_cur = ao_telemetry_gps_max;
+               ao_telemetry_send();
        }
 }
 #endif
@@ -378,8 +388,8 @@ ao_send_companion(void)
                       ao_companion_data,
                       ao_companion_setup.channels * 2);
                ao_mutex_put(&ao_companion_mutex);
-               ao_radio_send(&telemetry, sizeof (telemetry));
                ao_telemetry_companion_cur = ao_telemetry_companion_max;
+               ao_telemetry_send();
        }
 }
 #endif
@@ -484,9 +494,7 @@ ao_telemetry(void)
 #endif /* HAS_APRS */
                        delay = time - ao_time();
                        if (delay > 0) {
-                               ao_alarm(delay);
-                               ao_sleep(&telemetry);
-                               ao_clear_alarm();
+                               ao_sleep_for(&telemetry, delay);
                        }
                }
        }