/** * \brief Timer Callback function if identify command is received on air * by a node in reflector configuration. This is used to blink the LED * and thus identify itself * * \param parameter pass parameters to timer handler */ void led_blinker_timer_handler_cb(void *parameter) { #if (LED_COUNT > 0) static uint8_t led_count; parameter = parameter; /* LED Blinking sequence is completed */ if (led_count > LED_BLINK_COUNT_FOR_IDENTIFY) { led_count = 0; app_led_event(LED_EVENT_PEER_SEARCH_DONE); } else { /* Blink count is not completed */ /* For every timeout switch off and on all LEDs alternatively **/ if (led_count & 0x01) { led_count++; app_led_event(LED_EVENT_ALL_OFF); sw_timer_stop(APP_TIMER_TO_TX); } else { led_count++; app_led_event(LED_EVENT_ALL_ON); } sw_timer_start(APP_TIMER_TO_TX, LED_BLINK_RATE_IN_MICRO_SEC, SW_TIMEOUT_RELATIVE, (FUNC_PTR)led_blinker_timer_handler_cb, NULL); } #endif return; }
/* * \brief Application task to start peer search * * \param arg arguments to start the peer search */ void peer_search_initiator_init(void *arg) { /* Change LED pattern */ app_led_event(LED_EVENT_START_PEER_SEARCH); /* Print the message if it is Range measurement mode */ if (PEER_SEARCH_RANGE_TX == node_info.main_state) { print_event(PRINT_PEER_SEARCH_INITATED); } /* Peer search process seq number */ seq_num = rand(); /* assign a random address */ do { node_info.peer_short_addr = (uint16_t)rand(); /* Make sure random number is not zero */ } while (!node_info.peer_short_addr); /* Reduce the TX power level to minium,if configuration mode is enabled */ if (true == node_info.configure_mode) { /* set the tx power to lowest in configuration mode */ uint8_t config_tx_pwr = CONFIG_MODE_TX_PWR; tal_pib_set(phyTransmitPower, (pib_value_t *)&config_tx_pwr); } /* Keep compiler happy */ arg = arg; }
/* * \brief Application task to start peer search * * \param mode starts the peer search in this particular mode */ void peer_search_receptor_init(void *arg) { pib_value_t pib_value; peer_search_receptor_arg_t *arg_ptr = (peer_search_receptor_arg_t *)arg; /* Change LED pattern */ app_led_event(LED_EVENT_START_PEER_SEARCH); /* Peer process seq number */ seq_num = rand(); /* assign a random address */ do { node_info.peer_short_addr = rand(); /* Make sure random number is not zero */ } while (!node_info.peer_short_addr); /* Set my address which my peer send me */ pib_value.pib_value_16bit = arg_ptr->my_short_addr; tal_pib_set(macShortAddress, &pib_value); #ifdef EXT_RF_FRONT_END_CTRL /* Disable RF front end control during peer search process*/ tal_ext_pa_ctrl(PA_EXT_DISABLE); /* Make sure that Tx power is at max, when PA_EXT is disabled */ tal_set_tx_pwr(REGISTER_VALUE, 0x00); #endif }
/** * \brief Callback that is called once tx is done in wait for peer search conf * state. * * \param status Status of the transmission procedure * \param frame Pointer to the transmitted frame structure */ static void wait_for_conf_rx_cb(frame_info_t *mac_frame_info) { app_payload_t *msg; if (*(mac_frame_info->mpdu) == (FRAME_OVERHEAD + ((sizeof(app_payload_t) - sizeof(general_pkt_t)) + sizeof(peer_conf_t)))) { /* Point to the message : 1 =>size is first byte and 2=>FCS*/ msg = (app_payload_t *)(mac_frame_info->mpdu + 1 + FRAME_OVERHEAD - 2); if ((msg->cmd_id) == PEER_CONFIRM) { if (node_info.peer_short_addr == (msg->payload.peer_conf_data.nwk_addr)) { print_event(PRINT_PEER_SEARCH_SUCCESS); app_led_event(LED_EVENT_PEER_SEARCH_DONE); switch (node_info.main_state) { case PEER_SEARCH_RANGE_RX: /* Peer success - set the board to * RANGE_TEST_TX_OFF state */ set_main_state(RANGE_TEST_TX_OFF, 0); break; case PEER_SEARCH_PER_RX: /* Peer success - set the board to * RANGE_TEST_TX_OFF state */ set_main_state(PER_TEST_RECEPTOR, 0); break; /* To keep the GCC compiler happy */ case INIT: case WAIT_FOR_EVENT: case PEER_SEARCH_RANGE_TX: case PEER_SEARCH_PER_TX: case RANGE_TEST_TX_ON: case RANGE_TEST_TX_OFF: case SINGLE_NODE_TESTS: case PER_TEST_INITIATOR: case PER_TEST_RECEPTOR: case NUM_MAIN_STATES: break; default: /* Do nothing */ break; } } } } }
/* * \brief Application task when the node is in the WAIT_FOR_EVENT state * * \param arg arguments for WAIT_FOR_EVENT state */ void wait_for_event_init(void *arg) { /* Configure the TAL PIBs; e.g. set short address */ configure_pibs(); /* Leave the radio in RX mode in default channel */ tal_rx_enable(PHY_RX_ON); /* indicating application is started */ app_led_event(LED_EVENT_POWER_ON); /* Keep compiler happy */ arg = arg; }
/* * \brief Callback that is called if data has been received by trx when the . * node is in Range Measurement mode i.e RANGE_TEST_TX_ON or RANGE_TEST_TX_OFF * states * \param frame Pointer to received frame */ void range_test_rx_cb(frame_info_t *mac_frame_info) { app_payload_t *msg; if (*(mac_frame_info->mpdu) == (FRAME_OVERHEAD + ((sizeof(app_payload_t) - sizeof(general_pkt_t)) + sizeof(data_pkt_range_test_t)))) { /* Point to the message : 1 =>size is first byte and 2=>FCS*/ msg = (app_payload_t *)(mac_frame_info->mpdu + LENGTH_FIELD_LEN + FRAME_OVERHEAD - FCS_LEN); if ((msg->cmd_id) == DATA_PKT) { /* Correct packet received so toggle the LED on board */ app_led_event(LED_EVENT_RX_FRAME); /* Increment the frames received count */ num_of_frames_rec++; } } }
/** * \brief Callback function that handles timer in Range Measurement Mode * * \param parameter pass parameters to timer handler */ static void range_test_tx_timer_handler_cb(void *parameter) { /* Make compiler happy */ parameter = parameter; /* Transmit range test frame on Air */ range_test_frame_tx(); /* Toggle the LED indicating transmission */ app_led_event(LED_EVENT_TX_FRAME); /* Increment the frames transmitted counter */ num_of_frames_send++; /* Restart the timer */ sw_timer_start(APP_TIMER_TO_TX, APP_SEND_TEST_PKT_INTERVAL_IN_MICRO_SEC, SW_TIMEOUT_RELATIVE, (FUNC_PTR)range_test_tx_timer_handler_cb, NULL); }
/* * \brief Application task to start peer search * * \param mode starts the peer search in this particular mode */ void peer_search_receptor_init(trx_id_t trx, void *arg) { peer_search_receptor_arg_t *arg_ptr = (peer_search_receptor_arg_t *)arg; /* Change LED pattern */ app_led_event(LED_EVENT_START_PEER_SEARCH); /* Peer process seq number */ seq_num[trx] = rand(); /* assign a random address */ do { node_info[trx].peer_short_addr = rand(); /* Make sure random number is not zero */ } while (!node_info[trx].peer_short_addr); /* Set my address which my peer send me */ tal_pib_set(trx, macShortAddress, (pib_value_t *)&(arg_ptr->my_short_addr)); }
/* * \brief Application task to start peer search * * \param arg arguments to start the peer search */ void peer_search_initiator_init(void *arg) { pib_value_t pib_value_temp; /* Change LED pattern */ app_led_event(LED_EVENT_START_PEER_SEARCH); /* Print the message if it is Range measurement mode */ if (PEER_SEARCH_RANGE_TX == node_info.main_state) { print_event(PRINT_PEER_SEARCH_INITATED); } /* Peer search process seq number */ seq_num = rand(); /* assign a random address */ do { node_info.peer_short_addr = (uint16_t)rand(); /* Make sure random number is not zero */ } while (!node_info.peer_short_addr); #ifdef EXT_RF_FRONT_END_CTRL /* Disable RF front end control during peer search process*/ tal_ext_pa_ctrl(PA_EXT_DISABLE); /* Make sure that Tx power is at max, when PA_EXT is disabled */ tal_set_tx_pwr(REGISTER_VALUE, 0x00); #endif /* Reduce the TX power level to minium,if configuration mode is enabled **/ if (true == node_info.configure_mode) { /* set the tx power to lowest in configuration mode */ uint8_t config_tx_pwr = CONFIG_MODE_TX_PWR; pib_value_temp.pib_value_8bit = config_tx_pwr; tal_pib_set(phyTransmitPower, &pib_value_temp); } /* Keep compiler happy */ arg = arg; }
/** * \brief Callback that is called once tx is done in peer rsp rcvd state. * * \param status Status of the transmission procedure * \param frame Pointer to the transmitted frame structure */ static void peer_rsp_rcvd_tx_cb(retval_t status, frame_info_t *frame) { if (MAC_SUCCESS == status) { node_info.peer_found = true; /* Change LED pattern */ app_led_event(LED_EVENT_PEER_SEARCH_DONE); switch (node_info.main_state) { case PEER_SEARCH_RANGE_TX: { print_event(PRINT_PEER_SEARCH_SUCCESS); /* Peer success - set the board to RANGE_TEST_TX_ON state */ set_main_state(RANGE_TEST_TX_ON, NULL); } break; case PEER_SEARCH_PER_TX: { /* Peer success - set the board to PER_TEST_INITIATOR state */ set_main_state(PER_TEST_INITIATOR, NULL); } break; /* To keep the GCC compiler happy */ case INIT: case WAIT_FOR_EVENT: case PEER_SEARCH_RANGE_RX: case PEER_SEARCH_PER_RX: case RANGE_TEST_TX_ON: case RANGE_TEST_TX_OFF: case SINGLE_NODE_TESTS: case PER_TEST_INITIATOR: case PER_TEST_RECEPTOR: case NUM_MAIN_STATES: break; default: /* Do nothing */ break; } } else { /* Print messge if the Peer search failed in Range mode */ if (PEER_SEARCH_RANGE_TX == node_info.main_state) { print_event(PRINT_PEER_SEARCH_FAILED); } else if (PEER_SEARCH_PER_TX == node_info.main_state) { /* Send the confirmation to the PC application via Serial interface */ usr_perf_start_confirm(NO_PEER_FOUND, START_MODE_PER, NULL, NUL_VAL, NULL, NULL, NULL, NUL_VAL); } /* PEER CONF send failed so change to WAIT_FOR_EVENT state*/ set_main_state(WAIT_FOR_EVENT, NULL); } /* Keep compiler happy */ frame = frame; }