No bugs noted, just adding casts to resolve -Wconversion warnings.
Signed-off-by: Keith Packard <keithp@keithp.com>
#define AO_BEEP_MID_PANIC AO_BEEP_MID_DEFAULT
#ifndef AO_BEEP_MAKE_LOW
#define AO_BEEP_MID_PANIC AO_BEEP_MID_DEFAULT
#ifndef AO_BEEP_MAKE_LOW
-#define AO_BEEP_MAKE_LOW(m) ((m) * 150 / 94) /* 2500Hz */
+#define AO_BEEP_MAKE_LOW(m) ((uint8_t) ((m) * 150 / 94)) /* 2500Hz */
#endif
#ifndef AO_BEEP_MAKE_HIGH
#endif
#ifndef AO_BEEP_MAKE_HIGH
-#define AO_BEEP_MAKE_HIGH(m) ((m) * 75 / 94) /* 5000Hz */
+#define AO_BEEP_MAKE_HIGH(m) ((uint8_t) ((m) * 75 / 94)) /* 5000Hz */
#endif
#define AO_BEEP_LOW AO_BEEP_MAKE_LOW(AO_BEEP_MID)
#endif
#define AO_BEEP_LOW AO_BEEP_MAKE_LOW(AO_BEEP_MID)
void
ao_cmd_put16(uint16_t v)
{
void
ao_cmd_put16(uint16_t v)
{
- ao_cmd_put8(v >> 8);
- ao_cmd_put8(v);
+ ao_cmd_put8((uint8_t) (v >> 8));
+ ao_cmd_put8((uint8_t) v);
ao_cmd_hexchar(char c)
{
if ('0' <= c && c <= '9')
ao_cmd_hexchar(char c)
{
if ('0' <= c && c <= '9')
+ return (int8_t) (c - '0');
if ('a' <= c && c <= 'f')
if ('a' <= c && c <= 'f')
+ return (int8_t) (c - 'a' + 10);
if ('A' <= c && c <= 'F')
if ('A' <= c && c <= 'F')
+ return (int8_t) (c - 'A' + 10);
ao_cmd_status = ao_cmd_lex_error;
break;
}
ao_cmd_status = ao_cmd_lex_error;
break;
}
- result = (result << 4) | n;
+ result = (uint32_t) ((result << 4) | (uint32_t) n);
ao_cmd_lex();
}
return result;
ao_cmd_lex();
}
return result;
uint8_t
ao_cmd_hexbyte(void)
{
uint8_t
ao_cmd_hexbyte(void)
{
+ return (uint8_t) get_hex(2);
uint8_t cmd;
const struct ao_cmds * cs;
const char *h;
uint8_t cmd;
const struct ao_cmds * cs;
const char *h;
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
#define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
#endif
#define AO_CONFIG_DEFAULT_RADIO_AMP 0
#define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
#endif
#define AO_CONFIG_DEFAULT_RADIO_AMP 0
-#define AO_CONFIG_DEFAULT_APRS_SSID (ao_serial_number % 10)
+#define AO_CONFIG_DEFAULT_APRS_SSID ((uint8_t) (ao_serial_number % 10))
#define AO_CONFIG_DEFAULT_RADIO_RATE AO_RADIO_RATE_38400
#if HAS_CONFIG_SAVE
#define AO_CONFIG_DEFAULT_RADIO_RATE AO_RADIO_RATE_38400
#if HAS_CONFIG_SAVE
if (minor < 9)
memset(&ao_config.aes_key, '\0', AO_AES_LEN);
if (minor < 10)
if (minor < 9)
memset(&ao_config.aes_key, '\0', AO_AES_LEN);
if (minor < 10)
- ao_config.frequency = 434550 + ao_config._legacy_radio_channel * 100;
+ ao_config.frequency = 434550U + ao_config._legacy_radio_channel * 100U;
if (minor < 11)
ao_config.apogee_lockout = 0;
#if AO_PYRO_NUM
if (minor < 11)
ao_config.apogee_lockout = 0;
#if AO_PYRO_NUM
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.main_deploy = r;
+ ao_config.main_deploy = (uint16_t) r;
_ao_config_edit_finish();
}
_ao_config_edit_finish();
}
- accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT;
- accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT;
- accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT;
+ accel_cal_along = (int16_t) (accel_along_total >> ACCEL_CALIBRATE_SHIFT);
+ accel_cal_across = (int16_t) (accel_across_total >> ACCEL_CALIBRATE_SHIFT);
+ accel_cal_through = (int16_t) (accel_through_total >> ACCEL_CALIBRATE_SHIFT);
- return accel_total >> ACCEL_CALIBRATE_SHIFT;
+ return (int16_t) (accel_total >> ACCEL_CALIBRATE_SHIFT);
int16_t accel_through_up = 0, accel_through_down = 0;
#endif
int16_t accel_through_up = 0, accel_through_down = 0;
#endif
+ up = (int16_t) ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
if (ao_cmd_status != ao_cmd_success)
return;
- down = ao_cmd_decimal();
+ down = (int16_t) ao_cmd_decimal();
auto_cal = (up == 0 && ao_cmd_status != ao_cmd_success);
if (auto_cal) {
up = ao_config_accel_calibrate_auto("up");
auto_cal = (up == 0 && ao_cmd_status != ao_cmd_success);
if (auto_cal) {
up = ao_config_accel_calibrate_auto("up");
ao_config.accel_minus_g = down;
#if HAS_IMU
if (auto_cal) {
ao_config.accel_minus_g = down;
#if HAS_IMU
if (auto_cal) {
- ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2;
- ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2;
- ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2;
+ ao_config.accel_zero_along = (int16_t) ((accel_along_up + accel_along_down) / 2);
+ ao_config.accel_zero_across = (int16_t) ((accel_across_up + accel_across_down) / 2);
+ ao_config.accel_zero_through = (int16_t) ((accel_through_up + accel_through_down) / 2);
+ v = (int16_t) ao_cmd_decimal();
if (ao_cmd_status == ao_cmd_success) {
ao_config.accel_zero_along = v;
if (ao_cmd_status == ao_cmd_success) {
ao_config.accel_zero_along = v;
+ v = (int16_t) ao_cmd_decimal();
if (ao_cmd_status == ao_cmd_success) {
ao_config.accel_zero_across = v;
if (ao_cmd_status == ao_cmd_success) {
ao_config.accel_zero_across = v;
+ v = (int16_t) ao_cmd_decimal();
if (ao_cmd_status == ao_cmd_success)
ao_config.accel_zero_through = v;
}
if (ao_cmd_status == ao_cmd_success)
ao_config.accel_zero_through = v;
}
uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
+ if (r > 255) {
+ ao_cmd_status = ao_cmd_lex_error;
+ return;
+ }
- ao_config.apogee_delay = r;
+ ao_config.apogee_delay = (uint8_t) r;
_ao_config_edit_finish();
}
_ao_config_edit_finish();
}
static void
ao_config_apogee_lockout_set(void)
{
static void
ao_config_apogee_lockout_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
if (ao_cmd_status != ao_cmd_success)
return;
+ if (r > 65535) {
+ ao_cmd_status = ao_cmd_lex_error;
+ return;
+ }
- ao_config.apogee_lockout = r;
+ ao_config.apogee_lockout = (uint16_t) r;
_ao_config_edit_finish();
}
#endif
_ao_config_edit_finish();
}
#endif
static void
ao_config_radio_rate_set(void)
{
static void
ao_config_radio_rate_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
if (AO_RADIO_RATE_MAX < r) {
if (ao_cmd_status != ao_cmd_success)
return;
if (AO_RADIO_RATE_MAX < r) {
return;
}
_ao_config_edit_start();
return;
}
_ao_config_edit_start();
- ao_config.radio_rate = r;
+ ao_config.radio_rate = (uint8_t) r;
_ao_config_edit_finish();
#if HAS_TELEMETRY
ao_telemetry_reset_interval();
_ao_config_edit_finish();
#if HAS_TELEMETRY
ao_telemetry_reset_interval();
static void
ao_config_ignite_mode_set(void)
{
static void
ao_config_ignite_mode_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.ignite_mode = r;
+ ao_config.ignite_mode = (uint8_t) r;
_ao_config_edit_finish();
}
#endif
_ao_config_edit_finish();
}
#endif
static void
ao_config_pad_orientation_set(void)
{
static void
ao_config_pad_orientation_set(void)
{
- uint16_t r = ao_cmd_decimal() & 1;
+ uint8_t r = ao_cmd_decimal() & 1;
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
static void
ao_config_radio_enable_set(void)
{
static void
ao_config_radio_enable_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.radio_enable = r;
+ ao_config.radio_enable = r != 0;
_ao_config_edit_finish();
#if HAS_TELEMETRY && HAS_RADIO_RATE
ao_telemetry_reset_interval();
_ao_config_edit_finish();
#if HAS_TELEMETRY && HAS_RADIO_RATE
ao_telemetry_reset_interval();
static void
ao_config_aprs_set(void)
{
static void
ao_config_aprs_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.aprs_interval = r;
+ ao_config.aprs_interval = (uint16_t) r;
_ao_config_edit_finish();
ao_telemetry_reset_interval();
}
_ao_config_edit_finish();
ao_telemetry_reset_interval();
}
static void
ao_config_aprs_offset_set(void)
{
static void
ao_config_aprs_offset_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.aprs_offset = r;
+ ao_config.aprs_offset = (uint8_t) r;
_ao_config_edit_finish();
ao_telemetry_reset_interval();
}
_ao_config_edit_finish();
ao_telemetry_reset_interval();
}
static void
ao_config_beep_set(void)
{
static void
ao_config_beep_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.mid_beep = r;
+ ao_config.mid_beep = (uint8_t) r;
_ao_config_edit_finish();
}
#endif
_ao_config_edit_finish();
}
#endif
static void
ao_config_tracker_set(void)
{
static void
ao_config_tracker_set(void)
{
- uint16_t m, i;
- m = ao_cmd_decimal();
+ uint16_t m;
+ uint8_t i;
+ m = (uint16_t) ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
if (ao_cmd_status != ao_cmd_success)
return;
+ i = (uint8_t) ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
static void
ao_config_pyro_time_set(void)
{
static void
ao_config_pyro_time_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.pyro_time = r;
+ ao_config.pyro_time = (uint16_t) r;
_ao_config_edit_finish();
}
#endif
_ao_config_edit_finish();
}
#endif
static void
ao_config_aprs_ssid_set(void)
{
static void
ao_config_aprs_ssid_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
if (15 < r) {
if (ao_cmd_status != ao_cmd_success)
return;
if (15 < r) {
return;
}
_ao_config_edit_start();
return;
}
_ao_config_edit_start();
- ao_config.aprs_ssid = r;
+ ao_config.aprs_ssid = (uint8_t) r;
_ao_config_edit_finish();
}
static void
ao_config_aprs_format_set(void)
{
_ao_config_edit_finish();
}
static void
ao_config_aprs_format_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
static void
ao_config_pad_box_set(void)
{
static void
ao_config_pad_box_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
+ ao_config.pad_box = (uint8_t) r;
_ao_config_edit_finish();
}
_ao_config_edit_finish();
}
static void
ao_config_pad_idle_set(void)
{
static void
ao_config_pad_idle_set(void)
{
- uint16_t r = ao_cmd_decimal();
+ uint32_t r = ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
if (ao_cmd_status != ao_cmd_success)
return;
_ao_config_edit_start();
- ao_config.pad_idle = r;
+ ao_config.pad_idle = (uint8_t) r;
_ao_config_edit_finish();
}
#endif
_ao_config_edit_finish();
}
#endif
int16_t
ao_battery_decivolt(int16_t adc)
{
int16_t
ao_battery_decivolt(int16_t adc)
{
- return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
+ return (int16_t) scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
int16_t
ao_ignite_decivolt(int16_t adc)
{
int16_t
ao_ignite_decivolt(int16_t adc)
{
- return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
+ return (int16_t) scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
#define ao_data_pres_cook(packet) ao_ms5607_convert(&packet->ms5607_raw, &packet->ms5607_cooked)
#define ao_data_pres(packet) ((packet)->ms5607_cooked.pres)
#define ao_data_pres_cook(packet) ao_ms5607_convert(&packet->ms5607_raw, &packet->ms5607_cooked)
#define ao_data_pres(packet) ((packet)->ms5607_cooked.pres)
-#define ao_data_temp(packet) ((packet)->ms5607_cooked.temp)
+#define ao_data_temp(packet) ((int16_t) (packet)->ms5607_cooked.temp)
#define pres_to_altitude(p) ao_pa_to_altitude(p)
#define pres_to_altitude(p) ao_pa_to_altitude(p)
#endif
#if AO_MMA655X_INVERT
#endif
#if AO_MMA655X_INVERT
-#define ao_data_accel_raw(packet) (AO_ACCEL_INVERT - (packet)->mma655x)
+#define ao_data_accel_raw(packet) ((accel_t) (AO_ACCEL_INVERT - (packet)->mma655x))
-#define ao_data_accel_raw(packet) ((packet)->mma655x)
+#define ao_data_accel_raw(packet) ((accel_t) (packet)->mma655x)
#endif
#define ao_data_accel_invert(accel) (AO_ACCEL_INVERT - (accel))
#endif
#define ao_data_accel_invert(accel) (AO_ACCEL_INVERT - (accel))
/* check if it's shorter to go the other way around */
if ((lon_a >> 1) < (lon_b >> 1) - (1800000000 >> 1))
/* check if it's shorter to go the other way around */
if ((lon_a >> 1) < (lon_b >> 1) - (1800000000 >> 1))
+ lon_a = (int32_t) ((uint32_t) lon_a + 3600000000UL);
lon_dist = ao_dist(lon_a, lon_b);
if (c) {
if (lon_dist & 0x7f800000)
lon_dist = ao_dist(lon_a, lon_b);
if (c) {
if (lon_dist & 0x7f800000)
for (bit = 0; bit < 8; bit++) {
if (((crc & 0x8000) >> 8) ^ (byte & 0x80))
for (bit = 0; bit < 8; bit++) {
if (((crc & 0x8000) >> 8) ^ (byte & 0x80))
- crc = (crc << 1) ^ 0x8005;
+ crc = (uint16_t) ((crc << 1) ^ 0x8005);
+ byte = (uint8_t) (byte << 1);
};
static inline uint16_t ao_interleave_index(uint16_t i) {
};
static inline uint16_t ao_interleave_index(uint16_t i) {
- return (i & ~0x1e) | ao_interleave_order[(i & 0x1e) >> 1];
+ return (uint16_t) ((i & ~0x1e) | ao_interleave_order[(i & 0x1e) >> 1]);
* the end of the input, in which case
* it will be seven.
*/
* the end of the input, in which case
* it will be seven.
*/
- int8_t dist = b - (o + 8); /* distance to last ready-for-writing bit */
+ int8_t dist = (int8_t) (b - (o + 8)); /* distance to last ready-for-writing bit */
uint32_t min_cost; /* lowest cost */
uint8_t min_state; /* lowest cost state */
uint8_t byte;
uint32_t min_cost; /* lowest cost */
uint8_t min_state; /* lowest cost state */
uint8_t byte;
printf ("\tbit %3d min_cost %5d old bit %3d old_state %x bits %02x whiten %0x\n",
i/2, min_cost, o + 8, min_state, (bits[p][min_state] >> dist) & 0xff, *whiten);
#endif
printf ("\tbit %3d min_cost %5d old bit %3d old_state %x bits %02x whiten %0x\n",
i/2, min_cost, o + 8, min_state, (bits[p][min_state] >> dist) & 0xff, *whiten);
#endif
- byte = (bits[p][min_state] >> dist) ^ *whiten++;
+ byte = (uint8_t) ((bits[p][min_state] >> dist) ^ *whiten++);
*out++ = byte;
if (out_len > 2)
crc = ao_fec_crc_byte(byte, crc);
*out++ = byte;
if (out_len > 2)
crc = ao_fec_crc_byte(byte, crc);
ao_fec_check_crc(const uint8_t *bytes, uint8_t len)
{
uint16_t computed_crc = ao_fec_crc(bytes, len);
ao_fec_check_crc(const uint8_t *bytes, uint8_t len)
{
uint16_t computed_crc = ao_fec_crc(bytes, len);
- uint16_t received_crc = (bytes[len] << 8) | (bytes[len+1]);
+ uint16_t received_crc = (uint16_t) ((bytes[len] << 8) | (bytes[len+1]));
return computed_crc == received_crc;
}
return computed_crc == received_crc;
}
uint8_t num_fec;
/* Append CRC */
uint8_t num_fec;
/* Append CRC */
- extra[i++] = crc >> 8;
- extra[i++] = crc;
+ extra[i++] = (uint8_t) (crc >> 8);
+ extra[i++] = (uint8_t) crc;
/* Append FEC -- 1 byte if odd, two bytes if even */
num_fec = 2 - (i & 1);
/* Append FEC -- 1 byte if odd, two bytes if even */
num_fec = 2 - (i & 1);
for (byte = 0; byte < 2; byte++) {
if (pair + byte == len)
in = extra;
for (byte = 0; byte < 2; byte++) {
if (pair + byte == len)
in = extra;
- fec |= *in++ ^ *whiten++;
+ fec |= (uint16_t) (*in++ ^ *whiten++);
for (bit = 0; bit < 8; bit++) {
encode = encode << 2 | ao_fec_encode_table[fec >> 7];
fec = (fec << 1) & 0x7ff;
for (bit = 0; bit < 8; bit++) {
encode = encode << 2 | ao_fec_encode_table[fec >> 7];
fec = (fec << 1) & 0x7ff;
interleave = (interleave << 2) | ((encode >> (byte_shift + bit_shift)) & 0x3);
}
interleave = (interleave << 2) | ((encode >> (byte_shift + bit_shift)) & 0x3);
}
- *out++ = interleave >> 24;
- *out++ = interleave >> 16;
- *out++ = interleave >> 8;
- *out++ = interleave >> 0;
+ *out++ = (uint8_t) (interleave >> 24);
+ *out++ = (uint8_t) (interleave >> 16);
+ *out++ = (uint8_t) (interleave >> 8);
+ *out++ = (uint8_t) (interleave >> 0);
- return (len + extra_len) * 2;
+ return (uint8_t) ((len + extra_len) * 2);
accel = (ao_config.accel_plus_g - ao_sample_accel) * ao_accel_scale;
/* Can't use ao_accel here as it is the pre-prediction value still */
accel = (ao_config.accel_plus_g - ao_sample_accel) * ao_accel_scale;
/* Can't use ao_accel here as it is the pre-prediction value still */
- ao_error_a = (accel - ao_k_accel) >> 16;
+ ao_error_a = (ao_v_t) ((accel - ao_k_accel) >> 16);
}
#if !defined(FORCE_ACCEL) && HAS_BARO
}
#if !defined(FORCE_ACCEL) && HAS_BARO
ao_avg_height = (ao_avg_height_scaled + 7) >> 4;
else
#endif
ao_avg_height = (ao_avg_height_scaled + 7) >> 4;
else
#endif
- ao_avg_height = (ao_avg_height_scaled + 63) >> 7;
+ ao_avg_height = (ao_v_t) ((ao_avg_height_scaled + 63) >> 7);