fn fired(&self) {
        let now = self.alarm.now();

        self.app.each(|app| {
            if let Expiration::Abs(exp) = app.alarm_data.expiration {
                let expired =
                    now.wrapping_sub(app.alarm_data.t0) >= exp.wrapping_sub(app.alarm_data.t0);
                if expired {
                    if self.busy.get() {
                        // The radio is currently busy, so we won't be able to start the
                        // operation at the appropriate time. Instead, reschedule the
                        // operation for later. This is _kind_ of simulating actual
                        // on-air interference
                        debug!("BLE: operationg delayed for app {:?}", app.appid());
                        app.set_next_alarm::<A::Frequency>(self.alarm.now());
                        return;
                    }

                    match app.process_status {
                        Some(BLEState::AdvertisingIdle) => {
                            self.busy.set(true);
                            app.process_status =
                                Some(BLEState::Advertising(RadioChannel::AdvertisingChannel37));
                            self.sending_app.set(Some(app.appid()));
                            self.radio.set_tx_power(app.tx_power);
                            app.send_advertisement(&self, RadioChannel::AdvertisingChannel37);
                        }
                        Some(BLEState::ScanningIdle) => {
                            self.busy.set(true);
                            app.process_status =
                                Some(BLEState::Scanning(RadioChannel::AdvertisingChannel37));
                            self.receiving_app.set(Some(app.appid()));
                            self.radio.set_tx_power(app.tx_power);
                            self.radio
                                .receive_advertisement(RadioChannel::AdvertisingChannel37);
                        }
                        _ => debug!(
                            "app: {:?} \t invalid state {:?}",
                            app.appid(),
                            app.process_status
                        ),
                    }
                }
            }
        });
        self.reset_active_alarm();
    }
// When an alarm is fired, we find which apps have expired timers. Expired
// timers indicate a desire to perform some operation (e.g. start an
// advertising or scanning event). We know which operation based on the
// current app's state.
//
// In case of collision---if there is already an event happening---we'll
// just delay the operation for next time and hope for the best. Since some
// randomness is added for each period in an app's timer, collisions should
// be rare in practice.
//
// TODO: perhaps break ties more fairly by prioritizing apps that have least
// recently performed an operation.
When an alarm is fired, we find which apps have expired timers. Expired
timers indicate a desire to perform some operation . We know which operation based on the
current app's state.



perhaps break ties more fairly by prioritizing apps that have least
recently performed an operation.
When an alarm is fired we find which apps have expired timers . Expired timers indicate a desire to perform some operation . We know which operation based on the current app ' s state . perhaps break ties more fairly by prioritizing apps that have least recently performed an operation .
fn fired(&self) {
        let now = self.alarm.now();
        self.app.each(|app| {
            if let Expiration::Abs(exp) = app.alarm_data.expiration {
                let expired =
                    now.wrapping_sub(app.alarm_data.t0) >= exp.wrapping_sub(app.alarm_data.t0);
                if expired {
                    if self.busy.get() {
                        // The radio is currently busy, so we won't be able to start the
                        // operation at the appropriate time. Instead, reschedule the
                        // operation for later. This is _kind_ of simulating actual
                        // on-air interference
                        debug!("BLE: operationg delayed for app {:?}", app.appid());
                        app.set_next_alarm::<A::Frequency>(self.alarm.now());
                        return;
                    }
                    match app.process_status {
                        Some(BLEState::AdvertisingIdle) => {
                            self.busy.set(true);
                            app.process_status =
                                Some(BLEState::Advertising(RadioChannel::AdvertisingChannel37));
                            self.sending_app.set(Some(app.appid()));
                            self.radio.set_tx_power(app.tx_power);
                            app.send_advertisement(&self, RadioChannel::AdvertisingChannel37);
                        }
                        Some(BLEState::ScanningIdle) => {
                            self.busy.set(true);
                            app.process_status =
                                Some(BLEState::Scanning(RadioChannel::AdvertisingChannel37));
                            self.receiving_app.set(Some(app.appid()));
                            self.radio.set_tx_power(app.tx_power);
                            self.radio
                                .receive_advertisement(RadioChannel::AdvertisingChannel37);
                        }
                        _ => debug!(
                            "app: {:?} \t invalid state {:?}",
                            app.appid(),
                            app.process_status
                        ),
                    }
                }
            }
        });
        self.reset_active_alarm();
    }
fn fired ( & self ) { let now = self . alarm . now ( ) ; self . app . each ( | app | { if let Expiration :: Abs ( exp ) = app . alarm_data . expiration { let expired = now . wrapping_sub ( app . alarm_data . t0 ) >= exp . wrapping_sub ( app . alarm_data . t0 ) ; if expired { if self . busy . get ( ) { // The radio is currently busy, so we won't be able to start the // operation at the appropriate time. Instead, reschedule the // operation for later. This is _kind_ of simulating actual // on-air interference debug ! ( " " app appid ( ) ) ; app . set_next_alarm :: < A :: Frequency > ( self . alarm . now ( ) ) ; return ; } match app . process_status { Some ( BLEState :: AdvertisingIdle ) => { self . busy . set ( true ) ; app . process_status = Some ( BLEState :: Advertising ( RadioChannel :: AdvertisingChannel37 ) ) ; self . sending_app . set ( Some ( app . appid ( ) ) ) ; self . radio . set_tx_power ( app . tx_power ) ; app . send_advertisement ( & self , RadioChannel :: AdvertisingChannel37 ) ; } Some ( BLEState :: ScanningIdle ) => { self . busy . set ( true ) ; app . process_status = Some ( BLEState :: Scanning ( RadioChannel :: AdvertisingChannel37 ) ) ; self . receiving_app . set ( Some ( app . appid ( ) ) ) ; self . radio . set_tx_power ( app . tx_power ) ; self . radio . receive_advertisement ( RadioChannel :: AdvertisingChannel37 ) ; } _ => debug ! ( " \t " app appid ( ) app process_status ) , } } } } ) ; self . reset_active_alarm ( ) ; }
When an alarm is fired, we find which apps have expired timers.
When an alarm is fired we find which apps have expired timers .
&self
&self