// Public Functions void ascmm_init(const asc_ant_params_t * const p_ant_discovery_parameters, const asc_ant_params_t * const p_ant_connection_parameters, uint16_t device_number) { uint32_t err_code; m_discovery_channel_number = p_ant_discovery_parameters->channel_number; m_device_number = device_number; //Assign the slave channel err_code = sd_ant_channel_assign(m_discovery_channel_number, p_ant_discovery_parameters->channel_type, p_ant_discovery_parameters->network_number, EXT_PARAM_ALWAYS_SEARCH); APP_ERROR_CHECK(err_code); //Assign slave channel id. err_code = sd_ant_channel_id_set(m_discovery_channel_number, ANT_WILDCARD_DEVICE_NUMBER, p_ant_discovery_parameters->device_type, p_ant_discovery_parameters->tx_type); APP_ERROR_CHECK(err_code); //Assign slave channel frequency. err_code = sd_ant_channel_radio_freq_set(m_discovery_channel_number, p_ant_discovery_parameters->rf_frequency); APP_ERROR_CHECK(err_code); //Set the transmission power. err_code = sd_ant_channel_radio_tx_power_set(m_discovery_channel_number, p_ant_discovery_parameters->tx_power, ASC_ANT_CUSTOM_PWR); APP_ERROR_CHECK(err_code); //Configure search timeouts err_code = sd_ant_channel_rx_search_timeout_set(m_discovery_channel_number, DISCOVERY_SEARCH_TIMEOUT); APP_ERROR_CHECK(err_code); err_code = sd_ant_channel_low_priority_rx_search_timeout_set(m_discovery_channel_number, DISCOVERY_LP_SEARCH_TIMEOUT); APP_ERROR_CHECK(err_code); // Configure proximity search // @todo: JP added trailing 0 parameter err_code = sd_ant_prox_search_set(m_discovery_channel_number, PROXIMITY_THRESHOLD_2, 0); APP_ERROR_CHECK(err_code); //Enable extended messages err_code = sd_ant_lib_config_set(ANT_LIB_CONFIG_MESG_OUT_INC_DEVICE_ID); APP_ERROR_CHECK(err_code); //Initialize the connection parameters struct for later use //Many of these values are just defaults for now. //Ex. channel type will be determined before switching to the connected state) m_ant_connected_parameters.channel_number = p_ant_connection_parameters->channel_number; m_ant_connected_parameters.network_number = p_ant_connection_parameters->network_number; m_ant_connected_parameters.p_device_number = &(m_connection_device_number); //This will change over the course of discovery m_ant_connected_parameters.device_type = p_ant_connection_parameters->device_type; m_ant_connected_parameters.tx_type = p_ant_connection_parameters->tx_type; m_ant_connected_parameters.channel_period = p_ant_connection_parameters->channel_period; m_ant_connected_parameters.channel_type = p_ant_connection_parameters->channel_type; m_ant_connected_parameters.rf_frequency = p_ant_connection_parameters->rf_frequency; m_ant_connected_parameters.tx_power = p_ant_connection_parameters->tx_power; }
/**@brief initialize application */ static void continuous_scan_init() { uint32_t err_code; // Set library config to report RSSI and Device ID err_code = sd_ant_lib_config_set(ANT_LIB_CONFIG_MESG_OUT_INC_RSSI | ANT_LIB_CONFIG_MESG_OUT_INC_DEVICE_ID); APP_ERROR_CHECK(err_code); // Configure channel 0 for scanning mode, but do not open it. // The scanning channel will be opened in scan mode for a short amount of time on a button press. ant_channel_config_t channel_config = { .channel_number = ANT_SCAN_CHANNEL_NUMBER, .channel_type = ANT_BS_CHANNEL_TYPE, .ext_assign = 0, .rf_freq = ANT_FREQUENCY, .transmission_type = ANT_TRANSMISSION_TYPE, .device_type = ANT_DEVICE_TYPE, .device_number = ANT_BS_DEVICE_NUMBER, .channel_period = 0, // Not used, since this is going to be scanning .network_number = ANT_NETWORK_NUMBER, }; err_code = ant_channel_init(&channel_config); APP_ERROR_CHECK(err_code); // Assign a second channel for sending messages on the reverse direction // There is no need to configure any other parameters, this channel is never opened; // its resources are used by ANT to send messages in the reverse direction while in // continuous scanning mode. err_code = sd_ant_channel_assign(ANT_RESPONSE_CHANNEL_NUMBER, ANT_BS_CHANNEL_TYPE, ANT_NETWORK_NUMBER, 0x00); APP_ERROR_CHECK(err_code); } /** @brief Add a newly discovered node to the m_node_list * * @param[in] device_number The device_number of the current to be added * @param[in] rssi The RSSI from the current node to be added */ void add_node_to_list(uint16_t device_number, uint8_t rssi) { uint8_t index = MAX_DEVICES; // Specifed maximum total number in the array uint8_t start = CONVERT_DEVICE_NUM_TO_INDEX(device_number); // Start index of the array uint8_t node_device_number; for(int i = 0; i < MAX_DEVICES; i++ ) { node_device_number = m_node_list[(start + i) % MAX_DEVICES].device_number; if( node_device_number == device_number ) // If this node already exists, don't add it return; if(node_device_number == 0) // If we found a place to put it { // Find the best place to put this node (the place closest to the hash function result) index = (start + i) % MAX_DEVICES; break; } } if( index == MAX_DEVICES ) return; m_node_list[index].device_number = device_number; m_node_list[index].rssi = rssi; }