/****************************************************************************** * @fn nwk_replayFrame * * @brief Deal with hop count on a Range Extender or Access Point replay. * Queue entry usage always left as available when done. * * input parameters * @param pFrameInfo - pointer to frame information structure * * output parameters * * @return void */ void nwk_replayFrame(frameInfo_t *pFrameInfo) { uint8_t hops = GET_FROM_FRAME(MRFI_P_PAYLOAD(&pFrameInfo->mrfiPkt), F_HOP_COUNT); /* if hops are zero, drop frame. othewise send it. */ if (hops--) { PUT_INTO_FRAME(MRFI_P_PAYLOAD(&pFrameInfo->mrfiPkt),F_HOP_COUNT,hops); /* Don't care if the Tx fails because of TO. Either someone else * will retransmit or the application itself will recover. */ #if defined(SMPL_SECURE) /* If the frame was targeted to a NWK port it was decrypted on spec in * the 'dispatchFrame()' method. It must be re-encypted in this case. */ if (GET_FROM_FRAME(MRFI_P_PAYLOAD(&pFrameInfo->mrfiPkt), F_PORT_OS) <= SMPL_PORT_NWK_BCAST) { nwk_setSecureFrame(&pFrameInfo->mrfiPkt, MRFI_GET_PAYLOAD_LEN(&pFrameInfo->mrfiPkt)-F_APP_PAYLOAD_OS, 0); } #endif MRFI_DelayMs(1); nwk_sendFrame(pFrameInfo, MRFI_TX_TYPE_CCA); } else { pFrameInfo->fi_usage = FI_AVAILABLE; } return; }
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 ... */ }
/****************************************************************************** delay_ms *//** @brief Delays a certain number of milliseconds. ******************************************************************************/ void delay_ms(uint32_t time_delay_ms) { MRFI_DelayMs(time_delay_ms); }