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); } }
/*********************************************************************************** * @fn SMPL_Init * * @brief Initialize the SimpliciTI stack. * * input parameters * @param f - Pointer to call back function. Function called by NWK when * user application frame received. The callback is done in the * ISR thread. Argument is Link ID associated with frame. Function * returns 0 if frame is to be kept by NWK, otherwise 1. Frame * should be kept if application will do a SMPL_Receive() in the * user thread (recommended). Pointer may be NULL. * * output parameters * * @return Status of operation: * SMPL_SUCCESS * SMPL_NO_JOIN No Join reply. AP possibly not yet up. * SMPL_NO_CHANNEL Only if Frequency Agility enabled. Channel scan * failed. AP possibly not yet up. */ smplStatus_t SMPL_Init(uint8_t (*f)(linkID_t)) { smplStatus_t rc; if (!sInit_done) { /* set up radio. */ MRFI_Init(); /* initialize network */ if ((rc=nwk_nwkInit(f)) != SMPL_SUCCESS) { return rc; } MRFI_WakeUp(); #if defined( FREQUENCY_AGILITY ) { freqEntry_t chan; chan.logicalChan = 0; /* ok to set default channel explicitly now that MRFI initialized. */ nwk_setChannel(&chan); } #endif /* don't turn Rx on if we're an end device that isn't always on. */ /* but do turn the radio on for PLL operations */ #if !defined( END_DEVICE ) || defined( NWK_PLL ) MRFI_RxOn(); #endif #if defined( END_DEVICE ) /* All except End Devices are in promiscuous mode */ MRFI_SetRxAddrFilter((uint8_t *)nwk_getMyAddress()); MRFI_EnableRxAddrFilter(); #endif } sInit_done = 1; #ifdef NWK_PLL /* If the PLL is enabled then it must get running before the join * request or the system may lock up in the join request becuase * PLL is not locked in. */ // turn on the PLL SMPL_Ioctl(IOCTL_OBJ_PLL, IOCTL_ACT_ON, NULL); // reference clocks are by definition always locked. #ifndef NWK_PLL_REFERENCE_CLOCK // wait for a 5ms failure rate to be achieved while( nwk_pllIsLocked( 0 ) == false ) nwk_pllBackgrounder( false ); #endif #endif /* Join. if no AP or Join fails that status is returned. */ rc = nwk_join(); return rc; }
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 main1 (void) { /* holds length of current message */ uint8_t len; /* the link token */ linkID_t LinkID = 0; /* the transmit and receive buffers */ uint8_t rx[MAX_APP_PAYLOAD], tx[MAX_APP_PAYLOAD]; /* holds led indicator time out counts */ uint16_t led_tmr; int8_t rssi_value; BSP_Init( ); SMPL_Init( NULL ); uart_intfc_init( ); /* turn on the radio so we are always able to receive data asynchronously */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL ); /* turn on LED. */ BSP_TURN_ON_LED1( ); #ifdef LINK_TO { uint8_t cnt = 0; tx_send_wait( "Linking to...\r\n", 15 ); while (SMPL_SUCCESS != SMPL_Link(&LinkID)) if( cnt++ == 0 ) { /* blink LED until we link successfully */ BSP_TOGGLE_LED1( ); } } #else // ifdef LINK_LISTEN tx_send_wait( "Listening for Link...\r\n", 23 ); while (SMPL_SUCCESS != SMPL_LinkListen(&LinkID)) { /* blink LED until we link successfully */ BSP_TOGGLE_LED1( ); } #endif tx_send_wait( "Link Established!\r\nReady...\r\n", 29 ); /* turn off the led */ BSP_TURN_OFF_LED1( ); main_loop: /* Check to see if we received any characters from the other radio * and if we have send them out the uart and reset indicator timeout. * Prioritize on radio received links as that buffer is the most time * critical with respect to the UART buffers. */ if( SMPL_Receive( LinkID, tx, &len ) == SMPL_SUCCESS ) { /* blocking call but should be ok if both ends have same uart buad rate */ //tx_send_wait( tx, len ); led_tmr = INDICATOR_TIME_OUT; /* update activity time out */ /* int8_t dbm; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI, (void *)&dbm); sSample= dbm; tx_send_wait(&char2send, 1 );//input only (unsigned char) tx_send_wait("\n", 1 );*/ unsigned char Test2; //unsigned char Test; rssi_value = 0 ; ioctlRadioSiginfo_t sigInfo1; sigInfo1.lid=LinkID; smplStatus_t SMPL_SUCCESS = SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo1); //if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,(void*)&rssi_value) ) { //transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg ); //MRFI_Rssi() //Test2=RSSI; //Test=rssi_value; //int8_t i =-127; //int i =-127; unsigned char rssi_tmp[10]; int8_t rssi_int = sigInfo1.sigInfo.rssi; itoa(rssi_int,rssi_tmp); //tx_send_wait("This is Test :", sizeof("This is Test :") ); //tx_send_wait(&Test2, strlen(&Test2)); tx_send_wait(&rssi_tmp, strlen(rssi_tmp)); //tx_send_wait("\r\n", sizeof("\r\n") ); int8_t mk=0x01,bitshift=0; tx_send_wait("=",1); for (bitshift=0;bitshift<8;bitshift++) { if( (mk<<bitshift) & rssi_int ) tx_send_wait("1",1); else tx_send_wait("0",1); //tx_send_wait("x",1); MRFI_DelayMs( 5 ); } tx_send_wait("\r\n", sizeof("\r\n") ); /* tx_send_wait("This is Test2 :", sizeof("This is Test2 :") ); tx_send_wait( &Test2, sizeof(Test2) ); tx_send_wait("\n", sizeof("\n") ); */ } } FHSS_ACTIVE( if( nwk_pllBackgrounder( false ) != false ) ); { /* check to see if the host has sent any characters and if it has * then send them over the radio link and reset indicator timeout. */ len = rx_receive( rx, MAX_APP_PAYLOAD ); if( len != 0 ) { while( SMPL_Send( LinkID, rx, len ) != SMPL_SUCCESS ) ; /* if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,&rssi_value ) ){ SMPL_Send( LinkID, &rssi_value, sizeof(rssi_value) ); }*/ led_tmr = INDICATOR_TIME_OUT; /* update activity time out */ /* By forcing a minimum delay between transmissions we guarantee * a window for receiving packets. This is necessary as the radio * link is half duplex while the UART is full duplex. Without this * delay mechanism, packets can get lost as both ends may attempt to * transmit at the same time which the CCA algorithm fails to handle. */ MRFI_DelayMs( 5 ); } } /* manage led indicator */ if( led_tmr != 0 ) { led_tmr--; BSP_TURN_ON_LED1( ); } else BSP_TURN_OFF_LED1( ); goto main_loop; /* do it again and again and again and ... */ }
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); } }