- // valid beacon timestamp is pre-condition for slotted CSMA-CA
- if (m_beaconSwapBufferReady || !call Frame.isTimestampValid(m_beaconBufferPtr)){
- // missed a beacon!
- m_numBeaconsLost++;
- m_dt += m_beaconInterval;
- call Debug.log(LEVEL_IMPORTANT, SyncP_BEACON_MISSED_3,m_numBeaconsLost,0,m_lastBeaconRxTime);
- if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons){
- m_tracking = FALSE;
- call Debug.log(LEVEL_IMPORTANT, SyncP_LOST_SYNC,0,0,0);
- call Leds.led2Off();
- if (m_internalRequest)
- call TokenToCap.transfer();
- else
- signal MLME_SYNC_LOSS.indication(
- IEEE154_BEACON_LOSS,
- call MLME_GET.macPANId(),
- call MLME_GET.phyCurrentChannel(),
- call MLME_GET.phyCurrentPage(),
- NULL // security
- );
- } else
- call Token.request(); // make another request again (before giving the token up)
- call Debug.log(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 0, 0, 0);
- call Token.release();
+ if (getMode() == MODE_TRACK_SINGLE)
+ setMode(MODE_INACTIVE); // we're done with a single shot
+ resetInternalRequest();
+
+ // whether we next release the token or pass it to the CAP
+ // component, we want it back (because we decide later
+ // whether we'll actually stop tracking the beacon in future)
+ call RadioToken.request();
+
+ if (!wasBeaconReceived()) {
+
+ resetBeaconReceived(); // buffer ready
+ m_numBeaconsMissed += 1;
+ m_dt += getBeaconInterval(m_beaconOrder);
+ dbg_serial("BeaconSynchronizeP", "Missed a beacon (total missed: %lu).\n", (uint32_t) m_numBeaconsMissed);
+
+ if (wasInternalRequest) {
+ // note: if it only was an internal request, the
+ // mode was reset above already (SINGLE_SHOT)
+ signal TrackSingleBeacon.startDone(FAIL);
+ }
+ if (isExternalRequest() && m_numBeaconsMissed >= IEEE154_aMaxLostBeacons) {
+ resetExternalRequest();
+ setMode(MODE_INACTIVE);
+ dbg_serial("BeaconSynchronizeP", "MLME_SYNC_LOSS!\n");
+ signal MLME_SYNC_LOSS.indication(
+ IEEE154_BEACON_LOSS,
+ call MLME_GET.macPANId(),
+ call MLME_GET.phyCurrentChannel(),
+ call MLME_GET.phyCurrentPage(),
+ NULL);
+ }
+
+ call RadioToken.release();
+