Пример #1
0
/*--------------------------------------------------------------------------*/
static radio_result_t
set_value(radio_param_t param, radio_value_t value)
{
  switch(param) {
  case RADIO_PARAM_POWER_MODE:
    if(value == RADIO_POWER_MODE_ON) {
      stm32w_radio_on();
      return RADIO_RESULT_OK;
    }
    if(value == RADIO_POWER_MODE_OFF) {
      stm32w_radio_off();
      return RADIO_RESULT_OK;
    }
    return RADIO_RESULT_INVALID_VALUE;
  case RADIO_PARAM_CHANNEL:
    if(value < ST_MIN_802_15_4_CHANNEL_NUMBER ||
       value > ST_MAX_802_15_4_CHANNEL_NUMBER) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    if(ST_RadioSetChannel(value) != ST_SUCCESS) {
      return RADIO_RESULT_ERROR;
    }
    return RADIO_RESULT_OK;
  case RADIO_PARAM_PAN_ID:
    ST_RadioSetPanId(value & 0xffff);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_16BIT_ADDR:
    ST_RadioSetNodeId(value & 0xffff);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_RX_MODE:
    if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER |
                 RADIO_RX_MODE_AUTOACK)) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    ST_RadioEnableAddressFiltering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
    ST_RadioEnableAutoAck((value & RADIO_RX_MODE_AUTOACK) != 0);
    return RADIO_RESULT_OK;
  case RADIO_PARAM_TXPOWER:
    if(value < MIN_RADIO_POWER || value > MAX_RADIO_POWER) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    if(ST_RadioSetPower((int8_t)value) != ST_SUCCESS) {
      return RADIO_RESULT_INVALID_VALUE;
    }
    return RADIO_RESULT_OK;
  case RADIO_PARAM_CCA_THRESHOLD:
    ST_RadioSetEdCcaThreshold((int8_t)value);
    return RADIO_RESULT_OK;
  default:
    return RADIO_RESULT_NOT_SUPPORTED;
  }
}
Пример #2
0
/*******************************************************************************
** 函数名称:   Zigbee_Transmit
** 函数功能:   zigbee发送函数处理主函数
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void Zigbee_Transmit(void)
{
	  ST_RadioEnableOverflowNotification(FALSE);
      ST_RadioSetPowerMode(ST_TX_POWER_MODE_DEFAULT);    
      ST_RadioEnableAddressFiltering(FALSE);
      ST_RadioEnableAutoAck(FALSE);
      ST_RadioSetPower(RF_Power);
      ST_RadioSetChannel(Send_Channel);   
      ST_RadioInit(ST_RADIO_POWER_MODE_OFF); 
	  
	  Card_Cmd[10] |= (0x00|(battery.stat<<5)|(help_flag<<7));				//电池电量及求助状态

	  txBuf[0] =(int8u)(sizeof(Card_Cmd)+2);
      for(int8u ct = 0; ct < (int8u)sizeof(Card_Cmd); ct++)
        txBuf[ct + 1] = Card_Cmd[ct];      
      txPacketInFlight = TRUE;
      if(ST_RadioTransmit(txBuf)==ST_SUCCESS){
        while(txPacketInFlight);
        ST_RadioSleep();
      }
      else
        SendFailTime++;
}