static void start2Babble() { uint8_t msg[1]; /* frequency hopping doesn't support sleeping just yet */ #ifndef FREQUENCY_HOPPING /* wake up radio. */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); #endif /* Send the bad news message. To prevent confusion with different "networks" * such as neighboring smoke alarm arrays send a token controlled by a DIP * switch, for example, and filter in this token. */ msg[0] = BAD_NEWS; while (1) { FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */ /*wait "a while" */ NWK_DELAY(100); /* babble... */ SMPL_Send(SMPL_LINKID_USER_UUD, msg, sizeof(msg)); toggleLED(2); } }
int main (void) { BSP_Init(); /* If an on-the-fly device address is generated it must be done before the * call to SMPL_Init(). If the address is set here the ROM value will not * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call * will not take effect. One shot only. The IOCTL call below is conformal. */ #ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE { addr_t lAddr; createRandomAddress(&lAddr); SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); } #endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */ /* This call will fail because the join will fail since there is no Access Point * in this scenario. but we don't care -- just use the default link token later. * we supply a callback pointer to handle the message returned by the peer. */ SMPL_Init(0); /* turn on LEDs. */ if (!BSP_LED2_IS_ON()) toggleLED(2); if (!BSP_LED1_IS_ON()) toggleLED(1); /* wait for a button press... */ do { FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */ if (BSP_BUTTON1() || BSP_BUTTON2()) break; } while (1); /* never coming back... */ monitorForBadNews(); /* but in case we do... */ while (1) ; }
void main (void) { bspIState_t intState; #ifdef FREQUENCY_AGILITY memset(sSample, 0x0, sizeof(sSample)); #endif BSP_Init(); /* If an on-the-fly device address is generated it must be done before the * call to SMPL_Init(). If the address is set here the ROM value will not * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call * will not take effect. One shot only. The IOCTL call below is conformal. */ #ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE { addr_t lAddr; createRandomAddress(&lAddr); SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); } #endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */ SMPL_Init(sCB); /* green and red LEDs on solid to indicate waiting for a Join. */ if (!BSP_LED2_IS_ON()) { toggleLED(2); } if (!BSP_LED1_IS_ON()) { toggleLED(1); } /* main work loop */ while (1) { /* manage FHSS schedule if FHSS is active */ FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* Wait for the Join semaphore to be set by the receipt of a Join frame from a * device that supports an End Device. * * An external method could be used as well. A button press could be connected * to an ISR and the ISR could set a semaphore that is checked by a function * call here, or a command shell running in support of a serial connection * could set a semaphore that is checked by a function call. */ if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS)) { /* listen for a new connection */ while (1) { /* SMPL_LinkListen will call nwk_PllBackgrounder for us if FHSS active */ if (SMPL_SUCCESS == SMPL_LinkListen(&sLID[sNumCurrentPeers])) { break; } /* Implement fail-to-link policy here. otherwise, listen again. */ } sNumCurrentPeers++; BSP_ENTER_CRITICAL_SECTION(intState); sJoinSem--; BSP_EXIT_CRITICAL_SECTION(intState); } /* Have we received a frame on one of the ED connections? * No critical section -- it doesn't really matter much if we miss a poll */ if (sPeerFrameSem) { uint8_t msg[MAX_APP_PAYLOAD], len, i; /* process all frames waiting */ for (i=0; i<sNumCurrentPeers; ++i) { if (SMPL_SUCCESS == SMPL_Receive(sLID[i], msg, &len)) { processMessage(sLID[i], msg, len); BSP_ENTER_CRITICAL_SECTION(intState); sPeerFrameSem--; BSP_EXIT_CRITICAL_SECTION(intState); } } } if (BSP_BUTTON1()) { SPIN_ABOUT_A_QUARTER_SECOND; /* debounce */ changeChannel(); } else { checkChangeChannel(); } BSP_ENTER_CRITICAL_SECTION(intState); if (sBlinky) { if (++sBlinky >= 0xF) { sBlinky = 1; toggleLED(1); toggleLED(2); } } BSP_EXIT_CRITICAL_SECTION(intState); } }