コード例 #1
0
/**@brief Initializes controllable device. Sets up channel but does not open it.
 */
void phc_init(const asc_ant_params_t * const p_ant_params)
{
    uint32_t err_code;

    if(m_state == PHONE_OFF)
    {
        m_channel_number = p_ant_params->channel_number;
        m_device_number = *(p_ant_params->p_device_number);

        //Assign the slave channel
        err_code = sd_ant_channel_assign(m_channel_number, CHANNEL_TYPE_MASTER, p_ant_params->network_number, ASC_ANT_EXT_ASSIGNMENT);
        APP_ERROR_CHECK(err_code);

        //Assign channel id
        err_code = sd_ant_channel_id_set (m_channel_number, m_device_number, p_ant_params->device_type , p_ant_params->tx_type);
        APP_ERROR_CHECK(err_code);

        //Assign channel frequency
        err_code = sd_ant_channel_radio_freq_set (m_channel_number, p_ant_params->rf_frequency);
        APP_ERROR_CHECK(err_code);

        //Assign channel message period
        err_code = sd_ant_channel_period_set (m_channel_number, asc_get_counts_from_period_enum(p_ant_params->channel_period));
        APP_ERROR_CHECK(err_code);

        //Set the hub's transmission power
        err_code = sd_ant_channel_radio_tx_power_set (m_channel_number, p_ant_params->tx_power, 0);
        APP_ERROR_CHECK(err_code);
    }

}
コード例 #2
0
/**@brief Function for setting up ANT module to be ready for SDM RX broadcast.
 *
 * Issues the following commands:
 * - set network key
 * - assign channel
 * - set channel ID 
 * - set channel frequency
 * - set channel period
 * - open channel 
 */
static void ant_channel_sdm_rx_setup(void)
{
    uint32_t err_code;
    
    // Set network key.
    err_code = sd_ant_network_address_set(NETWORK_0, m_network_0_key);
    APP_ERROR_CHECK(err_code);
    
    // Set channel number.
    err_code = sd_ant_channel_assign(CHANNEL_0, 
                                     CHANNEL_TYPE_SLAVE, 
                                     NETWORK_0, 
                                     CHANNEL_0_ANT_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    // Set channel ID.
    err_code = sd_ant_channel_id_set(CHANNEL_0, 
                                     CHANNEL_0_CHAN_ID_DEV_NUM, 
                                     CHANNEL_0_CHAN_ID_DEV_TYPE, 
                                     CHANNEL_0_CHAN_ID_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);
    
    // Set channel radio frequency.
    err_code = sd_ant_channel_radio_freq_set(CHANNEL_0, CHANNEL_0_FREQUENCY);
    APP_ERROR_CHECK(err_code);
    
    // Set channel period.
    err_code = sd_ant_channel_period_set(CHANNEL_0, CHANNEL_0_RX_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);
    
    // Open channel.
    err_code = sd_ant_channel_open(CHANNEL_0);
    APP_ERROR_CHECK(err_code);
}
コード例 #3
0
/**@brief Function for configuring the ANT channel.
 */
static __INLINE void bicycle_power_channel_open(void)
{
    uint32_t err_code;

    // Set network address.
    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);

    // Set channel number.
    err_code = sd_ant_channel_assign(BP_RX_ANT_CHANNEL,
                                     CHANNEL_TYPE_SLAVE,
                                     ANTPLUS_NETWORK_NUMBER,
                                     BP_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    // Set channel ID.
    err_code = sd_ant_channel_id_set(BP_RX_ANT_CHANNEL,
                                     BP_RX_DEVICE_NUMBER,
                                     BP_DEVICE_TYPE,
                                     BP_RX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(BP_RX_ANT_CHANNEL, BP_RF_FREQ);
    APP_ERROR_CHECK(err_code);

    // Set channel period.
    err_code = sd_ant_channel_period_set(BP_RX_ANT_CHANNEL, BP_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Open channel.
    err_code = sd_ant_channel_open(BP_RX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);
}
コード例 #4
0
/**@brief Initialize the ANT HRM reception.
 */
static void ant_hrm_rx_init(void)
{
    uint32_t err_code;
    
    err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_ant_network_key);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_assign(ANT_HRMRX_ANT_CHANNEL,
                                     ANT_HRMRX_CHANNEL_TYPE,
                                     ANTPLUS_NETWORK_NUMBER,
                                     ANT_HRMRX_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_channel_id_set(ANT_HRMRX_ANT_CHANNEL,
                                     ANT_HRMRX_DEVICE_NUMBER,
                                     ANT_HRMRX_DEVICE_TYPE,
                                     ANT_HRMRX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_radio_freq_set(ANT_HRMRX_ANT_CHANNEL, ANTPLUS_RF_FREQ);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ant_channel_period_set(ANT_HRMRX_ANT_CHANNEL, ANT_HRMRX_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);
}
コード例 #5
0
ファイル: asc_master.c プロジェクト: lyncxy119/Sentry
// Public Functions
void ascm_init(const asc_ant_params_t * const ant_parameters)
{
    uint32_t err_code;
    m_channel_number = ant_parameters->channel_number;
    m_channel_period = ant_parameters->channel_period;
    deviceregistry_setup(pm_device_registry);

    err_code = sd_ant_channel_assign(m_channel_number,
                                     CHANNEL_TYPE_SHARED_MASTER,
                                     ant_parameters->network_number,
                                     ASC_ANT_EXT_ASSIGNMENT);
    APP_ERROR_CHECK(err_code);

    //Assign slave channel id.
    err_code = sd_ant_channel_id_set(m_channel_number,
                                     *(ant_parameters->p_device_number),
                                     ant_parameters->device_type,
                                     ant_parameters->tx_type);
    APP_ERROR_CHECK(err_code);

    //Assign slave channel frequency.
    err_code = sd_ant_channel_radio_freq_set(m_channel_number, ant_parameters->rf_frequency);
    APP_ERROR_CHECK(err_code);

    //Assign slave channel message period.
    err_code = sd_ant_channel_period_set(m_channel_number,
                                         asc_get_counts_from_period_enum(m_channel_period));
    APP_ERROR_CHECK(err_code);

    //Set the transmission power.
    err_code = sd_ant_channel_radio_tx_power_set(m_channel_number,
                                                 ant_parameters->tx_power,
                                                 ASC_ANT_CUSTOM_PWR);
    APP_ERROR_CHECK(err_code);
}
コード例 #6
0
ファイル: main.c プロジェクト: PolarState/nrf51
/**@brief Function for setting up the ANT module to be ready for RX broadcast.
 *
 * The following commands are issued in this order:
 * - assign channel
 * - set channel ID
 * - open channel
 */
static void ant_channel_rx_broadcast_setup(void)
{
    uint32_t err_code;

    // configure ant stack resources
    err_code = ant_stack_static_config();
    APP_ERROR_CHECK(err_code);
    
    // Set Channel Number.
    err_code = sd_ant_channel_assign(CHANNEL_0, 
                                     CHANNEL_TYPE_SLAVE_RX_ONLY, 
                                     ANT_CHANNEL_DEFAULT_NETWORK, 
                                     CHANNEL_0_ANT_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(CHANNEL_0, 
                                     CHANNEL_0_CHAN_ID_DEV_NUM, 
                                     CHANNEL_0_CHAN_ID_DEV_TYPE, 
                                     CHANNEL_0_CHAN_ID_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Open channel.
    err_code = sd_ant_channel_open(CHANNEL_0);
    APP_ERROR_CHECK(err_code);
}
コード例 #7
0
/**@brief Function for configuring the ANT channel.
 */
static __INLINE void channel_open(void)
{    
    // Set Network Address.
    uint32_t err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);
    
    // Set Channel Number.
    err_code = sd_ant_channel_assign(CBSC_TX_ANT_CHANNEL, 
                                     CBSC_TX_CHANNEL_TYPE, 
                                     ANTPLUS_NETWORK_NUMBER, 
                                     CBSC_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);
    
    // Set Channel ID.
    err_code = sd_ant_channel_id_set(CBSC_TX_ANT_CHANNEL, 
                                     CBSC_TX_DEVICE_NUMBER, 
                                     CBSC_DEVICE_TYPE, 
                                     CBSC_TX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set Channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(CBSC_TX_ANT_CHANNEL, CBSC_RF_FREQ);
    APP_ERROR_CHECK(err_code);

    // Set Channel period.
    err_code = sd_ant_channel_period_set(CBSC_TX_ANT_CHANNEL, CBSC_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);
  
    // Open Channel.
    err_code = sd_ant_channel_open(CBSC_TX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);
}
コード例 #8
0
uint32_t ant_channel_init(ant_channel_config_t const * p_config)
{
    uint32_t err_code;
    // Set Channel Number.
    err_code = sd_ant_channel_assign(p_config->channel_number, 
                                     p_config->channel_type, 
                                     p_config->network_number,
                                     p_config->ext_assign);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(p_config->channel_number, 
                                     p_config->device_number, 
                                     p_config->device_type, 
                                     p_config->transmission_type);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Set Channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(p_config->channel_number, p_config->rf_freq);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Set Channel period.
    if (!(p_config->ext_assign & EXT_PARAM_ALWAYS_SEARCH))
    {
        err_code = sd_ant_channel_period_set(p_config->channel_number, p_config->channel_period);
    }
    
    
#if ANT_CONFIG_ENCRYPTED_CHANNELS > 0
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    err_code = ant_channel_encrypt_config(p_config->channel_type , p_config->channel_number, p_config->p_crypto_settings);
#endif
    
    return err_code;
}
コード例 #9
0
ファイル: main.c プロジェクト: jafarnia/nrf51os
/**@brief Function for setting up the ANT module to be ready for TX broadcast.
 */
static void ant_channel_tx_broadcast_setup(void)
{
    uint32_t err_code;
    uint8_t  m_network_key[] = ANT_NETWORK_KEY;
    uint8_t m_broadcast_data[] = BROADCAST_PAYLOAD;

    // Set Network Key.
    err_code = sd_ant_network_address_set(ANT_NETWORK_NUMBER, (uint8_t*)m_network_key);
    APP_ERROR_CHECK(err_code);

    // Assign Channel
    err_code = sd_ant_channel_assign(ANT_CHANNEL_NUMBER,
                                     CHANNEL_TYPE_MASTER,
                                     ANT_NETWORK_NUMBER,
                                     ANT_EXT_ASSIGN);

    APP_ERROR_CHECK(err_code);

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(ANT_CHANNEL_NUMBER,
                                     ANT_DEV_NUM,
                                     ANT_DEV_TYPE,
                                     ANT_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);

    // Set Channel Period
    err_code = sd_ant_channel_period_set(ANT_CHANNEL_NUMBER, ANT_CHANNEL_PERIOD);
    APP_ERROR_CHECK(err_code);

    // Set RF Frequency
    err_code = sd_ant_channel_radio_freq_set(ANT_CHANNEL_NUMBER, ANT_RF_FREQUENCY);
    APP_ERROR_CHECK(err_code);

    //Set Tx Power
    err_code = sd_ant_channel_radio_tx_power_set(ANT_CHANNEL_NUMBER, RADIO_TX_POWER_LVL_3, ANT_TRANSMIT_POWER);
    APP_ERROR_CHECK(err_code);

    // Setup broadcast payload
    err_code = sd_ant_broadcast_message_tx(ANT_CHANNEL_NUMBER,
                                          BROADCAST_DATA_BUFFER_SIZE,
                                          m_broadcast_data);

    if(err_code != NRF_ANT_ERROR_CHANNEL_IN_WRONG_STATE)
    {
        APP_ERROR_CHECK(err_code);
    }

    // Open channel
    err_code = sd_ant_channel_open(ANT_CHANNEL_NUMBER);
    APP_ERROR_CHECK(err_code);
}
コード例 #10
0
ファイル: hrm_rx.c プロジェクト: BlueSkyGjj/nRF52
void hrm_rx_open(void)
{
    printf("Opening hrm rx channel...\n");  

    // Initialize data page structs.
    data_page_init();
  
    // Set Network Address.
    uint32_t err_code = sd_ant_network_address_set(ANTPLUS_NETWORK_NUMBER, m_network_key);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel Number.
    err_code = sd_ant_channel_assign(HRMRX_ANT_CHANNEL, 
                                     HRMRX_CHANNEL_TYPE, 
                                     ANTPLUS_NETWORK_NUMBER,
                                     HRMRX_EXT_ASSIGN);
    APP_ERROR_CHECK(err_code);  

    // Set Channel ID.
    err_code = sd_ant_channel_id_set(HRMRX_ANT_CHANNEL, 
                                     HRMRX_DEVICE_NUMBER, 
                                     HRMRX_DEVICE_TYPE, 
                                     HRMRX_TRANS_TYPE);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel RF frequency.
    err_code = sd_ant_channel_radio_freq_set(HRMRX_ANT_CHANNEL, ANTPLUS_RF_FREQ);
    APP_ERROR_CHECK(err_code);  
  
    // Set Channel period.
    err_code = sd_ant_channel_period_set(HRMRX_ANT_CHANNEL, HRMRX_MSG_PERIOD);
    APP_ERROR_CHECK(err_code);  

    // Open Channels.
    err_code = sd_ant_channel_open(HRMRX_ANT_CHANNEL);
    APP_ERROR_CHECK(err_code);  
} 
コード例 #11
0
/**@brief Sets the state machine to the specified state.
 */
static void ascmm_set_state(ascmm_states_t new_state)
{
    uint32_t err_code;

    if(new_state != m_state)
    {
        switch (new_state)
        {
            case ASCMM_OFF:
            {
                //Close the channel
                err_code = sd_ant_channel_close(m_discovery_channel_number);
                APP_ERROR_CHECK(err_code);
                break;
            }
            case DISCOVERY:
            {
                if (m_state != ASCMM_OFF)
                {
                    asc_event_set(&m_asc_event_flags, EVENT_ASC_DEVICE_IN_WRONG_STATE);
                    return;
                }

                m_state = new_state;
                //Open the discovery channel
                err_code = sd_ant_channel_open(m_discovery_channel_number);

                break;
            }
            case CONNECTED:
            {
                if (m_state != DISCOVERY)
                {
                    asc_event_set(&m_asc_event_flags, EVENT_ASC_DEVICE_IN_WRONG_STATE);
                    return;
                }
                m_state = new_state;

                //Close the channel
                err_code = sd_ant_channel_close(m_discovery_channel_number);
                APP_ERROR_CHECK(err_code);


                //Assign the connection channel
                err_code = sd_ant_channel_assign(m_ant_connected_parameters.channel_number,
                                                 m_ant_connected_parameters.channel_type,
                                                 m_ant_connected_parameters.network_number, 0);
                APP_ERROR_CHECK(err_code);

                //Set channel id
                err_code = sd_ant_channel_id_set (m_ant_connected_parameters.channel_number,
                                                  m_connection_device_number,
                                                  m_ant_connected_parameters.device_type,
                                                  m_ant_connected_parameters.tx_type);
                APP_ERROR_CHECK(err_code);

                //Set radio frequency
                err_code = sd_ant_channel_radio_freq_set (m_ant_connected_parameters.channel_number,
                                                          m_ant_connected_parameters.rf_frequency);
                APP_ERROR_CHECK(err_code);

                if(m_ant_connected_parameters.channel_type == CHANNEL_TYPE_SLAVE)
                {
                    //Configure search timeout for slave channel
                    err_code = sd_ant_channel_rx_search_timeout_set(m_ant_connected_parameters.channel_number,
                                                                    ASCMM_SEARCH_TIMEOUT);
                    APP_ERROR_CHECK(err_code);

                    err_code = sd_ant_channel_low_priority_rx_search_timeout_set(m_ant_connected_parameters.channel_number,
                                                                                 ASCMM_LP_SEARCH_TIMEOUT);
                    APP_ERROR_CHECK(err_code);
                }
                else
                {
                    // Configure Tx power for master chanel
                    err_code = sd_ant_channel_radio_tx_power_set(m_ant_connected_parameters.channel_number,
                                                                 m_ant_connected_parameters.tx_power, 0);
                    APP_ERROR_CHECK(err_code);
                }

                err_code = sd_ant_channel_open(m_ant_connected_parameters.channel_number);
                APP_ERROR_CHECK(err_code);

                break;
            }
            default:
            {
                //if the new state was not recognized, return to avoid setting the state changed event
                asc_event_set(&m_asc_event_flags, EVENT_ASC_DEVICE_IN_WRONG_STATE);
                return;
            }
        }
        asc_event_set(&m_asc_event_flags, EVENT_ASC_STATE_CHANGED);
    }
//lint --e{438}       
}
コード例 #12
0
// 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;
}
コード例 #13
0
ファイル: main.c プロジェクト: IOIOI/nRF51
/**@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;
}
コード例 #14
0
ファイル: main.c プロジェクト: BlueSkyGjj/nRF52
/**@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
}