/**@brief Process ANT message on ANT slave relay channel * * @param[in] p_ant_event ANT message content. */ void ant_process_relay_slave(ant_evt_t* p_ant_event) { static bool first_recieved = false; ANT_MESSAGE* p_ant_message = (ANT_MESSAGE*)p_ant_event->evt_buffer; switch(p_ant_event->event) { case EVENT_RX: { switch(p_ant_message->ANT_MESSAGE_aucPayload[0]) { case ANT_RELAY_MAIN_PAGE: { ant_handle_main_page(p_ant_message->ANT_MESSAGE_aucPayload); break; } } LEDS_ON(BSP_LED_1_MASK); if(first_recieved) break; else first_recieved = true; //!!INTENTIONAL FALL THROUGH !! } // fall-through case EVENT_TX: { ant_relay_main_message(ANT_RELAY_SLAVE_CHANNEL); break; } case EVENT_RX_SEARCH_TIMEOUT: { // Channel has closed. // Re-initialize proximity search settings. uint32_t err_code = sd_ant_prox_search_set(ANT_RELAY_SLAVE_CHANNEL, ANT_PROXIMITY_BIN, 0); APP_ERROR_CHECK(err_code); LEDS_OFF(BSP_LED_1_MASK); break; } default: { break; } } }
// 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 Function for setting up the ANT channels * */ static void ant_channel_setup(void) { uint32_t err_code; // !! GLOBAL ANT CONFIGURATION !! // err_code = sd_ant_network_address_set(ANT_CHANNEL_DEFAULT_NETWORK, pm_ant_public_key); APP_ERROR_CHECK(err_code); // !! CONFIGURE MOBILE CHANNEL !! // /* The purpose of the mobile channel is to provide an independent link to a mobile platform using ANT. The mobile channel will report the status of the LED as well as the status of the slave relay channel (closed/open/searching). The mobile channel will also accept commands which emulate the function of the development board. For example, to set the the set the state of the led or to put the device into pairing mode. */ //Assign the mobile channel type err_code = sd_ant_channel_assign( ANT_MOBILE_CHANNEL, ANT_MOBILE_CHANNEL_TYPE, ANT_CHANNEL_DEFAULT_NETWORK, 0); APP_ERROR_CHECK(err_code); //Assign channel id err_code = sd_ant_channel_id_set( ANT_MOBILE_CHANNEL, ANT_MOBILE_DEVICE_NUMBER, ANT_MOBILE_DEVICE_TYPE, ANT_MOBILE_TRANSMISSION_TYPE); APP_ERROR_CHECK(err_code); //Assign channel frequency err_code = sd_ant_channel_radio_freq_set( ANT_MOBILE_CHANNEL, ANT_MOBILE_FREQUENCY); APP_ERROR_CHECK(err_code); //Assign channel message period err_code = sd_ant_channel_period_set ( ANT_MOBILE_CHANNEL, ANT_MOBILE_CHANNEL_PERIOD); APP_ERROR_CHECK(err_code); // Open channel right away. err_code = sd_ant_channel_open(ANT_MOBILE_CHANNEL); APP_ERROR_CHECK(err_code); // !! CONFIGURE RELAY MASTER CHANNEL !! // /* The relay master channel is always on and transmits the status of the LED and the status of the slave relay channel (open/closed/searching). It is 100% bi-directional once a slave connects to it (status updates from the slave are sent on every message period) */ //Assign the relay master channel type err_code = sd_ant_channel_assign( ANT_RELAY_MASTER_CHANNEL, ANT_RELAY_MASTER_CHANNEL_TYPE, ANT_CHANNEL_DEFAULT_NETWORK, 0); APP_ERROR_CHECK(err_code); //Assign channel id err_code = sd_ant_channel_id_set( ANT_RELAY_MASTER_CHANNEL, ANT_RELAY_MASTER_DEVICE_NUMBER, ANT_RELAY_DEVICE_TYPE, ANT_RELAY_TRANSMISSION_TYPE); APP_ERROR_CHECK(err_code); //Assign channel frequency err_code = sd_ant_channel_radio_freq_set( ANT_RELAY_MASTER_CHANNEL, ANT_RELAY_FREQUENCY); APP_ERROR_CHECK(err_code); //Assign channel message period err_code = sd_ant_channel_period_set ( ANT_RELAY_MASTER_CHANNEL, ANT_RELAY_CHANNEL_PERIOD); APP_ERROR_CHECK(err_code); // Open channel right away. err_code = sd_ant_channel_open(ANT_RELAY_MASTER_CHANNEL); APP_ERROR_CHECK(err_code); // !! CONFIGURE RELAY SLAVE CHANNEL !! // /* The purpose of the relay slave channel is to find and synchronize to another devices master really channel. The slave channel is only opened on a button press and uses proximity pairing to connect to a master channel. Once tracking a master the slave channel will send status message back to the master 100% of the time. */ //Assign the relay slave channel type err_code = sd_ant_channel_assign( ANT_RELAY_SLAVE_CHANNEL, ANT_RELAY_SLAVE_CHANNEL_TYPE, ANT_CHANNEL_DEFAULT_NETWORK, 0); APP_ERROR_CHECK(err_code); //Assign channel id err_code = sd_ant_channel_id_set( ANT_RELAY_SLAVE_CHANNEL, ANT_RELAY_SLAVE_DEVICE_NUMBER, ANT_RELAY_DEVICE_TYPE, ANT_RELAY_TRANSMISSION_TYPE); APP_ERROR_CHECK(err_code); //Assign channel frequency err_code = sd_ant_channel_radio_freq_set( ANT_RELAY_SLAVE_CHANNEL, ANT_RELAY_FREQUENCY); APP_ERROR_CHECK(err_code); //Assign channel message period err_code = sd_ant_channel_period_set ( ANT_RELAY_SLAVE_CHANNEL, ANT_RELAY_CHANNEL_PERIOD); APP_ERROR_CHECK(err_code); err_code = sd_ant_prox_search_set(ANT_RELAY_SLAVE_CHANNEL, ANT_PROXIMITY_BIN, 0); APP_ERROR_CHECK(err_code); // DO NOT OPEN THE SLAVE RIGHT AWAY - IT OPENS ON BUTTON PRESS // OR MESSAGE FROM MOBILE PHONE }