interface MLME_SYNC;
interface MLME_BEACON_NOTIFY;
interface MLME_SYNC_LOSS;
- interface Get<bool> as IsTrackingBeacons;
+ interface GetNow<bool> as IsTrackingBeacons;
interface GetNow<uint32_t> as CapStart;
interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
interface GetNow<uint32_t> as CapLen;
interface MLME_GET;
interface MLME_SET;
interface FrameUtility;
+ interface Notify<bool> as FindBeacon;
interface IEEE154BeaconFrame as BeaconFrame;
interface Alarm<TSymbolIEEE802154,uint32_t> as TrackAlarm;
interface RadioRx as BeaconRx;
};
norace bool m_tracking = FALSE;
- norace bool m_updatePending = FALSE;
+ bool m_updatePending = FALSE;
uint8_t m_updateLogicalChannel;
bool m_updateTrackBeacon;
bool m_stopTracking = FALSE;
+ bool m_internalRequest = FALSE;
- norace uint8_t m_numBeaconsLost;
+ uint8_t m_numBeaconsLost;
uint8_t m_coordAddress[8];
message_t m_beaconBuffer;
norace message_t *m_beaconBufferPtr = &m_beaconBuffer;
m_stopTracking = FALSE;
m_updateLogicalChannel = logicalChannel;
m_updateTrackBeacon = trackBeacon;
- atomic m_updatePending = TRUE;
+ m_updatePending = TRUE;
+ m_internalRequest = FALSE;
call Debug.log(LEVEL_INFO,SyncP_RESOURCE_REQUEST, 0, 0, 0);
call Token.request();
}
return IEEE154_SUCCESS;
}
+ event void FindBeacon.notify( bool val )
+ {
+ if (!m_tracking && !m_updatePending){
+ // find a single beacon now (treat this like a user request)
+ m_updateLogicalChannel = call MLME_GET.phyCurrentChannel();
+ m_updateTrackBeacon = FALSE;
+ m_updatePending = TRUE;
+ m_internalRequest = TRUE;
+ call Token.request();
+ }
+ }
+
event void Token.granted()
{
bool missed = FALSE;
+ call Debug.flush();
call Debug.log(LEVEL_INFO,SyncP_GOT_RESOURCE, m_lastBeaconRxTime+m_beaconInterval,
m_beaconInterval, (m_updatePending<<1)+m_tracking);
if (m_updatePending){
async event void TrackAlarm.fired()
{
- call Debug.log(LEVEL_IMPORTANT,SyncP_SWITCHOFF, 0,0,0);
+ call Debug.log(LEVEL_IMPORTANT,SyncP_TRACK_ALARM, m_state,m_lastBeaconRxTime,m_dt);
atomic {
switch (m_state)
{
call BeaconRx.prepare();
break;
case S_RADIO_OFF:
- call Debug.log(LEVEL_INFO, SyncP_SWITCHOFF, 0, 0,0);
call RadioOff.off();
break;
}
async event void BeaconRx.prepareDone()
{
+ error_t result;
if (m_state == S_FIRST_SCAN){
m_state = S_RADIO_OFF;
atomic {
}
} else {
m_state = S_RADIO_OFF;
- call BeaconRx.receive(&m_lastBeaconRxRefTime, m_dt-RX_LAG);
- call Debug.log(LEVEL_IMPORTANT,SyncP_RX_ON, call TrackAlarm.getNow(),m_lastBeaconRxTime+m_dt,RX_LAG);
+ result = call BeaconRx.receive(&m_lastBeaconRxRefTime, m_dt-RX_LAG);
+ call Debug.log(LEVEL_IMPORTANT,SyncP_RX_ON, m_lastBeaconRxTime, call TrackAlarm.getNow(), m_dt+RX_DURATION);
+ if (result != SUCCESS)
+ call Debug.log(LEVEL_IMPORTANT,SyncP_RADIO_BUSY, result, 0, 0);
call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt + RX_DURATION);
}
}
mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK,mhr[MHR_INDEX_SEQNO]);
if (!m_beaconSwapBufferReady || !call FrameUtility.isBeaconFromCoord(frame))
{
+ call Debug.log(LEVEL_IMPORTANT,SyncP_RX_GARBAGE, m_beaconSwapBufferReady, 0, 0);
return frame;
} else {
message_t *tmp = m_beaconBufferPtr;
m_tracking = FALSE;
call Debug.log(LEVEL_IMPORTANT, SyncP_LOST_SYNC,0,0,0);
call Leds.led2Off();
- signal MLME_SYNC_LOSS.indication(
- IEEE154_BEACON_LOSS,
- call MLME_GET.macPANId(),
- call MLME_GET.phyCurrentChannel(),
- call MLME_GET.phyCurrentPage(),
- NULL // security
- );
+ 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);
}
}
- command bool IsTrackingBeacons.get(){ return m_tracking;}
+ async command bool IsTrackingBeacons.getNow(){ return m_tracking;}
default event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame){return frame;}