From 4e365f6dffc2c0776e0d7efdf9e697d1a21c4047 Mon Sep 17 00:00:00 2001 From: Karl Knutsson Date: Tue, 7 Oct 2014 22:23:25 +0200 Subject: [PATCH] OP-1530 Use rfm22b_dev->num_channels Use the number of allocated channel from the num_channels field in the pios_rfm22b_dev struct rather than from the maximum number of possible of channels given the configured speed. --- flight/pios/common/pios_rfm22b.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 20b487925..0269cedb2 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -2169,8 +2169,7 @@ static void rfm22_synchronizeClock(struct pios_rfm22b_dev *rfm22b_dev) portTickType start_time = rfm22b_dev->packet_start_ticks; // This packet was transmitted on channel 0, calculate the time delta that will force us to transmit on channel 0 at the time this packet started. - uint8_t num_chan = num_channels[rfm22b_dev->datarate]; - uint16_t frequency_hop_cycle_time = rfm22b_dev->packet_time * num_chan; + uint16_t frequency_hop_cycle_time = rfm22b_dev->packet_time * rfm22b_dev->num_channels; uint16_t time_delta = start_time % frequency_hop_cycle_time; // Calculate the adjustment for the preamble @@ -2232,8 +2231,7 @@ static bool rfm22_timeToSend(struct pios_rfm22b_dev *rfm22b_dev) static uint8_t rfm22_calcChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t index) { // Make sure we don't index outside of the range. - uint8_t num_chan = num_channels[rfm22b_dev->datarate]; - uint8_t idx = index % num_chan; + uint8_t idx = index % rfm22b_dev->num_channels; // Are we switching to a new channel? if (idx != rfm22b_dev->channel_index) { @@ -2271,8 +2269,7 @@ static uint8_t rfm22_calcChannelFromClock(struct pios_rfm22b_dev *rfm22b_dev) portTickType time = rfm22_coordinatorTime(rfm22b_dev, xTaskGetTickCount()); // Divide time into 8ms blocks. Coordinator sends in first 2 ms, and remote send in 5th and 6th ms. // Channel changes occur in the last 2 ms. - uint8_t num_chan = num_channels[rfm22b_dev->datarate]; - uint8_t n = (time / rfm22b_dev->packet_time) % num_chan; + uint8_t n = (time / rfm22b_dev->packet_time) % rfm22b_dev->num_channels; return rfm22_calcChannel(rfm22b_dev, n); }