/*---------------------------------------------------------------------------*/ static int spirit_radio_channel_clear(void) { float rssi_value; /* Local variable used to memorize the SPIRIT1 state */ uint8_t spirit_state = ON; PRINTF("CHANNEL CLEAR IN\n"); if(spirit_on == OFF) { /* Wakes up the SPIRIT1 */ spirit_radio_on(); spirit_state = OFF; } /* */ IRQ_DISABLE(); spirit1_strobe(SPIRIT1_STROBE_SABORT); /* SpiritCmdStrobeSabort();*/ SpiritIrqClearStatus(); IRQ_ENABLE(); { rtimer_clock_t timeout = RTIMER_NOW() + 5 * RTIMER_SECOND/1000; do { SpiritRefreshStatus(); } while((g_xStatus.MC_STATE != MC_STATE_READY) && (RTIMER_NOW() < timeout)); if(RTIMER_NOW() < timeout) { return 1; } } /* Stores the RSSI value */ rssi_value = SpiritQiGetRssidBm(); /* Puts the SPIRIT1 in its previous state */ if(spirit_state==OFF) { spirit_radio_off(); } else { spirit1_strobe(SPIRIT1_STROBE_RX); /* SpiritCmdStrobeRx();*/ BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 5 * RTIMER_SECOND/1000); } PRINTF("CHANNEL CLEAR OUT\n"); /* Checks the RSSI value with the threshold */ if(rssi_value<CCA_THRESHOLD) { return 0; } else { return 1; } }
/** * @brief This function handles the point-to-point packet reception * @param uint8_t *RxFrameBuff = Pointer to ReceiveBuffer * uint8_t cRxlen = length of ReceiveBuffer * @retval None */ void AppliReceiveBuff(uint8_t *RxFrameBuff, uint8_t cRxlen) { uint8_t xIndex = 0; uint8_t ledToggleCtr = 0; /*float rRSSIValue = 0;*/ cmdFlag = RESET; exitTime = SET; exitCounter = TIME_TO_EXIT_RX; pRadioDriver = &spirit_cb; /* Spirit IRQs enable */ pRadioDriver->DisableIrq(); pRadioDriver->EnableRxIrq(); /* payload length config */ pRadioDriver->SetPayloadLen(PAYLOAD_LEN); /* rx timeout config */ pRadioDriver->SetRxTimeout(1000); /* IRQ registers blanking */ pRadioDriver->ClearIrqStatus(); SpiritIrqGetStatus(&xIrqStatus); /* RX command */ pRadioDriver->StartRx(); uint32_t timeout = HAL_GetTick() + 5000; /* wait for data received or timeout period occured */ while((RESET == xRxDoneFlag)&&(RESET == rx_timeout)&&(RESET == spirit_error) && (HAL_GetTick () < timeout)); if(rx_timeout==SET) { HAL_UART_Transmit(&huart1, "T ", 2, 1000); rx_timeout = RESET; } else if(xRxDoneFlag) { xRxDoneFlag=RESET; pRadioDriver->GetRxPacket(RxFrameBuff,&cRxlen); int dbmValue= SpiritQiGetRssidBm(); sprintf(message, "R %d ", dbmValue); /*rRSSIValue = Spirit1GetRssiTH();*/ HAL_UART_Transmit(&huart1, message, strlen(message), 1000); xRxFrame.Cmd = RxFrameBuff[0]; xRxFrame.CmdLen = RxFrameBuff[1]; xRxFrame.Cmdtag = RxFrameBuff[2]; xRxFrame.CmdType = RxFrameBuff[3]; xRxFrame.DataLen = RxFrameBuff[4]; for (xIndex = 5; xIndex < cRxlen; xIndex++) { xRxFrame.DataBuff[xIndex] = RxFrameBuff[xIndex]; } if(xRxFrame.Cmd == LED_TOGGLE) { RadioShieldLedOn(RADIO_SHIELD_LED); HAL_Delay(DELAY_RX_LED_TOGGLE); RadioShieldLedOff(RADIO_SHIELD_LED); cmdFlag = SET; } if(xRxFrame.Cmd == ACK_OK) { for(; ledToggleCtr<5; ledToggleCtr++) { RadioShieldLedToggle(RADIO_SHIELD_LED); HAL_Delay(DELAY_RX_LED_TOGGLE); } RadioShieldLedOff(RADIO_SHIELD_LED); } } else if (spirit_error == SET) { spirit_error = RESET; } }
/** * @brief this function sets the RSSI threshold * @param int dbmValue * @retval None */ float Spirit1GetRssiTH(void) { float dbmValue=0; dbmValue = SpiritQiGetRssidBm(); return dbmValue; }