/*---------------------------------------------------------------------------*/ void stm32w_radio_set_promiscous(uint8_t on) { if(on) { ST_RadioEnableAddressFiltering(0); } else { ST_RadioEnableAddressFiltering(ST_RADIO_AUTOACK); } }
/*---------------------------------------------------------------------------*/ static int stm32w_radio_init(void) { /* A channel also needs to be set. */ ST_RadioSetChannel(RF_CHANNEL); /* Initialize radio (analog section, digital baseband and MAC). */ /* Leave radio powered up in non-promiscuous rx mode. */ ST_RadioInit(ST_RADIO_POWER_MODE_OFF); onoroff = OFF; ST_RadioSetPanId(IEEE802154_PANID); CLEAN_RXBUFS(); CLEAN_TXBUF(); #if ST_RADIO_AUTOACK && !(UIP_CONF_LL_802154 && RIMEADDR_CONF_SIZE==8) #error "Autoack and address filtering can only be used with EUI 64" #endif ST_RadioEnableAutoAck(ST_RADIO_AUTOACK); ST_RadioEnableAddressFiltering(ST_RADIO_AUTOACK); locked = 0; process_start(&stm32w_radio_process, NULL); return 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; } }
void enable_sniffer_mode(short on) { if(on){ #if 0 ST_RadioEnableReceiveCrc(FALSE); // CRC will not be checked by hardware. ST_RadioEnableAutoAck(FALSE); ST_RadioEnableAddressFiltering(FALSE); stm32w_radio_driver.set_receive_function(mac_ethhijack); usbstick_mode.raw = 1; usbstick_mode.sendToRf = 0; #endif } else { ST_RadioEnableReceiveCrc(TRUE); // CRC will not be checked by hardware. ST_RadioEnableAutoAck(TRUE); ST_RadioEnableAddressFiltering(TRUE); //MAC_DRIVER.init(&stm32w_radio_driver); usbstick_mode.raw = 0; usbstick_mode.sendToRf = 1; } }
/******************************************************************************* ** 函数名称: 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++; }
/*---------------------------------------------------------------------------*/ int main(void) { /* * Initialize hardware. */ halInit(); clock_init(); uart1_init(115200); // Led initialization leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n",boardDescription->name); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif //etimer_process should be started before ctimer init process_start(&etimer_process, NULL); //ctimer and rtimer should be initialized before netstack to enable RDC (cxmac, contikimac, lpp) ctimer_init(); rtimer_init(); netstack_init(); #if !UIP_CONF_IPV6 ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. ST_RadioEnableAddressFiltering(FALSE); #endif set_rime_addr(); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); while(1){ int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); ENERGEST_OFF(ENERGEST_TYPE_CPU); //watchdog_stop(); ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ //watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } }
/*---------------------------------------------------------------------------*/ int main(void) { /* * Initialize hardware. */ halInit(); clock_init(); uart1_init(115200); // Led initialization leds_init(); INTERRUPTS_ON(); PRINTF("\r\nStarting "); PRINTF(CONTIKI_VERSION_STRING); PRINTF(" on %s\r\n",boardDescription->name); /* * Initialize Contiki and our processes. */ process_init(); #if WITH_SERIAL_LINE_INPUT uart1_set_input(serial_line_input_byte); serial_line_init(); #endif process_start(&etimer_process, NULL); ctimer_init(); rtimer_init(); netstack_init(); set_rime_addr(); PRINTF("ACK enable=%u %s %s, channel check rate=%luHz, check interval %ums, clock second=%u, radio channel %u\r\n", ST_RadioAutoAckEnabled(), NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), NETSTACK_RDC.channel_check_interval(), CLOCK_SECOND, RF_CHANNEL); #if !UIP_CONF_IPV6 ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. ST_RadioEnableAddressFiltering(FALSE); #endif ST_RadioEnableAutoAck(TRUE); procinit_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); while(1){ int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); ENERGEST_OFF(ENERGEST_TYPE_CPU); //watchdog_stop(); ENERGEST_ON(ENERGEST_TYPE_LPM); /* Go to idle mode. */ halSleepWithOptions(SLEEPMODE_IDLE,0); /* We are awake. */ //watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } }