rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,86 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_CHANNEL_CONFIG)
#include "nrf_error.h"
#include "ant_channel_config.h"
#include "ant_interface.h"
#include "ant_parameters.h"
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);
VERIFY_SUCCESS(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);
VERIFY_SUCCESS(err_code);
// Set Channel RF frequency.
err_code = sd_ant_channel_radio_freq_set(p_config->channel_number, p_config->rf_freq);
VERIFY_SUCCESS(err_code);
// Set Channel period.
if (!(p_config->ext_assign & EXT_PARAM_ALWAYS_SEARCH) && (p_config->channel_period != 0))
{
err_code = sd_ant_channel_period_set(p_config->channel_number, p_config->channel_period);
}
#if NRF_SDH_ANT_ENCRYPTED_CHANNELS > 0
VERIFY_SUCCESS(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;
}
#endif // NRF_MODULE_ENABLED(ANT_CHANNEL_CONFIG)

View file

@ -0,0 +1,98 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_CHANNEL_CONFIG_H__
#define ANT_CHANNEL_CONFIG_H__
/** @file
*
* @defgroup ant_channel_config ANT channel configuration
* @{
* @ingroup ant_sdk_utils
* @brief ANT channel configuration module.
*/
#include <stdint.h>
#include "sdk_config.h"
#ifndef NRF_SDH_ANT_ENCRYPTED_CHANNELS
#error Undefined NRF_SDH_ANT_ENCRYPTED_CHANNELS. It should be defined in sdk_config.h file.
#elif NRF_SDH_ANT_ENCRYPTED_CHANNELS > 0
#include "ant_encrypt_config.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**@brief ANT channel configuration structure. */
typedef struct
{
uint8_t channel_number; ///< Assigned channel number.
uint8_t channel_type; ///< Channel type (see Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
uint8_t ext_assign; ///< Extended assign (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
uint8_t rf_freq; ///< Radio frequency offset from 2400 MHz (for example, 2466 MHz, rf_freq = 66).
uint8_t transmission_type; ///< Transmission type.
uint8_t device_type; ///< Device type.
uint16_t device_number; ///< Device number.
uint16_t channel_period; ///< The period in 32 kHz counts.
uint8_t network_number; ///< Network number denoting the network key.
#if NRF_SDH_ANT_ENCRYPTED_CHANNELS > 0
ant_encrypt_channel_settings_t * p_crypto_settings; ///< Pointer to cryptographic settings, NULL if this configuration have to be omitted.
#endif
} ant_channel_config_t;
/**@brief Function for configuring the ANT channel.
*
* @param[in] p_config Pointer to the channel configuration structure.
*
* @retval NRF_SUCCESS If the channel was successfully configured. Otherwise, an error code is returned.
*/
uint32_t ant_channel_init(ant_channel_config_t const * p_config);
#ifdef __cplusplus
}
#endif
#endif // ANT_CHANNEL_CONFIG_H__
/** @} */

View file

@ -0,0 +1,245 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_ENCRYPT_CONFIG)
#include <stdlib.h>
#include "ant_encrypt_config.h"
#include "ant_interface.h"
#include "ant_parameters.h"
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
#include "ant_encrypt_negotiation_slave.h"
#endif
/*lint -e551 -save*/
/** Flag for checking if stack was configured for encryption. */
static bool m_stack_encryption_configured = false;
/*lint -restore */
/** Pointer to handler of module's events. */
static ant_encryp_user_handler_t m_ant_enc_evt_handler = NULL;
static ret_code_t ant_enc_advance_burs_config_apply(
ant_encrypt_adv_burst_settings_t const * const p_adv_burst_set);
ret_code_t ant_stack_encryption_config(ant_encrypt_stack_settings_t const * const p_crypto_set)
{
ret_code_t err_code;
for ( uint32_t i = 0; i < p_crypto_set->key_number; i++)
{
err_code = sd_ant_crypto_key_set(i, p_crypto_set->pp_key[i]);
VERIFY_SUCCESS(err_code);
}
if (p_crypto_set->p_adv_burst_config != NULL)
{
err_code = ant_enc_advance_burs_config_apply(p_crypto_set->p_adv_burst_config);
VERIFY_SUCCESS(err_code);
}
// subcomands LUT for @ref sd_ant_crypto_info_set calls
const uint8_t set_enc_info_param_lut[] =
{
ENCRYPTION_INFO_SET_CRYPTO_ID,
ENCRYPTION_INFO_SET_CUSTOM_USER_DATA,
ENCRYPTION_INFO_SET_RNG_SEED
};
for ( uint32_t i = 0; i < sizeof(set_enc_info_param_lut); i++)
{
if ( p_crypto_set->info.pp_array[i] != NULL)
{
err_code = sd_ant_crypto_info_set(set_enc_info_param_lut[i],
p_crypto_set->info.pp_array[i]);
VERIFY_SUCCESS(err_code);
}
}
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
// all ANT channels have unsupported slave encryption tracking (even master's channel)
ant_channel_encryp_negotiation_slave_init();
#endif
m_ant_enc_evt_handler = NULL;
m_stack_encryption_configured = true;
return NRF_SUCCESS;
}
/**
* @brief Function for configuring advanced burst settings according to encryption requirements.
*
* @param p_adv_burst_set Pointer to ANT advanced burst settings.
*
* @retval Value returned by @ref sd_ant_adv_burst_config_set.
*/
static ret_code_t ant_enc_advance_burs_config_apply(
ant_encrypt_adv_burst_settings_t const * const p_adv_burst_set)
{
uint8_t adv_burst_conf_str[ADV_BURST_CFG_MIN_SIZE] =
{ ADV_BURST_MODE_ENABLE, 0, 0, 0, 0, 0, 0, 0 };
adv_burst_conf_str[ADV_BURST_CFG_PACKET_SIZE_INDEX] = p_adv_burst_set->packet_length;
adv_burst_conf_str[ADV_BURST_CFG_REQUIRED_FEATURES] = p_adv_burst_set->required_feature;
adv_burst_conf_str[ADV_BURST_CFG_OPTIONAL_FEATURES] = p_adv_burst_set->optional_feature;
return sd_ant_adv_burst_config_set(adv_burst_conf_str, sizeof(adv_burst_conf_str));
}
ret_code_t ant_channel_encrypt_config_perform(uint8_t channel_number,
ant_encrypt_channel_settings_t * p_crypto_config)
{
return sd_ant_crypto_channel_enable(channel_number,
p_crypto_config->mode,
p_crypto_config->key_index,
p_crypto_config->decimation_rate);
}
ret_code_t ant_channel_encrypt_config(uint8_t channel_type,
uint8_t channel_number,
ant_encrypt_channel_settings_t * p_crypto_config)
{
ret_code_t err_code;
if (p_crypto_config != NULL)
{
// encryption of the stack should be initialized previously
if (m_stack_encryption_configured == false)
{
return NRF_ERROR_MODULE_NOT_INITIALZED;
}
switch (channel_type)
{
case CHANNEL_TYPE_MASTER:
err_code = ant_channel_encrypt_config_perform(channel_number, p_crypto_config);
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
ant_channel_encryp_tracking_state_set(channel_number,
ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED);
#endif
break;
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
case CHANNEL_TYPE_SLAVE:
ant_slave_channel_encrypt_config(channel_number, p_crypto_config);
if (p_crypto_config->mode == ENCRYPTION_DISABLED_MODE)
{
err_code = ant_channel_encrypt_config_perform(channel_number, p_crypto_config);
ant_channel_encryp_tracking_state_set(channel_number,
ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED);
}
else
{
ant_channel_encryp_tracking_state_set(channel_number,
ANT_ENC_CHANNEL_STAT_NOT_TRACKING);
err_code = NRF_SUCCESS;
}
break;
#endif
default:
err_code = NRF_ERROR_INVALID_PARAM;
break;
}
}
else
{
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
ant_channel_encryp_tracking_state_set(channel_number,
ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED);
#endif
err_code = NRF_SUCCESS;
}
return err_code;
}
/** @brief Function for calling the handler of module events.*/
static void ant_encrypt_user_handler_try_to_run(uint8_t ant_channel, ant_encrypt_user_evt_t event)
{
if (m_ant_enc_evt_handler != NULL)
{
m_ant_enc_evt_handler(ant_channel, event);
}
}
/**@brief Function for handling an ANT stack event.
* @param[in] p_ant_evt ANT stack event.
* @param[in] p_context Context.
*/
static void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
uint8_t const ant_channel = p_ant_evt->channel;
#ifdef ANT_ENCRYPT_NEGOTIATION_SLAVE_ENABLED
ant_slave_encrypt_negotiation(p_ant_evt);
#endif
switch (p_ant_evt->event)
{
case EVENT_RX_FAIL_GO_TO_SEARCH:
ant_encrypt_user_handler_try_to_run(ant_channel, ANT_ENC_EVT_CHANNEL_LOST);
break;
case EVENT_ENCRYPT_NEGOTIATION_SUCCESS:
ant_encrypt_user_handler_try_to_run(ant_channel, ANT_ENC_EVT_NEGOTIATION_SUCCESS);
break;
case EVENT_ENCRYPT_NEGOTIATION_FAIL:
ant_encrypt_user_handler_try_to_run(ant_channel, ANT_ENC_EVT_NEGOTIATION_FAIL);
break;
}
}
NRF_SDH_ANT_OBSERVER(m_ant_observer, ANT_ENCRYPT_ANT_OBSERVER_PRIO, ant_evt_handler, NULL);
void ant_enc_event_handler_register(ant_encryp_user_handler_t user_handler_func)
{
m_ant_enc_evt_handler = user_handler_func;
}
#endif // NRF_MODULE_ENABLED(ANT_ENCRYPT_CONFIG)

View file

@ -0,0 +1,241 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_ENCRYPT_CONFIG__
#define ANT_ENCRYPT_CONFIG__
/**@file
*
* @defgroup ant_encrypt_config ANT encryption configuration
* @{
* @ingroup ant_sdk_utils
*
* @brief Encryption configuration for the ANT stack and channels.
*
*/
#include <stdint.h>
#include "sdk_errors.h"
#include "nrf_sdh_ant.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @name Advanced burst configuration for encryption modules
* @{
*/
#define ADV_BURST_CFG_MIN_SIZE 8 ///< Minimum size of the advance burst configuration data.
#define ADV_BURST_CFG_PACKET_SIZE_INDEX 1 ///< Index of the packet size field in the configuration data.
#define ADV_BURST_CFG_REQUIRED_FEATURES 2 ///< Index of the required features field in the configuration data.
#define ADV_BURST_CFG_OPTIONAL_FEATURES 5 ///< Index of the optional features field in the configuration data.
/**@} */
/** @brief ANT channel cryptographic configuration. */
typedef struct
{
uint8_t mode; ///< Encryption mode. See the encrypted channel defines in ant_parameters.h.
uint8_t key_index; ///< Index of encryption key.
uint8_t decimation_rate; ///< Division of the master channel rate by the slaves tracking channel rate.
} ant_encrypt_channel_settings_t;
/** @brief ANT encryption information. */
typedef union
{
uint8_t * pp_array[3]; // For array access support.
struct
{
uint8_t * p_encryption_id; ///< Pointer to the encryption ID of the device (4 bytes).
uint8_t * p_user_info; ///< Pointer to the user information string (19 bytes).
uint8_t * p_random_num_seed; ///< Pointer to the random number seed (16 bytes).
} items;
} ant_encrypt_info_settings_t;
/** @brief Advanced burst settings used by the encrypted channel. */
typedef struct
{
uint8_t packet_length; ///< RF payload size. See the advanced burst configuration defines in ant_parameters.h.
uint8_t required_feature; ///< Required advanced burst modes. See the advanced burst configuration defines in ant_parameters.h.
uint8_t optional_feature; ///< Optional advanced burst modes. See the advanced burst configuration defines in ant_parameters.h.
} ant_encrypt_adv_burst_settings_t;
/**@brief ANT stack cryptographic configuration. */
typedef struct
{
ant_encrypt_info_settings_t info; ///< Pointer to the encryption information structure.
uint8_t * * pp_key; ///< Pointer to an array for pointers to encryption keys. Each key must have a length of 16 bytes.
uint8_t key_number; ///< Number of encryption keys.
ant_encrypt_adv_burst_settings_t * p_adv_burst_config; ///< Advanced burst configuration. If NULL, the advanced burst must be configured externally.
} ant_encrypt_stack_settings_t;
/**
* @brief ANT encryption negotiation events.
*/
typedef enum
{
ANT_ENC_EVT_NEGOTIATION_SUCCESS, ///< Negotiation success.
ANT_ENC_EVT_NEGOTIATION_FAIL, ///< Negotiation failure.
ANT_ENC_EVT_CHANNEL_LOST ///< Lost a channel. It's relevant only for slave channels.
} ant_encrypt_user_evt_t;
/**
* @brief Event handler for ANT encryption user events.
*/
typedef void (* ant_encryp_user_handler_t)(uint8_t channel, ant_encrypt_user_evt_t event);
/**
* @brief Macro for initializing an ANT encryption information structure.
*
* @param[in] P_ENC_ID Pointer to the encryption ID of the device (4 bytes).
* @param[in] P_USER_INFO Pointer to the user information string (19 bytes).
* @param[in] P_RAND_NUM_SEED Pointer to the random number seed (16 bytes).
*/
#define ANT_CRYPTO_INFO_SETTINGS_INIT(P_ENC_ID, P_USER_INFO, P_RAND_NUM_SEED) \
{ \
.items = \
{ \
.p_encryption_id = P_ENC_ID, \
.p_user_info = P_USER_INFO, \
.p_random_num_seed = P_RAND_NUM_SEED \
} \
}
/**
* @brief Macro for declaring the basic cryptographic configuration for the ANT stack.
*
* This macro configures the following settings:
* - Cryptographic key
* - Encryption ID
* - Advanced burst mode with the maximum RF payload size
*
* Use @ref ANT_ENCRYPT_STACK_SETTINGS_BASE to access the created configuration instance.
*
* @param[in] NAME Name for the created data instance.
* @param[in] P_KEY Pointer to the cryptographic key (16 bytes).
* @param[in] P_ENC_ID Pointer to the encryption ID (4 bytes).
*/
#define ANT_ENCRYPT_STACK_SETTINGS_BASE_DEF(NAME, P_KEY, P_ENC_ID) \
ant_encrypt_adv_burst_settings_t NAME##_ant_enc_adv_burst_set = \
{ \
.packet_length = ADV_BURST_MODES_MAX_SIZE, \
.required_feature = 0, \
.optional_feature = 0 \
}; \
uint8_t * pp_##NAME##_key[1] = {P_KEY}; \
ant_encrypt_stack_settings_t NAME ## _ant_crypto_settings = \
{ \
.info = ANT_CRYPTO_INFO_SETTINGS_INIT(P_ENC_ID, NULL, NULL), \
.pp_key = pp_##NAME##_key, \
.key_number = 1, \
.p_adv_burst_config = &NAME##_ant_enc_adv_burst_set \
}
/** @brief Macro for accessing the configuration instance created
* by @ref ANT_ENCRYPT_STACK_SETTINGS_BASE_DEF.
*
* @param[in] NAME Name of the settings instance.
*/
#define ANT_ENCRYPT_STACK_SETTINGS_BASE(NAME) (NAME##_ant_crypto_settings)
/**
* @brief Function for applying an encryption configuration to a slave channel.
*
* This function enables encryption on a channel.
*
* This function should be used by the @ref ant_encrypt_negotiation_slave module and this module.
*
* @param[in] channel_number ANT channel number.
* @param[in] p_crypto_config Pointer to the encryption configuration.
*
* @return Value returned by @ref sd_ant_crypto_channel_enable (for example, NRF_SUCCESS if
* the configuration was successful).
*/
ret_code_t ant_channel_encrypt_config_perform(uint8_t channel_number,
ant_encrypt_channel_settings_t * p_crypto_config);
/**
* @brief Function for applying an encryption configuration to a master or slave channel.
*
* When called for a master channel, this function enables encryption
* for that channel. When called for a slave channel, it saves
* the encryption configuration for future use.
*
* This function should be used by the @ref ant_channel_config module.
*
* @param[in] channel_type ANT channel type: CHANNEL_TYPE_SLAVE or CHANNEL_TYPE_MASTER.
* @param[in] channel_num ANT channel number.
* @param[in] p_crypto_config Pointer to the encryption configuration.
*
* @retval NRF_SUCCESS If the function completed successfully.
* @retval NRF_ERROR_INVALID_PARAM If the channel type is invalid.
* @retval NRF_ERROR_MODULE_NOT_INITIALZED If the stack is not configured for encryption.
* @retval Other Otherwise, the error value returned by the @ref
* ant_channel_encrypt_config_perform function is returned.
*/
ret_code_t ant_channel_encrypt_config(uint8_t channel_type,
uint8_t channel_num,
ant_encrypt_channel_settings_t * p_crypto_config);
/**
* @brief Function for configuring the cryptographic settings of the ANT stack.
*
* @param[in] p_crypto_info_set Pointer to the settings.
*/
ret_code_t ant_stack_encryption_config(ant_encrypt_stack_settings_t const * const p_crypto_info_set);
/**
* @brief Function for registering an event handler for ANT encryption events.
*
* The event handler should support all of the events in @ref ant_encrypt_user_evt_t.
*
* @param[in] p_handler Pointer to a handler function.
*/
void ant_enc_event_handler_register(ant_encryp_user_handler_t p_handler);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_ENCRYPT_CONFIG__

View file

@ -0,0 +1,185 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_ENCRYPT_NEGOTIATION_SLAVE)
#include <stdlib.h>
#include <string.h>
#include "ant_encrypt_config.h"
#include "ant_interface.h"
#include "ant_parameters.h"
#include "nrf_error.h"
#include "app_error.h"
#include "ant_encrypt_negotiation_slave.h"
/** Number of supported channels. */
#define NUMBER_OF_CHANNELS (NRF_SDH_ANT_TOTAL_CHANNELS_ALLOCATED)
/** Flag to block other channels from attempting to enable encryption while
* another encryption is in the process.
*/
static volatile bool m_can_enable_crypto = true;
/** Array to keep track of which channels are currently tracking. */
static ant_encrypt_tracking_state_t m_encrypt_channel_states[NUMBER_OF_CHANNELS];
/** Array for the slave channels' encryption settings. */
static ant_encrypt_channel_settings_t m_slave_channel_conf[MAX_ANT_CHANNELS];
void ant_channel_encryp_tracking_state_set(uint8_t channel_number,
ant_encrypt_tracking_state_t state)
{
m_encrypt_channel_states[channel_number] = state;
}
void ant_channel_encryp_negotiation_slave_init(void)
{
for (uint32_t channel = 0; channel < NUMBER_OF_CHANNELS; channel++)
{
ant_channel_encryp_tracking_state_set(channel, ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED);
}
m_can_enable_crypto = true;
}
ant_encrypt_tracking_state_t ant_channel_encryp_tracking_state_get(uint8_t channel_number)
{
return m_encrypt_channel_states[channel_number];
}
void ant_slave_channel_encrypt_config(uint8_t channel_number,
ant_encrypt_channel_settings_t const * const p_crypto_config)
{
memcpy(&m_slave_channel_conf[channel_number], p_crypto_config,
sizeof(ant_encrypt_channel_settings_t));
}
/**@brief Function for handling ANT RX channel events.
*
* @param[in] p_event_message_buffer The ANT event message buffer.
*/
static void ant_slave_encrypt_try_enable(uint8_t ant_channel,
uint8_t ant_message_id)
{
uint32_t err_code;
ant_encrypt_tracking_state_t track_stat;
switch (ant_message_id)
{
// Broadcast data received.
case MESG_BROADCAST_DATA_ID:
track_stat = ant_channel_encryp_tracking_state_get(ant_channel);
// If the encryption has not yet been negotiated for this channel and another channel
// is not currently trying to enable encryption, enable encryption
if ((track_stat != ANT_ENC_CHANNEL_STAT_TRACKING_DECRYPTED)
&& (track_stat != ANT_ENC_CHANNEL_STAT_NEGOTIATING)
&& m_can_enable_crypto)
{
// Block other channels from trying to enable encryption until this channel
// is finished
m_can_enable_crypto = false;
ant_channel_encryp_tracking_state_set(ant_channel,
ANT_ENC_CHANNEL_STAT_NEGOTIATING);
// Enable encryption on ant_channel
err_code =
ant_channel_encrypt_config_perform(ant_channel,
&m_slave_channel_conf[ant_channel]);
APP_ERROR_CHECK(err_code);
}
break;
default:
break;
}
}
void ant_slave_encrypt_negotiation(ant_evt_t * p_ant_evt)
{
ant_encrypt_tracking_state_t track_state =
ant_channel_encryp_tracking_state_get(p_ant_evt->channel);
if (track_state == ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED)
return;
switch (p_ant_evt->event)
{
case EVENT_RX_FAIL_GO_TO_SEARCH:
if (track_state == ANT_ENC_CHANNEL_STAT_NEGOTIATING)
{
m_can_enable_crypto = true;
}
ant_channel_encryp_tracking_state_set(p_ant_evt->channel,
ANT_ENC_CHANNEL_STAT_NOT_TRACKING);
break;
case EVENT_RX:
ant_slave_encrypt_try_enable(p_ant_evt->channel,
p_ant_evt->message.ANT_MESSAGE_ucMesgID);
break;
case EVENT_ENCRYPT_NEGOTIATION_SUCCESS:
m_can_enable_crypto = true;
ant_channel_encryp_tracking_state_set(p_ant_evt->channel,
ANT_ENC_CHANNEL_STAT_TRACKING_DECRYPTED);
break;
case EVENT_ENCRYPT_NEGOTIATION_FAIL:
m_can_enable_crypto = true;
ant_channel_encryp_tracking_state_set(p_ant_evt->channel,
ANT_ENC_CHANNEL_STAT_TRACKING_ENCRYPTED);
break;
default:
break;
}
}
#endif // NRF_MODULE_ENABLED(ANT_ENCRYPT_NEGOTIATION_SLAVE)

View file

@ -0,0 +1,140 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_ENCRYPT_NEGOTIATION_SLAVE_H__
#define ANT_ENCRYPT_NEGOTIATION_SLAVE_H__
/**@file
*
* @defgroup ant_encrypt_negotiation_slave ANT encryption negotiation
* @{
* @ingroup ant_sdk_utils
*
* @brief Encryption negotiation for encrypted ANT slave channels.
*
* After pairing, the slave starts negotiating the encryption with the master. After
* successful negotiation, the slave can decrypt messages from the master, and all
* future messages are sent encrypted.
*
*/
#include <stdint.h>
#include "nrf_sdh_ant.h"
#include "ant_encrypt_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Encryption negotiation states for a slave channel. */
typedef enum
{
ANT_ENC_CHANNEL_STAT_NOT_TRACKING, ///< Not tracking the master.
ANT_ENC_CHANNEL_STAT_TRACKING_ENCRYPTED, ///< Tracking the master, but cannot decrypt messages.
ANT_ENC_CHANNEL_STAT_NEGOTIATING, ///< Encryption has been enabled and negotiation is in progress.
ANT_ENC_CHANNEL_STAT_TRACKING_DECRYPTED, ///< Tracking the master and can decrypt messages.
ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED ///< Tracking unsupported on this channel.
} ant_encrypt_tracking_state_t;
/**
* @brief Function for setting the encryption negotiation state of a slave ANT channel.
*
* This function should be used by the @ref ant_encrypt_config module.
*
* @param[in] channel_number ANT channel number.
* @param[in] state State to set.
*/
void ant_channel_encryp_tracking_state_set(uint8_t channel_number,
ant_encrypt_tracking_state_t state);
/**
* @brief Function for getting the encryption negotiation state of a slave ANT channel.
*
* @param[in] channel_number ANT channel number.
*/
ant_encrypt_tracking_state_t ant_channel_encryp_tracking_state_get(uint8_t channel_number);
/**
* @brief Function for initializing the module.
*
* This function initializes internal states of the module. It should
* only be used by the @ref ant_encrypt_config module.
*
*/
void ant_channel_encryp_negotiation_slave_init(void);
/**
* @brief Function for setting the configuration for the slave channel.
*
* This function saves the channel's encryption configuration to a lookup table (LUT) for
* future usage. The configuration can then be used to enable encryption.
*
* This function is intended to be used by the @ref ant_encrypt_config module.
*
* @param[in] channel_number ANT channel number.
* @param[in] p_crypto_config Pointer to the encryption configuration.
*/
void ant_slave_channel_encrypt_config(uint8_t channel_number,
ant_encrypt_channel_settings_t const * const p_crypto_config);
/**
* @brief Function for handling ANT encryption negotiation on slave nodes.
*
* This function should be used directly in the ANT event dispatching process. It
* tries to enable slave channel encryption for all slave channels that are declared
* as encrypted channels (if appropriate master channels are found).
*
* This function should be used by the @ref ant_encrypt_config module.
*
* @param[in] p_ant_evt Pointer to the ANT stack event message structure.
*/
void ant_slave_encrypt_negotiation(ant_evt_t * p_ant_evt);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_ENCRYPT_NEGOTIATION_SLAVE_H__

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,396 @@
/**
* This software is subject to the ANT+ Shared Source License
* www.thisisant.com/swlicenses
* Copyright (c) Dynastream Innovations, Inc. 2012
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3) Neither the name of Dynastream nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission.
*
* The following actions are prohibited:
* 1) Redistribution of source code containing the ANT+ Network
* Key. The ANT+ Network Key is available to ANT+ Adopters.
* Please refer to http://thisisant.com to become an ANT+
* Adopter and access the key.
*
* 2) Reverse engineering, decompilation, and/or disassembly of
* software provided in binary form under this license.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE HEREBY
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; DAMAGE TO ANY DEVICE, LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. SOME STATES DO NOT ALLOW
* THE EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
* ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
*
*/
/**@file
* @brief The ANT-FS client protocol interface.
* This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012
* @defgroup ant_fs ANT-FS client device simulator
* @{
* @ingroup ant_sdk_utils
*
* @brief The ANT-FS client device simulator.
*
* @note The ANT-FS Network Key is available for ANT+ Adopters. Please refer to http://thisisant.com to become an ANT+ Adopter and access the key.
*/
#ifndef ANTFS_H__
#define ANTFS_H__
#include <stdint.h>
#include <stdbool.h>
#include "defines.h"
#include "sdk_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ANTFS_VERSION_MAJOR 1u /**< Version major number. */
#define ANTFS_VERSION_MINOR 0 /**< Version minor number. */
#define ANTFS_VERSION_ITERATION 0 /**< Version iteration. */
#define ANTFS_VERSION_TYPE 'R' /**< Version type is release. */
#define ANTFS_VERSION_SPEC '0.AK' /**< Version of the ANT-FS Technology Specification. */
#define ANTFS_DIR_STRUCT_VERSION 1u /**< Version of the directory file structure. */
#define ANTFS_VERSION_DATE 20090522u /**< Version date. */
// ANT-FS options.
#define ANTFS_LINK_FREQ 50u /**< RF Frequency (+2400MHz). */
#define ANTFS_CHANNEL_TYPE CHANNEL_TYPE_MASTER /**< ANT-FS Client Channel Type. */
#define ANTFS_AUTH_STRING_MAX 255u /**< Maximum size of authentication strings (passkey/friendly name). */
#define ANTFS_PASSKEY_SIZE 16u /**< Passkey size. */
#define ANTFS_FRIENDLY_NAME_MAX 16u /**< Maximum size of friendly name received from host. */
#define ANTFS_REMOTE_FRIENDLY_NAME_MAX 16u /**< Maximum size of client's friendly name. */
// Beacon definitions.
#define BEACON_PERIOD_SHIFT 0x00 /**< Shift value for masking out beacon period. */
#define BEACON_PERIOD_MASK (0x07u << BEACON_PERIOD_SHIFT) /**< Beacon period bitmask. */
#define BEACON_PERIOD_0_5_HZ (0x00 << BEACON_PERIOD_SHIFT) /**< Value for 0,5Hz beacon period. */
#define BEACON_PERIOD_1_HZ (0x01u << BEACON_PERIOD_SHIFT) /**< Value for 1Hz beacon period. */
#define BEACON_PERIOD_2_HZ (0x02u << BEACON_PERIOD_SHIFT) /**< Value for 2Hz beacon period. */
#define BEACON_PERIOD_4_HZ (0x03u << BEACON_PERIOD_SHIFT) /**< Value for 4Hz beacon period. */
#define BEACON_PERIOD_8_HZ (0x04u << BEACON_PERIOD_SHIFT) /**< Value for 8Hz beacon period. */
#define PAIRING_AVAILABLE_FLAG_SHIFT 0x03u /**< Shift value for masking out pairing enabled bit. */
#define PAIRING_AVAILABLE_FLAG_MASK (0x01u << PAIRING_AVAILABLE_FLAG_SHIFT) /**< Pairing enabled bitmask. */
#define UPLOAD_ENABLED_FLAG_SHIFT 0x04u /**< Shift value for masking out upload enabled bit. */
#define UPLOAD_ENABLED_FLAG_MASK (0x01u << UPLOAD_ENABLED_FLAG_SHIFT) /**< Upload enabled bitmask. */
#define DATA_AVAILABLE_FLAG_SHIFT 0x05u /**< Shift value for masking out data available bit. */
#define DATA_AVAILABLE_FLAG_MASK (0x01u << DATA_AVAILABLE_FLAG_SHIFT) /**< Data available bitmask. */
#if ANTFS_ENABLED
// Build the default beacon settings.
#if ANTFS_CONFIG_AUTH_TYPE_PAIRING_ENABLED
#define ANTFS_PAIRING_BIT PAIRING_AVAILABLE_FLAG_MASK /**< Build pairing enabled default beacon setting. */
#else
#define ANTFS_PAIRING_BIT 0x00u /**< Build pairing disabled default beacon setting. */
#endif // ANTFS_CONFIG_AUTH_TYPE_PAIRING_ENABLED
#if ANTFS_CONFIG_UPLOAD_ENABLED
#define ANTFS_UPLOAD_BIT UPLOAD_ENABLED_FLAG_MASK /**< Build upload enabled default beacon setting. */
#else
#define ANTFS_UPLOAD_BIT 0x00u /**< Build upload disabled default beacon setting. */
#endif // ANTFS_CONFIG_UPLOAD_ENABLED
#define ANTFS_DEFAULT_BEACON (ANTFS_CONFIG_BEACON_STATUS_PERIOD | ANTFS_UPLOAD_BIT | ANTFS_PAIRING_BIT | DATA_AVAILABLE_FLAG_MASK) /**< Define the default beacon setting. */
#endif // ANTFS_ENABLED
// Download/Upload responses.
#define RESPONSE_MESSAGE_OK 0x00u /**< Download request ok. */
#define RESPONSE_MESSAGE_NOT_EXIST 0x01u /**< File does not exist. */
#define RESPONSE_MESSAGE_NOT_AVAILABLE 0x02u /**< File can not be read/written to (download/upload respectively). */
#define RESPONSE_INVALID_OPERATION 0x04u /**< Request invalid. */
// Download responses.
#define RESPONSE_MESSAGE_NOT_READY 0x03u /**< Not ready to download. */
#define RESPONSE_INVALID_CRC 0x05u /**< CRC incorrect. */
// Upload responses.
#define RESPONSE_MESSAGE_NOT_ENOUGH_SPACE 0x03u /**< Not enough space to to complete write. */
#define RESPONSE_MESSAGE_UPLOAD_NOT_READY 0x05u /**< Not ready to upload */
// Upload/Erase responses.
#define RESPONSE_MESSAGE_FAIL 0x01u /**< Data File Index does not exist / Erase failed. */
// Directory general file flags.
#define ANTFS_DIR_READ_MASK 0x80u /**< Read (can download). */
#define ANTFS_DIR_WRITE_MASK 0x40u /**< Write (can upload). */
#define ANTFS_DIR_ERASE_MASK 0x20u /**< Erase (can erase). */
#define ANTFS_DIR_ARCHIVE_MASK 0x10u /**< Archive (has been downloaded). */
#define ANTFS_DIR_APPEND_MASK 0x08u /**< Append (can append to file only). */
#define ANTFS_MAX_FILE_SIZE 0xFFFFFFFFu /**< Maximum file size, as specified by directory structure. */
#define ANTFS_BURST_BLOCK_SIZE 16u /**< Size of each block of burst data that the client attempts to send when it processes a data request event. */
/**@brief ANT-FS beacon status. */
typedef union
{
uint32_t status; /**< Beacon status byte 1. */
struct
{
uint32_t link_period : 3; /**< Beacon period (0.5 - 8 Hz). */
bool is_pairing_enabled : 1; /**< Pairing is enabled/disabled. */
bool is_upload_enabled : 1; /**< Upload is enabled/disabled. */
bool is_data_available : 1; /**< Data is available for download / no data available. */
bool reserved : 2; /**< Reserved. */
} parameters;
} antfs_beacon_status_byte1_t;
// ANT-FS states.
typedef enum
{
ANTFS_STATE_OFF, /**< Off state. */
ANTFS_STATE_INIT, /**< Init state. */
ANTFS_STATE_LINK, /**< Link state. */
ANTFS_STATE_AUTH, /**< Authenticate state. */
ANTFS_STATE_TRANS /**< Transport state. */
} antfs_state_t;
// ANT-FS link layer substates.
typedef enum
{
ANTFS_LINK_SUBSTATE_NONE /**< None state. */
} antfs_link_substate_t;
// ANT-FS authenticate layer substates. */
typedef enum
{
ANTFS_AUTH_SUBSTATE_NONE, /**< None state. */
ANTFS_AUTH_SUBSTATE_PAIR, /**< Pairing state. */
ANTFS_AUTH_SUBSTATE_PASSKEY, /**< Passkey state. */
ANTFS_AUTH_SUBSTATE_ACCEPT, /**< Authenticate accept state. */
ANTFS_AUTH_SUBSTATE_REJECT /**< Authenticate reject state. */
} antfs_authenticate_substate_t;
// ANT-FS transport layer substates. */
typedef enum
{
ANTFS_TRANS_SUBSTATE_NONE, /**< None state. */
ANTFS_TRANS_SUBSTATE_VERIFY_CRC, /**< Verify CRC state. */
ANTFS_TRANS_SUBSTATE_DOWNLOADING, /**< Downloading state. */
ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA, /**< Wait for upload data request state. */
ANTFS_TRANS_SUBSTATE_UPLOADING, /**< Ready / receiving upload data state. */
ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME /**< RX failure upon receiving upload data state. */
} antfs_transport_substate_t;
// ANT-FS Events.
typedef enum
{
ANTFS_EVENT_PAIRING_REQUEST = 0xB0, /**< Pairing request event. */
ANTFS_EVENT_PAIRING_TIMEOUT = 0xB1, /**< Pairing timeout event. */
ANTFS_EVENT_OPEN_COMPLETE = 0xB2, /**< Channel setup complete event. */
ANTFS_EVENT_CLOSE_COMPLETE = 0xB4, /**< Channel closed event. */
ANTFS_EVENT_LINK = 0xB6, /**< Enter link layer event. */
ANTFS_EVENT_AUTH = 0xB7, /**< Enter authenticate layer event. */
ANTFS_EVENT_TRANS = 0xB8, /**< Enter transport layer event. */
ANTFS_EVENT_DOWNLOAD_REQUEST = 0xB9, /**< Download request event. */
ANTFS_EVENT_DOWNLOAD_REQUEST_DATA = 0xBA, /**< Download request data event. */
ANTFS_EVENT_DOWNLOAD_START = 0xBB, /**< Download started event. */
ANTFS_EVENT_DOWNLOAD_COMPLETE = 0xBC, /**< Download completed event. */
ANTFS_EVENT_DOWNLOAD_FAIL = 0xBD, /**< Download failed event. */
ANTFS_EVENT_UPLOAD_REQUEST = 0xBE, /**< Upload request event. */
ANTFS_EVENT_UPLOAD_DATA = 0xBF, /**< Upload data available for read event. */
ANTFS_EVENT_UPLOAD_START = 0xC0, /**< Upload begin event. */
ANTFS_EVENT_UPLOAD_COMPLETE = 0xC1, /**< Upload completed event. */
ANTFS_EVENT_UPLOAD_FAIL = 0xC2, /**< Upload process failed event. */
ANTFS_EVENT_ERASE_REQUEST = 0xC3 /**< Erase request event. */
} antfs_event_t;
/**@brief ANT-FS <-> application event communication object. */
typedef struct
{
antfs_event_t event; /**< ANT-FS event. */
uint16_t file_index; /**< File index (download/upload/erase). */
uint32_t offset; /**< Current offset (download/upload). */
uint32_t bytes; /**< Number of bytes in block (download/upload). */
uint16_t crc; /**< Current CRC (upload). */
uint8_t data[8]; /**< Block of data (upload). */
} antfs_event_return_t;
/**@brief ANT-FS parameters. */
typedef struct
{
uint32_t client_serial_number; /**< Client serial number. */
uint16_t beacon_device_type; /**< Client device type. */
uint16_t beacon_device_manufacturing_id; /**< Client manufacturing ID. */
uint8_t beacon_frequency; /**< Beacon RF Frequency. */
antfs_beacon_status_byte1_t beacon_status_byte1; /**< Beacon status byte 1. */
const uint8_t * p_pass_key; /**< Pass Key. */
const uint8_t * p_remote_friendly_name; /**< Friendly Name. */
} antfs_params_t;
/**@brief ANT-FS directory header. */
typedef struct
{
uint8_t version; /**< Version of the directory file structure. */
uint8_t length; /**< Length of each structure, in bytes. */
uint8_t time_format; /**< Defines how system keeps track of date/time stamps. */
uint8_t reserved01;
uint8_t reserved02;
uint8_t reserved03;
uint8_t reserved04;
uint8_t reserved05;
uint32_t system_time; /**< Number of seconds elapsed since system power up. */
uint32_t date; /**< Number of seconds elapsed since 00:00 hrs Dec 31, 1989. If system time is unknown, used as counter. */
} antfs_dir_header_t;
/**@brief ANT-FS directory entry. */
typedef struct
{
uint16_t data_file_index; /**< Data file index. */
uint8_t file_data_type; /**< File data type. */
uint8_t user_defined1; /**< Identifier, first byte (structure defined by data type). */
uint16_t user_defined2; /**< Identifier, last two bytes (structure defined by data type). */
uint8_t user_flags; /**< File data type specific flags (bits defined by data type). */
uint8_t general_flags; /**< Bit mapped flags of flag permissions. */
uint32_t file_size_in_bytes; /**< File size, in bytes. */
uint32_t date; /**< Number of seconds elapsed since 00:00 hrs Dec 31, 1980, if supported. */
} antfs_dir_struct_t;
/**@brief ANT-FS download/upload request context. */
typedef struct
{
ulong_union_t file_size; /**< Size of a file to download when reading, or the size of a partially completed upload when writing. */
uint32_t max_file_size; /**< The maximum size of the file specified, this is the file size when reading, and the maximum allowed file size when writing. */
ulong_union_t max_burst_block_size; /**< Maximum burst block size. */
ushort_union_t file_index; /**< File index. */
uint16_t file_crc; /**< CRC (uploads). */
} antfs_request_info_t;
/**@brief The burst wait handler can be configured by the application to customize the code that is
* executed while waiting for the burst busy flag. */
typedef void(*antfs_burst_wait_handler_t)(void);
/**@brief Function for setting initial ANT-FS configuration parameters.
*
* @param[in] p_params The initial ANT-FS configuration parameters.
* @param[in] burst_wait_handler Burst wait handler.
*/
void antfs_init(const antfs_params_t * const p_params,
antfs_burst_wait_handler_t burst_wait_handler);
/**@brief Function for getting host name if received.
*
* @return Pointer to host name buffer if a host name was recieved, NULL otherwise.
*/
const char * antfs_hostname_get(void);
/**@brief Function for transmitting a response to a pairing request issued by ANT-FS host.
*
* @param[in] accept The pairing response, true if pairing accepted.
*
* @retval true Operation success. Response to a pairing request was transmitted.
* @retval false Operation failure. Not in pairing mode or pairing not supported by the
* implementation.
*/
bool antfs_pairing_resp_transmit(bool accept);
/**@brief Function for doing calculations prior downloading the data to the ANT-FS host.
*
* Function does the necessary pre processing calculations, which are required prior downloading the
* data, and also transmits the download request response right away in case of the download request
* was rejected or there is no data to send.
*
* @param[in] response The download request response code.
* @param[in] p_request_info ANT-FS request info structure.
*/
void antfs_download_req_resp_prepare(uint8_t response,
const antfs_request_info_t * const p_request_info);
/**@brief Function for downloading requested data.
*
* @param[in] index Index of the current file downloaded.
* @param[in] offset Offset specified by client.
* @param[in] num_bytes Number of bytes requested to be transmitted from the buffer.
* @param[in] p_message Data buffer to be transmitted.
*
* @return Number of data bytes transmitted.
*/
uint32_t antfs_input_data_download(uint16_t index,
uint32_t offset,
uint32_t num_bytes,
const uint8_t * const p_message);
/**@brief Function for transmitting upload request response to a upload request command by ANT-FS
* host.
*
* @param[in] response The upload response code.
* @param[in] p_request_info ANT-FS request info structure.
*
* @retval true Operation success. Response to upload request command was transmitted.
* @retval false Operation failure. Upload not supported by the implementation or not in correct
* state or application is sending a response for a different file
* than requested.
*/
bool antfs_upload_req_resp_transmit(uint8_t response,
const antfs_request_info_t * const p_request_info);
/**@brief Function for transmitting upload data response to a upload data command by ANT-FS host.
*
* @param[in] data_upload_success The upload response code, true for success.
*
* @retval true Operation success. Response to upload data command was transmitted.
* @retval false Operation failure. Upload not supported by the implementation or not in correct
* state.
*/
bool antfs_upload_data_resp_transmit(bool data_upload_success);
/**@brief Function for transmitting erase response to a erase request.
*
* @param[in] response The erase response code.
*/
void antfs_erase_req_resp_transmit(uint8_t response);
/**@brief Function for extracting possible pending ANT-FS event.
*
* @param[out] p_event The output event structure.
*
* @retval true Operation success. Pending ANT-FS event available and it was copied to the output
* event structure.
* @retval false Operation failure. No pending ANT-FS event available.
*/
bool antfs_event_extract(antfs_event_return_t * const p_event);
/**@brief Function for processing ANT events and data received from the ANT-FS channel.
*
* @param[in] p_message The message buffer containing the message received from the ANT-FS
* channel.
*/
void antfs_message_process(uint8_t * p_message);
/**@brief Function for setting up the ANT-FS channel.
*/
void antfs_channel_setup(void);
#ifdef __cplusplus
}
#endif
#endif // ANTFS_H__
/**
*@}
**/

View file

@ -0,0 +1,98 @@
/**
* This software is subject to the ANT+ Shared Source License
* www.thisisant.com/swlicenses
* Copyright (c) Dynastream Innovations, Inc. 2012
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3) Neither the name of Dynastream nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission.
*
* The following actions are prohibited:
* 1) Redistribution of source code containing the ANT+ Network
* Key. The ANT+ Network Key is available to ANT+ Adopters.
* Please refer to http://thisisant.com to become an ANT+
* Adopter and access the key.
*
* 2) Reverse engineering, decompilation, and/or disassembly of
* software provided in binary form under this license.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE HEREBY
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; DAMAGE TO ANY DEVICE, LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. SOME STATES DO NOT ALLOW
* THE EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
* ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
*
*/
#include "crc.h"
#include "compiler_abstraction.h"
/**@brief Function for updating the current CRC-16 value for a single byte input.
*
* @param[in] current_crc The current calculated CRC-16 value.
* @param[in] byte The input data byte for the computation.
*
* @return The updated CRC-16 value, based on the input supplied.
*/
static __INLINE uint16_t crc16_get(uint16_t current_crc, uint8_t byte)
{
static const uint16_t crc16_table[16] =
{
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
uint16_t temp;
// Compute checksum of lower four bits of a byte.
temp = crc16_table[current_crc & 0xF];
current_crc = (current_crc >> 4u) & 0x0FFFu;
current_crc = current_crc ^ temp ^ crc16_table[byte & 0xF];
// Now compute checksum of upper four bits of a byte.
temp = crc16_table[current_crc & 0xF];
current_crc = (current_crc >> 4u) & 0x0FFFu;
current_crc = current_crc ^ temp ^ crc16_table[(byte >> 4u) & 0xF];
return current_crc;
}
uint16_t crc_crc16_update(uint16_t current_crc, const volatile void * p_data, uint32_t size)
{
uint8_t * p_block = (uint8_t *)p_data;
while (size != 0)
{
current_crc = crc16_get(current_crc, *p_block);
p_block++;
size--;
}
return current_crc;
}

View file

@ -0,0 +1,94 @@
/**
* This software is subject to the ANT+ Shared Source License
* www.thisisant.com/swlicenses
* Copyright (c) Dynastream Innovations, Inc. 2012
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3) Neither the name of Dynastream nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission.
*
* The following actions are prohibited:
* 1) Redistribution of source code containing the ANT+ Network
* Key. The ANT+ Network Key is available to ANT+ Adopters.
* Please refer to http://thisisant.com to become an ANT+
* Adopter and access the key.
*
* 2) Reverse engineering, decompilation, and/or disassembly of
* software provided in binary form under this license.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE HEREBY
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; DAMAGE TO ANY DEVICE, LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. SOME STATES DO NOT ALLOW
* THE EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
* ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
*
*/
/** @file
* @brief The CRC-16 interface.
* This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012
* @defgroup ant_fs_client_main ANT-FS client device simulator
* @{
* @ingroup ant_fs
*
* @brief The ANT-FS client device simulator.
*
*/
#ifndef CRC_H__
#define CRC_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Function for calculating CRC-16 in blocks.
*
* Feed each consecutive data block into this function, along with the current value of current_crc
* as returned by the previous call of this function. The first call of this function should pass
* the initial value (usually 0) of the crc in current_crc.
* @param[in] current_crc The current calculated CRC-16 value.
* @param[in] p_data The input data block for computation.
* @param[in] size The size of the input data block in bytes.
*
* @return The updated CRC-16 value, based on the input supplied.
*/
uint16_t crc_crc16_update(uint16_t current_crc, const volatile void * p_data, uint32_t size);
#ifdef __cplusplus
}
#endif
#endif // CRC_H__
/**
*@}
**/

View file

@ -0,0 +1,109 @@
/**
* This software is subject to the ANT+ Shared Source License
* www.thisisant.com/swlicenses
* Copyright (c) Dynastream Innovations, Inc. 2012
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3) Neither the name of Dynastream nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission.
*
* The following actions are prohibited:
* 1) Redistribution of source code containing the ANT+ Network
* Key. The ANT+ Network Key is available to ANT+ Adopters.
* Please refer to http://thisisant.com to become an ANT+
* Adopter and access the key.
*
* 2) Reverse engineering, decompilation, and/or disassembly of
* software provided in binary form under this license.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE HEREBY
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; DAMAGE TO ANY DEVICE, LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. SOME STATES DO NOT ALLOW
* THE EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE
* ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
*
*/
/**@file
* @brief Definitions.
* This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012
* @defgroup ant_fs_client_main ANT-FS client device simulator
* @{
* @ingroup nrf_ant_fs_client
*
* @brief The ANT-FS client device simulator.
*
*/
#ifndef DEFINES_H__
#define DEFINES_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_ULONG 0xFFFFFFFFu /**< The Max value for the type. */
/**@brief uint16_t type presentation as an union. */
typedef union
{
uint16_t data; /**< The data content. */
struct
{
uint8_t low; /**< The low byte of the data content. */
uint8_t high; /**< The high byte of the data content. */
} bytes;
} ushort_union_t;
/**@brief uint32_t type presentation as an union. */
typedef union
{
uint32_t data; /**< The data content as a single variable. */
uint8_t data_bytes[sizeof(uint32_t)]; /**< The data content as a byte array. */
struct
{
// The least significant byte of the uint32_t in this structure is referenced by byte0.
uint8_t byte0; /**< Byte 0 of the data content. */
uint8_t byte1; /**< Byte 1 of the data content. */
uint8_t byte2; /**< Byte 2 of the data content. */
uint8_t byte3; /**< Byte 3 of the data content. */
} bytes;
} ulong_union_t;
#ifdef __cplusplus
}
#endif
#endif // DEFINES_H__
/**
*@}
**/

View file

@ -0,0 +1,67 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_KEY_MANAGER)
#include <stdio.h>
#include "ant_key_manager.h"
#include "ant_key_manager_config.h"
#include "ant_interface.h"
#include "nrf_assert.h"
static uint8_t m_ant_plus_network_key[] = ANT_PLUS_NETWORK_KEY;
static uint8_t m_ant_fs_network_key[] = ANT_FS_NETWORK_KEY;
uint32_t ant_custom_key_set(uint8_t network_number, uint8_t * network_key)
{
ASSERT(network_key != NULL);
return sd_ant_network_address_set(network_number, network_key);
}
uint32_t ant_plus_key_set(uint8_t network_number)
{
return sd_ant_network_address_set(network_number, m_ant_plus_network_key);
}
uint32_t ant_fs_key_set(uint8_t network_number)
{
return sd_ant_network_address_set(network_number, m_ant_fs_network_key);
}
#endif // NRF_MODULE_ENABLED(ANT_KEY_MANAGER)

View file

@ -0,0 +1,104 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_KEY_MANAGER_H__
#define ANT_KEY_MANAGER_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
*/
/**
* @defgroup ant_key_manager ANT key manager
* @{
* @ingroup ant_sdk_utils
* @brief Module for registering common and custom ANT network keys.
*/
/**@brief Function for registering a custom network key.
*
* @param[in] network_number Network key number.
* @param[in] p_network_key Pointer to the custom ANT network key.
*
* @return A SoftDevice error code.
*/
uint32_t ant_custom_key_set(uint8_t network_number, uint8_t * p_network_key);
/**@brief Function for registering an ANT+ network key.
*
* The key must be defined by @ref ANT_PLUS_NETWORK_KEY.
*
* @note The ANT+ Network Key is available for ANT+ Adopters. Go to http://thisisant.com
* to become an ANT+ Adopter and access the key.
*
* @param[in] network_number Network key number.
*
* @return A SoftDevice error code.
*/
uint32_t ant_plus_key_set(uint8_t network_number);
/**@brief Function for registering an ANT-FS network key.
*
* The key must be defined by @ref ANT_FS_NETWORK_KEY.
*
* @note The ANT+ Network Key is available for ANT+ Adopters. Go to http://thisisant.com
* to become an ANT+ Adopter and access the key.
*
* @param[in] network_number Network key number.
*
* @return A SoftDevice error code.
*/
uint32_t ant_fs_key_set(uint8_t network_number);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_KEY_MANAGER_H__

View file

@ -0,0 +1,69 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_KEY_MANAGER_CONFIG_H__
#define ANT_KEY_MANAGER_CONFIG_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup ant_key_manager
* @{
*/
#ifndef ANT_PLUS_NETWORK_KEY
#define ANT_PLUS_NETWORK_KEY {0, 0, 0, 0, 0, 0, 0, 0} /**< The ANT+ network key. */
#endif //ANT_PLUS_NETWORK_KEY
#ifndef ANT_FS_NETWORK_KEY
#define ANT_FS_NETWORK_KEY {0, 0, 0, 0, 0, 0, 0, 0} /**< The ANT-FS network key. */
#endif // ANT_FS_NETWORK_KEY
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_KEY_MANAGER_CONFIG_H__

View file

@ -0,0 +1,490 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include "nrf_assert.h"
#include "app_error.h"
#include "ant_interface.h"
#include "ant_bpwr.h"
#define NRF_LOG_MODULE_NAME ant_bpwr
#if ANT_BPWR_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_INFO_COLOR
#else // ANT_BPWR_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#define BPWR_CALIB_INT_TIMEOUT ((ANT_CLOCK_FREQUENCY * BPWR_CALIBRATION_TIMOUT_S) / BPWR_MSG_PERIOD) // calibration timeout in ant message period's unit
// for torque sensor Minimum: Interleave every 9th message
#define BPWR_PAGE_16_INTERVAL 5 // Preferred: Interleave every 5th message
#define BPWR_PAGE_16_INTERVAL_OFS 2 // Permissible offset
#define COMMON_PAGE_80_INTERVAL 119 // Minimum: Interleave every 121 messages
#define COMMON_PAGE_81_INTERVAL 120 // Minimum: Interleave every 121 messages
#define AUTO_ZERO_SUPPORT_INTERVAL 120 // Minimum: Interleave every 121 messages
/**@brief Bicycle power message data layout structure. */
typedef struct
{
uint8_t page_number;
uint8_t page_payload[7];
} ant_bpwr_message_layout_t;
/**@brief Function for initializing the ANT Bicycle Power Profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
static ret_code_t ant_bpwr_init(ant_bpwr_profile_t * p_profile,
ant_channel_config_t const * p_channel_config)
{
p_profile->channel_number = p_channel_config->channel_number;
p_profile->page_1 = DEFAULT_ANT_BPWR_PAGE1();
p_profile->page_16 = DEFAULT_ANT_BPWR_PAGE16();
p_profile->page_17 = DEFAULT_ANT_BPWR_PAGE17();
p_profile->page_18 = DEFAULT_ANT_BPWR_PAGE18();
p_profile->page_80 = DEFAULT_ANT_COMMON_page80();
p_profile->page_81 = DEFAULT_ANT_COMMON_page81();
NRF_LOG_INFO("ANT B-PWR channel %u init", p_profile->channel_number);
return ant_channel_init(p_channel_config);
}
ret_code_t ant_bpwr_disp_init(ant_bpwr_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bpwr_disp_config_t const * p_disp_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_disp_config != NULL);
ASSERT(p_disp_config->evt_handler != NULL);
ASSERT(p_disp_config->p_cb != NULL);
p_profile->evt_handler = p_disp_config->evt_handler;
p_profile->_cb.p_disp_cb = p_disp_config->p_cb;
p_profile->_cb.p_disp_cb ->calib_timeout = 0;
p_profile->_cb.p_disp_cb ->calib_stat = BPWR_DISP_CALIB_NONE;
return ant_bpwr_init(p_profile, p_channel_config);
}
ret_code_t ant_bpwr_sens_init(ant_bpwr_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bpwr_sens_config_t const * p_sens_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_sens_config != NULL);
ASSERT(p_sens_config->p_cb != NULL);
ASSERT(p_sens_config->evt_handler != NULL);
ASSERT(p_sens_config->calib_handler != NULL);
p_profile->evt_handler = p_sens_config->evt_handler;
p_profile->_cb.p_sens_cb = p_sens_config->p_cb;
p_profile->_cb.p_sens_cb->torque_use = p_sens_config->torque_use;
p_profile->_cb.p_sens_cb->calib_handler = p_sens_config->calib_handler;
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_NONE;
p_profile->_cb.p_sens_cb->message_counter = 0;
return ant_bpwr_init(p_profile, p_channel_config);
}
/**@brief Function for getting next page number to send.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @return Next page number.
*/
static ant_bpwr_page_t next_page_number_get(ant_bpwr_profile_t * p_profile)
{
ant_bpwr_sens_cb_t * p_bpwr_cb = p_profile->_cb.p_sens_cb;
ant_bpwr_page_t page_number;
if (p_bpwr_cb->calib_stat == BPWR_SENS_CALIB_READY)
{
page_number = ANT_BPWR_PAGE_1;
p_bpwr_cb->calib_stat = BPWR_SENS_CALIB_NONE; // mark event as processed
}
else if ((p_profile->BPWR_PROFILE_auto_zero_status != ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED)
&& (p_bpwr_cb->message_counter == AUTO_ZERO_SUPPORT_INTERVAL))
{
page_number = ANT_BPWR_PAGE_1;
p_profile->BPWR_PROFILE_calibration_id = ANT_BPWR_CALIB_ID_AUTO_SUPPORT;
p_bpwr_cb->message_counter++;
}
else if (p_bpwr_cb->message_counter >= COMMON_PAGE_81_INTERVAL)
{
page_number = ANT_BPWR_PAGE_81;
p_bpwr_cb->message_counter = 0;
}
else
{
if (p_bpwr_cb->message_counter == COMMON_PAGE_80_INTERVAL)
{
page_number = ANT_BPWR_PAGE_80;
}
else
{
if ( p_bpwr_cb->torque_use == TORQUE_NONE)
{
page_number = ANT_BPWR_PAGE_16;
}
else if ((p_bpwr_cb->message_counter % BPWR_PAGE_16_INTERVAL)
== BPWR_PAGE_16_INTERVAL_OFS)
{
page_number = ANT_BPWR_PAGE_16;
}
else if ( p_bpwr_cb->torque_use == TORQUE_WHEEL)
{
page_number = ANT_BPWR_PAGE_17;
}
else // assumed TORQUE_CRANK
{
page_number = ANT_BPWR_PAGE_18;
}
}
p_bpwr_cb->message_counter++;
}
return page_number;
}
/**@brief Function for encoding Bicycle Power Sensor message.
*
* @note Assume to be call each time when Tx window will occur.
*/
static void sens_message_encode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
{
ant_bpwr_message_layout_t * p_bpwr_message_payload =
(ant_bpwr_message_layout_t *)p_message_payload;
p_bpwr_message_payload->page_number = next_page_number_get(p_profile);
NRF_LOG_INFO("B-PWR tx page: %u", p_bpwr_message_payload->page_number);
switch (p_bpwr_message_payload->page_number)
{
case ANT_BPWR_PAGE_1:
ant_bpwr_page_1_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_1));
break;
case ANT_BPWR_PAGE_16:
ant_bpwr_page_16_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_16));
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_BPWR_PAGE_17:
ant_bpwr_page_17_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_17));
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_BPWR_PAGE_18:
ant_bpwr_page_18_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_18));
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_COMMON_PAGE_80:
ant_common_page_80_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_80));
break;
case ANT_COMMON_PAGE_81:
ant_common_page_81_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_81));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_bpwr_evt_t)p_bpwr_message_payload->page_number);
}
/**@brief Function for decoding messages received by Bicycle Power sensor message.
*
* @note Assume to be call each time when Rx window will occur.
*/
static void sens_message_decode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
{
const ant_bpwr_message_layout_t * p_bpwr_message_payload =
(ant_bpwr_message_layout_t *)p_message_payload;
ant_bpwr_page1_data_t page1;
switch (p_bpwr_message_payload->page_number)
{
case ANT_BPWR_PAGE_1:
ant_bpwr_page_1_decode(p_bpwr_message_payload->page_payload, &page1);
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_REQUESTED;
p_profile->_cb.p_sens_cb->calib_handler(p_profile, &page1);
break;
default:
break;
}
}
/**@brief Function for decoding messages received by Bicycle Power display message.
*
* @note Assume to be call each time when Rx window will occur.
*/
static void disp_message_decode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
{
const ant_bpwr_message_layout_t * p_bpwr_message_payload =
(ant_bpwr_message_layout_t *)p_message_payload;
NRF_LOG_INFO("B-PWR rx page: %u", p_bpwr_message_payload->page_number);
switch (p_bpwr_message_payload->page_number)
{
case ANT_BPWR_PAGE_1:
ant_bpwr_page_1_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_1));
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_NONE;
break;
case ANT_BPWR_PAGE_16:
ant_bpwr_page_16_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_16));
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_BPWR_PAGE_17:
ant_bpwr_page_17_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_17));
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_BPWR_PAGE_18:
ant_bpwr_page_18_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_18));
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
break;
case ANT_COMMON_PAGE_80:
ant_common_page_80_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_80));
break;
case ANT_COMMON_PAGE_81:
ant_common_page_81_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_81));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_bpwr_evt_t)p_bpwr_message_payload->page_number);
}
ret_code_t ant_bpwr_calib_request(ant_bpwr_profile_t * p_profile, ant_bpwr_page1_data_t * p_page_1)
{
ant_bpwr_message_layout_t bpwr_message_payload;
if (p_profile->_cb.p_disp_cb->calib_stat == BPWR_DISP_CALIB_REQUESTED)
{
return NRF_SUCCESS; // calibration in progress, so omit this request
}
bpwr_message_payload.page_number = ANT_BPWR_PAGE_1;
ant_bpwr_page_1_encode(bpwr_message_payload.page_payload, p_page_1);
uint32_t err_code = sd_ant_acknowledge_message_tx(p_profile->channel_number,
sizeof (bpwr_message_payload),
(uint8_t *) &bpwr_message_payload);
if (err_code == NRF_SUCCESS)
{
p_profile->_cb.p_disp_cb->calib_timeout = BPWR_CALIB_INT_TIMEOUT; // initialize watch on calibration's time-out
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_REQUESTED;
NRF_LOG_INFO("Start calibration process");
}
return err_code;
}
void ant_bpwr_calib_response(ant_bpwr_profile_t * p_profile)
{
if (p_profile->_cb.p_sens_cb->calib_stat != BPWR_SENS_CALIB_READY) // abort if callback request is in progress
{
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_READY; // calibration respond
}
}
/**@brief Function for hangling calibration events.
*/
static void service_calib(ant_bpwr_profile_t * p_profile, uint8_t event)
{
ant_bpwr_evt_t bpwr_event;
if (p_profile->_cb.p_disp_cb->calib_stat == BPWR_DISP_CALIB_REQUESTED)
{
switch (event)
{
case EVENT_RX:
/* fall through */
case EVENT_RX_FAIL:
if (p_profile->_cb.p_disp_cb->calib_timeout-- == 0)
{
bpwr_event = ANT_BPWR_CALIB_TIMEOUT;
break;
}
else
{
return;
}
case EVENT_TRANSFER_TX_FAILED:
bpwr_event = ANT_BPWR_CALIB_REQUEST_TX_FAILED;
break;
case EVENT_RX_SEARCH_TIMEOUT:
bpwr_event = ANT_BPWR_CALIB_TIMEOUT;
break;
default:
return;
}
NRF_LOG_INFO("End calibration process");
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_NONE;
p_profile->evt_handler(p_profile, bpwr_event);
}
}
static void ant_message_send(ant_bpwr_profile_t * p_profile)
{
uint32_t err_code;
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
sens_message_encode(p_profile, p_message_payload);
err_code =
sd_ant_broadcast_message_tx(p_profile->channel_number,
sizeof (p_message_payload),
p_message_payload);
APP_ERROR_CHECK(err_code);
}
ret_code_t ant_bpwr_disp_open(ant_bpwr_profile_t * p_profile)
{
NRF_LOG_INFO("ANT B-PWR %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
ret_code_t ant_bpwr_sens_open(ant_bpwr_profile_t * p_profile)
{
// Fill tx buffer for the first frame
ant_message_send(p_profile);
NRF_LOG_INFO("ANT B-PWR %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
void ant_bpwr_sens_evt_handler(ant_evt_t * p_ant_event, void * p_context)
{
ant_bpwr_profile_t * p_profile = ( ant_bpwr_profile_t *)p_context;
if (p_ant_event->channel == p_profile->channel_number)
{
switch (p_ant_event->event)
{
case EVENT_TX:
ant_message_send(p_profile);
break;
case EVENT_RX:
if (p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID)
{
sens_message_decode(p_profile, p_ant_event->message.ANT_MESSAGE_aucPayload);
}
break;
default:
// No implementation needed
break;
}
}
}
void ant_bpwr_disp_evt_handler(ant_evt_t * p_ant_event, void * p_context)
{
ant_bpwr_profile_t * p_profile = ( ant_bpwr_profile_t *)p_context;
if (p_ant_event->channel == p_profile->channel_number)
{
switch (p_ant_event->event)
{
case EVENT_RX:
if (p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|| p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|| p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
{
disp_message_decode(p_profile, p_ant_event->message.ANT_MESSAGE_aucPayload);
}
break;
default:
break;
}
service_calib(p_profile, p_ant_event->event);
}
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,377 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @file
* @defgroup ant_bpwr Bicycle Power profile
* @{
* @ingroup ant_sdk_profiles
* @brief This module implements the Bicycle Power profile.
*
*/
#ifndef ANT_BICYCLE_POWER_H__
#define ANT_BICYCLE_POWER_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_parameters.h"
#include "nrf_sdh_ant.h"
#include "ant_channel_config.h"
#include "ant_bpwr_pages.h"
#include "sdk_errors.h"
#define BPWR_DEVICE_TYPE 0x0Bu ///< Device type reserved for ANT+ Bicycle Power.
#define BPWR_ANTPLUS_RF_FREQ 0x39u ///< Frequency, decimal 57 (2457 MHz).
#define BPWR_MSG_PERIOD 8182u ///< Message period, decimal 8182 (4.0049 Hz).
#define BPWR_EXT_ASSIGN 0x00 ///< ANT ext assign (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
#define BPWR_DISP_CHANNEL_TYPE CHANNEL_TYPE_SLAVE ///< Display Bicycle Power channel type.
#define BPWR_SENS_CHANNEL_TYPE CHANNEL_TYPE_MASTER ///< Sensor Bicycle Power channel type.
#define BPWR_CALIBRATION_TIMOUT_S 5u ///< Time-out for responding to calibration callback (s).
/**@brief Initialize an ANT channel configuration structure for the Bicycle Power profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
*/
#define BPWR_DISP_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER) \
static const ant_channel_config_t CONCAT_2(NAME, _channel_bpwr_disp_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = BPWR_DISP_CHANNEL_TYPE, \
.ext_assign = BPWR_EXT_ASSIGN, \
.rf_freq = BPWR_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = BPWR_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = BPWR_MSG_PERIOD, \
.network_number = (NETWORK_NUMBER), \
}
#define BPWR_DISP_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME, _channel_bpwr_disp_config)
/**@brief Initialize an ANT channel configuration structure for the Bicycle Power profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
*/
#define BPWR_SENS_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER) \
static const ant_channel_config_t CONCAT_2(NAME, _channel_bpwr_sens_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = BPWR_SENS_CHANNEL_TYPE, \
.ext_assign = BPWR_EXT_ASSIGN, \
.rf_freq = BPWR_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = BPWR_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = BPWR_MSG_PERIOD, \
.network_number = (NETWORK_NUMBER), \
}
#define BPWR_SENS_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME, _channel_bpwr_sens_config)
/**@brief Initialize an ANT profile configuration structure for the BPWR profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BPWR profile.
*/
#define BPWR_DISP_PROFILE_CONFIG_DEF(NAME, \
EVT_HANDLER) \
static ant_bpwr_disp_cb_t CONCAT_2(NAME, _bpwr_disp_cb); \
static const ant_bpwr_disp_config_t CONCAT_2(NAME, _profile_bpwr_disp_config) = \
{ \
.p_cb = &CONCAT_2(NAME, _bpwr_disp_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define BPWR_DISP_PROFILE_CONFIG(NAME) &CONCAT_2(NAME, _profile_bpwr_disp_config)
/**@brief Initialize an ANT profile configuration structure for the BPWR profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] TORQUE_USED Determines whether the torque page is included.
* @param[in] CALIB_HANDLER Event handler to be called for handling calibration requests.
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BPWR profile.
*/
#define BPWR_SENS_PROFILE_CONFIG_DEF(NAME, \
TORQUE_USED, \
CALIB_HANDLER, \
EVT_HANDLER) \
static ant_bpwr_sens_cb_t CONCAT_2(NAME, _bpwr_sens_cb); \
static const ant_bpwr_sens_config_t CONCAT_2(NAME, _profile_bpwr_sens_config) = \
{ \
.torque_use = (TORQUE_USED), \
.calib_handler = (CALIB_HANDLER), \
.p_cb = &CONCAT_2(NAME, _bpwr_sens_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define BPWR_SENS_PROFILE_CONFIG(NAME) &NAME##_profile_bpwr_sens_config
/**@brief Configuration values for the Bicycle Power torque page. */
typedef enum
{
TORQUE_NONE = 0,
TORQUE_WHEEL = 1,
TORQUE_CRANK = 2,
} ant_bpwr_torque_t;
/**@brief Bicycle Power page number type. */
typedef enum
{
ANT_BPWR_PAGE_1 = 1, ///< Calibration data page.
ANT_BPWR_PAGE_16 = 16, ///< Standard power-only main data page.
ANT_BPWR_PAGE_17 = 17, ///< Standard wheel torque main data page.
ANT_BPWR_PAGE_18 = 18, ///< Standard crank torque main data page.
ANT_BPWR_PAGE_80 = ANT_COMMON_PAGE_80,
ANT_BPWR_PAGE_81 = ANT_COMMON_PAGE_81
} ant_bpwr_page_t;
/**@brief BPWR profile event type. */
typedef enum
{
ANT_BPWR_PAGE_1_UPDATED = ANT_BPWR_PAGE_1, ///< Data page 1 and speed have been updated (Display) or sent (Sensor).
ANT_BPWR_PAGE_16_UPDATED = ANT_BPWR_PAGE_16, ///< Data page 16 and speed have been updated (Display) or sent (Sensor).
ANT_BPWR_PAGE_17_UPDATED = ANT_BPWR_PAGE_17, ///< Data page 17 and speed have been updated (Display) or sent (Sensor).
ANT_BPWR_PAGE_18_UPDATED = ANT_BPWR_PAGE_18, ///< Data page 18 has been updated (Display) or sent (Sensor).
ANT_BPWR_PAGE_80_UPDATED = ANT_BPWR_PAGE_80, ///< Data page 80 has been updated (Display) or sent (Sensor).
ANT_BPWR_PAGE_81_UPDATED = ANT_BPWR_PAGE_81, ///< Data page 81 has been updated (Display) or sent (Sensor).
ANT_BPWR_CALIB_TIMEOUT, ///< Request of calibration time-out occurred (Display).
ANT_BPWR_CALIB_REQUEST_TX_FAILED, ///< Calibration request did not reach the destination (Display).
} ant_bpwr_evt_t;
// Forward declaration of the ant_bpwr_profile_t type.
typedef struct ant_bpwr_profile_s ant_bpwr_profile_t;
/**@brief BPWR event handler type. */
typedef void (* ant_bpwr_evt_handler_t) (ant_bpwr_profile_t *, ant_bpwr_evt_t);
/**@brief BPWR Sensor calibration request handler type. */
typedef void (* ant_bpwr_calib_handler_t) (ant_bpwr_profile_t *, ant_bpwr_page1_data_t *);
#include "ant_bpwr_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Bicycle Power Sensor configuration structure. */
typedef struct
{
ant_bpwr_torque_t torque_use; ///< Determines whether the torque page is included.
ant_bpwr_sens_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
ant_bpwr_calib_handler_t calib_handler; ///< Event handler to be called for handling calibration requests.
} ant_bpwr_sens_config_t;
/**@brief Bicycle Power Display configuration structure. */
typedef struct
{
ant_bpwr_disp_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
} ant_bpwr_disp_config_t;
/**@brief Bicycle Power profile structure. */
struct ant_bpwr_profile_s
{
uint8_t channel_number; ///< Channel number assigned to the profile.
union {
ant_bpwr_disp_cb_t * p_disp_cb;
ant_bpwr_sens_cb_t * p_sens_cb;
} _cb; ///< Pointer to internal control block.
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
ant_bpwr_page1_data_t page_1; ///< Page 1.
ant_bpwr_page16_data_t page_16; ///< Page 16.
ant_bpwr_page17_data_t page_17; ///< Page 17.
ant_bpwr_page18_data_t page_18; ///< Page 18.
ant_common_page80_data_t page_80; ///< Page 80.
ant_common_page81_data_t page_81; ///< Page 81.
ant_bpwr_common_data_t common; ///< BPWR common data.
};
/** @name Defines for accessing ant_bpwr_profile_t member variables
@{ */
#define BPWR_PROFILE_calibration_id page_1.calibration_id
#define BPWR_PROFILE_auto_zero_status page_1.auto_zero_status
#define BPWR_PROFILE_general_calib_data page_1.data.general_calib
#define BPWR_PROFILE_custom_calib_data page_1.data.custom_calib
#define BPWR_PROFILE_instantaneous_cadence common.instantaneous_cadence
#define BPWR_PROFILE_pedal_power page_16.pedal_power.items
#define BPWR_PROFILE_power_update_event_count page_16.update_event_count
#define BPWR_PROFILE_accumulated_power page_16.accumulated_power
#define BPWR_PROFILE_instantaneous_power page_16.instantaneous_power
#define BPWR_PROFILE_wheel_update_event_count page_17.update_event_count
#define BPWR_PROFILE_wheel_tick page_17.tick
#define BPWR_PROFILE_wheel_period page_17.period
#define BPWR_PROFILE_wheel_accumulated_torque page_17.accumulated_torque
#define BPWR_PROFILE_crank_update_event_count page_18.update_event_count
#define BPWR_PROFILE_crank_tick page_18.tick
#define BPWR_PROFILE_crank_period page_18.period
#define BPWR_PROFILE_crank_accumulated_torque page_18.accumulated_torque
#define BPWR_PROFILE_manuf_id page_80.manuf_id
#define BPWR_PROFILE_hw_revision page_80.hw_revision
#define BPWR_PROFILE_manufacturer_id page_80.manufacturer_id
#define BPWR_PROFILE_model_number page_80.model_number
#define BPWR_PROFILE_sw_revision_minor page_81.sw_revision_minor
#define BPWR_PROFILE_sw_revision_major page_81.sw_revision_major
#define BPWR_PROFILE_serial_number page_81.serial_number
/** @} */
/**@brief Function for initializing the ANT Bicycle Power Display profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_disp_config Pointer to the Bicycle Power Display configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_bpwr_disp_init(ant_bpwr_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bpwr_disp_config_t const * p_disp_config);
/**@brief Function for initializing the ANT Bicycle Power Sensor profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_sens_config Pointer to the Bicycle Power Sensor configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_bpwr_sens_init(ant_bpwr_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bpwr_sens_config_t const * p_sens_config);
/**@brief Function for opening the profile instance channel for ANT BPWR Display.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_bpwr_disp_open(ant_bpwr_profile_t * p_profile);
/**@brief Function for opening the profile instance channel for ANT BPWR Sensor.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_bpwr_sens_open(ant_bpwr_profile_t * p_profile);
/** @name Functions: Sensor calibration API
* @{
*/
/** @brief Function for initializing the response for a calibration request.
*
* This function should be used to signal the status of the calibration procedure to the ANT profile layer .
*
* @param[in] p_profile Pointer to the profile instance.
*/
void ant_bpwr_calib_response(ant_bpwr_profile_t * p_profile);
/** @} */
/**@brief Function for handling the Sensor ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Power Display profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_bpwr_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
/**@brief Function for handling the Display ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Power Display profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_bpwr_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
/** @name Functions: Display calibration API
* @{
*/
/**@brief Function for initializing the calibration request process from the Bicycle Power Display side.
*
* @details This function requests a transfer to the Sensor and starts watching for the calibration response.
* If a calibration response has already been requested, the function ignores the new request and returns NRF_SUCCESS.
*
* @param [in] p_profile Pointer to the profile instance.
* @param [in] p_page_1 Pointer to the prepared page 1.
*
* @return Values returned by the @ref sd_ant_acknowledge_message_tx SVC callback.
*/
uint32_t ant_bpwr_calib_request(ant_bpwr_profile_t * p_profile, ant_bpwr_page1_data_t * p_page_1);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_BICYCLE_POWER_H__

View file

@ -0,0 +1,89 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_LOCAL_H__
#define ANT_BPWR_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_bpwr.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup ant_bpwr
* @{
*/
/** @brief Bicycle Power Sensor control block. */
typedef struct
{
uint8_t message_counter;
ant_bpwr_torque_t torque_use;
enum
{
BPWR_SENS_CALIB_NONE, ///< Idle state.
BPWR_SENS_CALIB_REQUESTED, ///< Received request for general calibration result message by the sensor.
BPWR_SENS_CALIB_READY, ///< Calibration response message is ready to be transmitted.
} calib_stat;
ant_bpwr_calib_handler_t calib_handler;
} ant_bpwr_sens_cb_t;
/**@brief Bicycle Power Sensor RX control block. */
typedef struct
{
uint8_t calib_timeout;
enum
{
BPWR_DISP_CALIB_NONE, ///< Idle state.
BPWR_DISP_CALIB_REQUESTED, ///< Calibration requested.
} calib_stat;
} ant_bpwr_disp_cb_t;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_LOCAL_H__

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include "ant_bpwr_common_data.h"
#include "ant_bpwr_utils.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_common
#if ANT_BPWR_COMMON_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_COMMON_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_COMMON_INFO_COLOR
#else // ANT_BPWR_COMMON_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_COMMON_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BPWR common page data layout structure. */
typedef struct
{
uint8_t reserved0[2];
uint8_t instantaneous_cadence;
uint8_t reserved1[4];
}ant_bpwr_cadence_data_layout_t;
/**@brief Function for tracing common data.
*
* @param[in] p_common_data Pointer to the common data.
*/
static void cadence_data_log(ant_bpwr_common_data_t const * p_common_data)
{
if (p_common_data->instantaneous_cadence == 0xFF)
{
NRF_LOG_INFO("instantaneous cadence: -- rpm\r\n\n");
}
else
{
NRF_LOG_INFO("instantaneous cadence: %u rpm\r\n\n",
p_common_data->instantaneous_cadence);
}
}
void ant_bpwr_cadence_encode(uint8_t * p_page_buffer,
ant_bpwr_common_data_t const * p_common_data)
{
ant_bpwr_cadence_data_layout_t * p_outcoming_data = (ant_bpwr_cadence_data_layout_t *)p_page_buffer;
p_outcoming_data->instantaneous_cadence = p_common_data->instantaneous_cadence;
cadence_data_log(p_common_data);
}
void ant_bpwr_cadence_decode(uint8_t const * p_page_buffer,
ant_bpwr_common_data_t * p_common_data)
{
ant_bpwr_cadence_data_layout_t const * p_incoming_data = (ant_bpwr_cadence_data_layout_t *)p_page_buffer;
p_common_data->instantaneous_cadence = p_incoming_data->instantaneous_cadence;
cadence_data_log(p_common_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_COMMON_DATA_H__
#define ANT_BPWR_COMMON_DATA_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_common_data_page Stride Based Speed and Distance Monitor profile common data
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BPWR common data.
*
* @details This structure stores data that is not associated with a particular page.
*/
typedef struct
{
uint8_t instantaneous_cadence; ///< Crank cadence (rpm, 0 - 254, 255-> invalid).
} ant_bpwr_common_data_t;
/**@brief Initialize common data.
*/
#define DEFAULT_ANT_BPWR_COMMON_DATA() \
(ant_bpwr_common_data_t) \
{ \
.instantaneous_cadence = 0, \
}
/**@brief Function for encoding speed.
*
* This function can be used for pages 16, 17, and 18.
*
* @param[in] p_common_data Pointer to the common data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_cadence_encode(uint8_t * p_page_buffer,
ant_bpwr_common_data_t const * p_common_data);
/**@brief Function for decoding speed.
*
* This function can be used for pages 16, 17, and 18.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_common_data Pointer to the common data.
*/
void ant_bpwr_cadence_decode(uint8_t const * p_page_buffer,
ant_bpwr_common_data_t * p_common_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_COMMON_DATA_H__
/** @} */

View file

@ -0,0 +1,286 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include <string.h>
#include "ant_bpwr_page_1.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_page_1
#if ANT_BPWR_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_1_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_1_INFO_COLOR
#else // ANT_BPWR_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_PAGE_1_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief bicycle power page 1 data layout structure. */
typedef struct
{
uint8_t calibration_id; ///< Calibration request type
union
{
struct
{
uint8_t reserved[6]; ///< Unused, fill by 0xFF.
} general_calib_request;
struct
{
uint8_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
uint8_t reserved[5]; ///< Unused, fill by 0xFF.
} auto_zero_config;
struct
{
uint8_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
uint8_t reserved[3]; ///< Unused, fill by 0xFF.
uint8_t data[2]; ///< Calibration Data.
} general_calib_response;
struct
{
uint8_t enable : 1;
uint8_t status : 1;
uint8_t reserved0 : 6; ///< Unused, fill by 0x00.
uint8_t reserved1[5]; ///< Unused, fill by 0xFF.
} auto_zero_support;
struct
{
uint8_t manufac_spec[6]; ///< Manufacture Specyfic Data.
} custom_calib;
} data;
} ant_bpwr_page1_data_layout_t;
static void page1_data_log(ant_bpwr_page1_data_t const * p_page_data)
{
NRF_LOG_INFO("Calibration id: %u", p_page_data->calibration_id);
switch (p_page_data->calibration_id)
{
case ANT_BPWR_CALIB_ID_MANUAL:
// No implementation needed
break;
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_FAILED:
NRF_LOG_INFO("General calibration data: %u",
p_page_data->data.general_calib);
/* fall through */
case ANT_BPWR_CALIB_ID_AUTO:
/* fall through */
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
switch (p_page_data->auto_zero_status)
{
case ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED:
NRF_LOG_INFO("Auto zero not supported\r\n\n");
break;
case ANT_BPWR_AUTO_ZERO_OFF:
NRF_LOG_INFO("Auto zero off\r\n\n");
break;
case ANT_BPWR_AUTO_ZERO_ON:
NRF_LOG_INFO("Auto zero on\r\n\n");
break;
}
break;
case ANT_BPWR_CALIB_ID_CTF:
NRF_LOG_INFO("Not supported\r\n\n");
break;
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
NRF_LOG_INFO("Manufacture specyfic: ");
NRF_LOG_HEXDUMP_INFO((uint8_t*)p_page_data->data.custom_calib,
sizeof (p_page_data->data.custom_calib));
break;
default: // shouldn't occur
NRF_LOG_INFO("Unsupported calibration ID\r\n\n");
break;
}
}
void ant_bpwr_page_1_encode(uint8_t * p_page_buffer,
ant_bpwr_page1_data_t const * p_page_data)
{
ant_bpwr_page1_data_layout_t * p_outcoming_data = (ant_bpwr_page1_data_layout_t *)p_page_buffer;
page1_data_log(p_page_data);
p_outcoming_data->calibration_id = p_page_data->calibration_id;
switch (p_page_data->calibration_id)
{
case ANT_BPWR_CALIB_ID_MANUAL:
memset(p_outcoming_data->data.general_calib_request.reserved, 0xFF,
sizeof (p_outcoming_data->data.general_calib_request.reserved));
break;
case ANT_BPWR_CALIB_ID_AUTO:
memset(p_outcoming_data->data.auto_zero_config.reserved, 0xFF,
sizeof (p_outcoming_data->data.auto_zero_config.reserved));
p_outcoming_data->data.auto_zero_config.auto_zero_status =
p_page_data->auto_zero_status;
break;
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_FAILED:
memset(p_outcoming_data->data.general_calib_response.reserved, 0xFF,
sizeof (p_outcoming_data->data.general_calib_response.reserved));
p_outcoming_data->data.general_calib_response.auto_zero_status =
p_page_data->auto_zero_status;
UNUSED_PARAMETER(uint16_encode(p_page_data->data.general_calib,
p_outcoming_data->data.general_calib_response.data));
break;
case ANT_BPWR_CALIB_ID_CTF:
NRF_LOG_INFO("Not supported");
break;
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
memset(p_outcoming_data->data.auto_zero_support.reserved1, 0xFF,
sizeof (p_outcoming_data->data.auto_zero_support.reserved1));
p_outcoming_data->data.auto_zero_support.reserved0 = 0x00;
p_outcoming_data->data.auto_zero_support.enable =
(p_page_data->auto_zero_status == ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED) ? false : true;
p_outcoming_data->data.auto_zero_support.status =
(p_page_data->auto_zero_status == ANT_BPWR_AUTO_ZERO_ON) ? true : false;
break;
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
memcpy(p_outcoming_data->data.custom_calib.manufac_spec,
(void *)p_page_data->data.custom_calib,
sizeof (p_page_data->data.custom_calib));
break;
default: // shouldn't occur
break;
}
}
void ant_bpwr_page_1_decode(uint8_t const * p_page_buffer,
ant_bpwr_page1_data_t * p_page_data)
{
ant_bpwr_page1_data_layout_t const * p_incoming_data =
(ant_bpwr_page1_data_layout_t *)p_page_buffer;
p_page_data->calibration_id = (ant_bpwr_calib_id_t)p_incoming_data->calibration_id;
switch (p_incoming_data->calibration_id)
{
case ANT_BPWR_CALIB_ID_MANUAL:
// No implementation needed
break;
case ANT_BPWR_CALIB_ID_AUTO:
/* fall through */
p_page_data->auto_zero_status =
(ant_bpwr_auto_zero_status_t)p_incoming_data->data.auto_zero_config.auto_zero_status;
break;
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_FAILED:
p_page_data->auto_zero_status =
(ant_bpwr_auto_zero_status_t)p_incoming_data->data.general_calib_response.
auto_zero_status;
p_page_data->data.general_calib = uint16_decode(
p_incoming_data->data.general_calib_response.data);
break;
case ANT_BPWR_CALIB_ID_CTF:
NRF_LOG_INFO("Not supported");
break;
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
if (p_incoming_data->data.auto_zero_support.enable == false)
{
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED;
}
else if (p_incoming_data->data.auto_zero_support.status)
{
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_ON;
}
else
{
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_OFF;
}
break;
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
/* fall through */
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
memcpy((void *)p_page_data->data.custom_calib,
p_incoming_data->data.custom_calib.manufac_spec,
sizeof (p_page_data->data.custom_calib));
break;
default: // shouldn't occur
break;
}
page1_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,136 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGE_1_H__
#define ANT_BPWR_PAGE_1_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_page1 Bicycle Power profile page 1
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BPWR Calibration ID.
*/
typedef enum
{
ANT_BPWR_CALIB_ID_NONE = 0x00,
ANT_BPWR_CALIB_ID_MANUAL = 0xAA, ///< Calibration Request: Manual Zero.
ANT_BPWR_CALIB_ID_AUTO = 0xAB, ///< Calibration Request: Auto Zero Configuration.
ANT_BPWR_CALIB_ID_MANUAL_SUCCESS = 0xAC, ///< Calibration Response: Manual Zero Successful.
ANT_BPWR_CALIB_ID_FAILED = 0xAF, ///< Calibration Response: Failed.
ANT_BPWR_CALIB_ID_CTF = 0x10, ///< Crank Torque Frequency (CTF) Power sensor Defined Message.
ANT_BPWR_CALIB_ID_AUTO_SUPPORT = 0x12, ///< Auto Zero Support.
ANT_BPWR_CALIB_ID_CUSTOM_REQ = 0xBA, ///< Custom Calibration Parameter Request.
ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS = 0xBB, ///< Custom Calibration Parameter Response.
ANT_BPWR_CALIB_ID_CUSTOM_UPDATE = 0xBC, ///< Custom Calibration Parameter Update.
ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS = 0xBD, ///< Custom Calibration Parameter Update Response.
} ant_bpwr_calib_id_t;
/**@brief BPWR Calibration Auto Zero Status.
*/
typedef enum
{
ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED = 0xFF, ///< Auto Zero Not Supported.
ANT_BPWR_AUTO_ZERO_OFF = 0x00, ///< Auto Zero OFF.
ANT_BPWR_AUTO_ZERO_ON = 0x01, ///< Auto Zero ON.
} ant_bpwr_auto_zero_status_t;
/**@brief Data structure for Bicycle Power data page 1.
*/
typedef struct
{
ant_bpwr_calib_id_t calibration_id; ///< Calibration request type.
ant_bpwr_auto_zero_status_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
union
{
int16_t general_calib;
uint8_t custom_calib[6];
} data;
} ant_bpwr_page1_data_t;
/**@brief Initialize page 1.
*/
#define DEFAULT_ANT_BPWR_PAGE1() \
(ant_bpwr_page1_data_t) \
{ \
.calibration_id = ANT_BPWR_CALIB_ID_NONE, \
.auto_zero_status = ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED, \
.data.general_calib = 0x00, \
}
/**@brief Initialize page 1 with the general request.
*/
#define ANT_BPWR_GENERAL_CALIB_REQUEST() \
(ant_bpwr_page1_data_t) \
{ \
.calibration_id = ANT_BPWR_CALIB_ID_MANUAL, \
}
/**@brief Function for encoding page 1.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_page_1_encode(uint8_t * p_page_buffer,
ant_bpwr_page1_data_t const * p_page_data);
/**@brief Function for decoding page 1.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_1_decode(uint8_t const * p_page_buffer,
ant_bpwr_page1_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGE_1_H__
/** @} */

View file

@ -0,0 +1,117 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include "ant_bpwr_page_16.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_page_16
#if ANT_BPWR_PAGE_16_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_16_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_16_INFO_COLOR
#else // ANT_BPWR_PAGE_16_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_PAGE_16_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief bicycle power page 16 data layout structure. */
typedef struct
{
uint8_t update_event_count;
uint8_t pedal_power;
uint8_t reserved;
uint8_t accumulated_power[2];
uint8_t instantaneous_power[2];
}ant_bpwr_page16_data_layout_t;
static void page16_data_log(ant_bpwr_page16_data_t const * p_page_data)
{
NRF_LOG_INFO("event count: %u", p_page_data->update_event_count);
if (p_page_data->pedal_power.byte != 0xFF)
{
NRF_LOG_INFO("pedal power: %u %%",
p_page_data->pedal_power.items.distribution);
}
else
{
NRF_LOG_INFO("pedal power: --");
}
NRF_LOG_INFO("accumulated power: %u W", p_page_data->accumulated_power);
NRF_LOG_INFO("instantaneous power: %u W", p_page_data->instantaneous_power);
}
void ant_bpwr_page_16_encode(uint8_t * p_page_buffer,
ant_bpwr_page16_data_t const * p_page_data)
{
ant_bpwr_page16_data_layout_t * p_outcoming_data =
(ant_bpwr_page16_data_layout_t *)p_page_buffer;
p_outcoming_data->update_event_count = p_page_data->update_event_count;
p_outcoming_data->pedal_power = p_page_data->pedal_power.byte;
UNUSED_PARAMETER(uint16_encode(p_page_data->accumulated_power,
p_outcoming_data->accumulated_power));
UNUSED_PARAMETER(uint16_encode(p_page_data->instantaneous_power,
p_outcoming_data->instantaneous_power));
page16_data_log(p_page_data);
}
void ant_bpwr_page_16_decode(uint8_t const * p_page_buffer,
ant_bpwr_page16_data_t * p_page_data)
{
ant_bpwr_page16_data_layout_t const * p_incoming_data =
(ant_bpwr_page16_data_layout_t *)p_page_buffer;
p_page_data->update_event_count = p_incoming_data->update_event_count;
p_page_data->pedal_power.byte = p_incoming_data->pedal_power;
p_page_data->accumulated_power = uint16_decode(p_incoming_data->accumulated_power);
p_page_data->instantaneous_power = uint16_decode(p_incoming_data->instantaneous_power);
page16_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,111 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGE_16_H__
#define ANT_BPWR_PAGE_16_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_page16 Bicycle Power profile page 16
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for Bicycle Power data page 16.
*
* @note This structure implements only page 16 specific data.
*/
typedef struct
{
union
{
struct
{
uint8_t distribution : 7; ///< Pedal power distribution (%).
uint8_t differentiation : 1; ///< Pedal differentiation: 1 -> right, 0 -> unknown.
} items;
uint8_t byte;
} pedal_power;
uint8_t update_event_count; ///< Power event count.
uint16_t accumulated_power; ///< Accumulated power (W).
uint16_t instantaneous_power; ///< Instantaneous power (W).
} ant_bpwr_page16_data_t;
/**@brief Initialize page 16.
*/
#define DEFAULT_ANT_BPWR_PAGE16() \
(ant_bpwr_page16_data_t) \
{ \
.update_event_count = 0, \
.pedal_power.items.distribution = 0, \
.pedal_power.items.differentiation = 0, \
.accumulated_power = 0, \
.instantaneous_power = 0, \
}
/**@brief Function for encoding page 16.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_page_16_encode(uint8_t * p_page_buffer,
ant_bpwr_page16_data_t const * p_page_data);
/**@brief Function for decoding page 16.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_16_decode(uint8_t const * p_page_buffer,
ant_bpwr_page16_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGE_16_H__
/** @} */

View file

@ -0,0 +1,77 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include "ant_bpwr_page_17.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_page_17
#if ANT_BPWR_PAGE_17_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_17_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_17_INFO_COLOR
#else // ANT_BPWR_PAGE_17_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_PAGE_17_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
static void page17_data_log(ant_bpwr_page17_data_t const * p_page_data)
{
NRF_LOG_INFO("Wheel:");
ant_bpwr_page_torque_log((ant_bpwr_page_torque_data_t *) p_page_data);
}
void ant_bpwr_page_17_encode(uint8_t * p_page_buffer,
ant_bpwr_page17_data_t const * p_page_data)
{
ant_bpwr_page_torque_encode(p_page_buffer, (ant_bpwr_page_torque_data_t *)p_page_data);
page17_data_log(p_page_data);
}
void ant_bpwr_page_17_decode(uint8_t const * p_page_buffer,
ant_bpwr_page17_data_t * p_page_data)
{
ant_bpwr_page_torque_decode(p_page_buffer, (ant_bpwr_page_torque_data_t *) p_page_data);
page17_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,89 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGE_17_H__
#define ANT_BPWR_PAGE_17_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_page17 Bicycle Power profile page 17
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#include "ant_bpwr_page_torque.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for Bicycle Power data page 17.
*
* @note This structure implements only page 17 specific data.
*/
typedef ant_bpwr_page_torque_data_t ant_bpwr_page17_data_t;
/**@brief Initialize page 17.
*/
#define DEFAULT_ANT_BPWR_PAGE17() (ant_bpwr_page17_data_t) DEFAULT_ANT_BPWR_PAGE_TORQUE(0, 0, 0, 0)
/**@brief Function for encoding page 17.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_page_17_encode(uint8_t * p_page_buffer,
ant_bpwr_page17_data_t const * p_page_data);
/**@brief Function for decoding page 17.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_17_decode(uint8_t const * p_page_buffer,
ant_bpwr_page17_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGE_17_H__
/** @} */

View file

@ -0,0 +1,77 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include "ant_bpwr_page_18.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_page_18
#if ANT_BPWR_PAGE_18_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_18_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_18_INFO_COLOR
#else // ANT_BPWR_PAGE_18_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_PAGE_18_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
static void page18_data_log(ant_bpwr_page18_data_t const * p_page_data)
{
NRF_LOG_INFO("Crank:");
ant_bpwr_page_torque_log((ant_bpwr_page_torque_data_t *) p_page_data);
}
void ant_bpwr_page_18_encode(uint8_t * p_page_buffer,
ant_bpwr_page18_data_t const * p_page_data)
{
ant_bpwr_page_torque_encode(p_page_buffer, (ant_bpwr_page_torque_data_t *)p_page_data);
page18_data_log(p_page_data);
}
void ant_bpwr_page_18_decode(uint8_t const * p_page_buffer,
ant_bpwr_page18_data_t * p_page_data)
{
ant_bpwr_page_torque_decode(p_page_buffer, (ant_bpwr_page_torque_data_t *) p_page_data);
page18_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,89 @@
/**
* Copyright (c) 2011 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGE_18_H__
#define ANT_BPWR_PAGE_18_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_page18 Bicycle Power profile page 18
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#include "ant_bpwr_page_torque.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for Bicycle Power data page 18.
*
* @note This structure implements only page 18 specific data.
*/
typedef ant_bpwr_page_torque_data_t ant_bpwr_page18_data_t;
/**@brief Initialize page 18.
*/
#define DEFAULT_ANT_BPWR_PAGE18() (ant_bpwr_page18_data_t) DEFAULT_ANT_BPWR_PAGE_TORQUE(0, 0, 0, 0)
/**@brief Function for encoding page 18.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_page_18_encode(uint8_t * p_page_buffer,
ant_bpwr_page18_data_t const * p_page_data);
/**@brief Function for decoding page 18.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_18_decode(uint8_t const * p_page_buffer,
ant_bpwr_page18_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGE_18_H__
/** @} */

View file

@ -0,0 +1,113 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BPWR)
#include <stdio.h>
#include "ant_bpwr_page_torque.h"
#include "ant_bpwr_utils.h"
#define NRF_LOG_MODULE_NAME ant_bpwr_page_torque
#if ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_TORQUE_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_TORQUE_INFO_COLOR
#else // ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief bicycle power page torque data layout structure. */
typedef struct
{
uint8_t update_event_count;
uint8_t tick;
uint8_t reserved;
uint8_t period[2];
uint8_t accumulated_torque[2];
}ant_bpwr_page_torque_data_layout_t;
STATIC_ASSERT(ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION == 1000); ///< Display format need to be updated
STATIC_ASSERT(ANT_BPWR_ACC_TORQUE_DISP_PRECISION == 10); ///< Display format need to be updated
void ant_bpwr_page_torque_log(ant_bpwr_page_torque_data_t const * p_page_data)
{
uint16_t period = ANT_BPWR_TORQUE_PERIOD_RESCALE(p_page_data->period);
uint32_t acc_torque = ANT_BPWR_ACC_TORQUE_RESCALE(p_page_data->accumulated_torque);
NRF_LOG_INFO("event count: %u", p_page_data->update_event_count);
NRF_LOG_INFO("tick: %u", p_page_data->tick);
NRF_LOG_INFO("period: %u.%03us",
(unsigned int)(period / ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION),
(unsigned int)(period % ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION));
NRF_LOG_INFO("accumulated torque: %u.%01uNm",
(unsigned int)(acc_torque / ANT_BPWR_ACC_TORQUE_DISP_PRECISION),
(unsigned int)(acc_torque % ANT_BPWR_ACC_TORQUE_DISP_PRECISION));
}
void ant_bpwr_page_torque_encode(uint8_t * p_page_buffer,
ant_bpwr_page_torque_data_t const * p_page_data)
{
ant_bpwr_page_torque_data_layout_t * p_outcoming_data =
(ant_bpwr_page_torque_data_layout_t *)p_page_buffer;
p_outcoming_data->update_event_count = p_page_data->update_event_count;
p_outcoming_data->tick = p_page_data->tick;
UNUSED_PARAMETER(uint16_encode(p_page_data->period, p_outcoming_data->period));
UNUSED_PARAMETER(uint16_encode(p_page_data->accumulated_torque,
p_outcoming_data->accumulated_torque));
}
void ant_bpwr_page_torque_decode(uint8_t const * p_page_buffer,
ant_bpwr_page_torque_data_t * p_page_data)
{
ant_bpwr_page_torque_data_layout_t const * p_incoming_data =
(ant_bpwr_page_torque_data_layout_t *)p_page_buffer;
p_page_data->update_event_count = p_incoming_data->update_event_count;
p_page_data->tick = p_incoming_data->tick;
p_page_data->period = uint16_decode(p_incoming_data->period);
p_page_data->accumulated_torque = uint16_decode(p_incoming_data->accumulated_torque);
}
#endif // NRF_MODULE_ENABLED(ANT_BPWR)

View file

@ -0,0 +1,106 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGE_TORQUE_COMMON_H__
#define ANT_BPWR_PAGE_TORQUE_COMMON_H__
/** @file
*
* @defgroup ant_sdk_profiles_bicycle_p_page_torque Bicycle Power profile pages 17, 18 (commons)
* @{
* @ingroup ant_sdk_profiles_bpwr_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Common data structure for Bicycle Power data pages 17, 18.
*
* @note This structure implements specific data that is common for pages 17, 18.
*/
typedef struct
{
uint8_t update_event_count; ///< Power event count.
uint8_t tick; ///< Wheel/crank revolutions counter.
uint16_t period; ///< Accumulated wheel/crank period (1/2048 s).
uint16_t accumulated_torque; ///< Accumulated wheel/torque (1/32 Nm).
} ant_bpwr_page_torque_data_t;
/**@brief Initialize page torque.
*/
#define DEFAULT_ANT_BPWR_PAGE_TORQUE(up_evt_cnt, def_tick, def_period, acc_torque) \
{ \
.update_event_count = (up_evt_cnt), \
.tick = (def_tick), \
.period = (def_period), \
.accumulated_torque = (acc_torque) \
}
/**@brief Function for encoding pages 17, 18.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bpwr_page_torque_encode(uint8_t * p_page_buffer,
ant_bpwr_page_torque_data_t const * p_page_data);
/**@brief Function for decoding pages 17, 18.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_torque_decode(uint8_t const * p_page_buffer,
ant_bpwr_page_torque_data_t * p_page_data);
/**@brief Function for logging pages 17, 18.
*
* @param[in] p_page_data Pointer to the page data.
*/
void ant_bpwr_page_torque_log(ant_bpwr_page_torque_data_t const * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGE_TORQUE_COMMON_H__
/** @} */

View file

@ -0,0 +1,69 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_PAGES_H__
#define ANT_BPWR_PAGES_H__
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_pages Bicycle Power profile pages
* @{
* @ingroup ant_bpwr
* @brief This module implements functions for the BPWR data pages.
*/
#include "ant_bpwr_page_1.h" // Calibration message main data page.
#include "ant_bpwr_page_16.h" // Standard power-only page.
#include "ant_bpwr_page_17.h" // Wheel Torque main data page.
#include "ant_bpwr_page_18.h" // Crank Torque main data page.
#include "ant_bpwr_common_data.h" // Instantaneous cadence data.
#include "ant_common_page_80.h" // Manufacturer's information data page.
#include "ant_common_page_81.h" // Product information data page.
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_PAGES_H__
/** @} */

View file

@ -0,0 +1,201 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ant_bpwr_simulator.h"
#include "app_util.h"
#include "nordic_common.h"
#define POWER_MIN 0
#define POWER_MAX 2000
#define POWER_INCR 10
#define CADENCE_MIN 0
#define CADENCE_MAX (UINT8_MAX - 1)
#define CADENCE_INCR 1
#define PEDAL_MIN 0
#define PEDAL_MAX 100
#define PEDAL_INCR 1
#define TORQUE_PERIOD 774
#define SIMULATOR_TIME_INCREMENT BPWR_MSG_PERIOD
#define TORQUE_INCR 10
void ant_bpwr_simulator_init(ant_bpwr_simulator_t * p_simulator,
ant_bpwr_simulator_cfg_t const * p_config,
bool auto_change)
{
p_simulator->p_profile = p_config->p_profile;
p_simulator->_cb.auto_change = auto_change;
p_simulator->_cb.tick_incr = 0;
p_simulator->_cb.power_sensorsim_cfg.min = POWER_MIN;
p_simulator->_cb.power_sensorsim_cfg.max = POWER_MAX;
p_simulator->_cb.power_sensorsim_cfg.incr = POWER_INCR;
p_simulator->_cb.power_sensorsim_cfg.start_at_max = false;
p_simulator->_cb.cadence_sensorsim_cfg.min = CADENCE_MIN;
p_simulator->_cb.cadence_sensorsim_cfg.max = CADENCE_MAX;
p_simulator->_cb.cadence_sensorsim_cfg.incr = CADENCE_INCR;
p_simulator->_cb.cadence_sensorsim_cfg.start_at_max = false;
p_simulator->_cb.pedal_sensorsim_cfg.min = PEDAL_MIN;
p_simulator->_cb.pedal_sensorsim_cfg.max = PEDAL_MAX;
p_simulator->_cb.pedal_sensorsim_cfg.incr = PEDAL_INCR;
p_simulator->_cb.pedal_sensorsim_cfg.start_at_max = false;
p_simulator->p_profile->BPWR_PROFILE_pedal_power.differentiation = 0x01; // right
sensorsim_init(&(p_simulator->_cb.power_sensorsim_state),
&(p_simulator->_cb.power_sensorsim_cfg));
sensorsim_init(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg));
sensorsim_init(&(p_simulator->_cb.pedal_sensorsim_state),
&(p_simulator->_cb.pedal_sensorsim_cfg));
}
void ant_bpwr_simulator_one_iteration(ant_bpwr_simulator_t * p_simulator, ant_bpwr_evt_t event)
{
switch (event)
{
case ANT_BPWR_PAGE_16_UPDATED:
if (p_simulator->_cb.auto_change)
{
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.power_sensorsim_state),
&(p_simulator->_cb.power_sensorsim_cfg)));
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg)));
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.pedal_sensorsim_state),
&(p_simulator->_cb.pedal_sensorsim_cfg)));
}
p_simulator->p_profile->BPWR_PROFILE_instantaneous_power =
p_simulator->_cb.power_sensorsim_state.current_val;
p_simulator->p_profile->BPWR_PROFILE_accumulated_power +=
p_simulator->_cb.power_sensorsim_state.current_val;
if (p_simulator->p_profile->BPWR_PROFILE_accumulated_power == UINT16_MAX)
{
p_simulator->p_profile->BPWR_PROFILE_accumulated_power = 0;
}
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
p_simulator->_cb.cadence_sensorsim_state.current_val;
p_simulator->p_profile->BPWR_PROFILE_pedal_power.distribution =
p_simulator->_cb.pedal_sensorsim_state.current_val;
p_simulator->p_profile->BPWR_PROFILE_power_update_event_count++;
break;
case ANT_BPWR_PAGE_17_UPDATED:
if (p_simulator->_cb.auto_change)
{
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg)));
}
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
p_simulator->_cb.cadence_sensorsim_state.current_val;
p_simulator->p_profile->BPWR_PROFILE_wheel_period += TORQUE_PERIOD;
p_simulator->_cb.tick_incr +=
SIMULATOR_TIME_INCREMENT;
p_simulator->p_profile->BPWR_PROFILE_wheel_tick +=
p_simulator->_cb.tick_incr / (TORQUE_PERIOD * 16);
p_simulator->_cb.tick_incr =
p_simulator->_cb.tick_incr % (TORQUE_PERIOD * 16);
p_simulator->p_profile->BPWR_PROFILE_wheel_accumulated_torque += TORQUE_INCR;
p_simulator->p_profile->BPWR_PROFILE_wheel_update_event_count++;
break;
case ANT_BPWR_PAGE_18_UPDATED:
if (p_simulator->_cb.auto_change)
{
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg)));
}
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
p_simulator->_cb.cadence_sensorsim_state.current_val;
p_simulator->p_profile->BPWR_PROFILE_crank_period = TORQUE_PERIOD;
p_simulator->_cb.tick_incr +=
SIMULATOR_TIME_INCREMENT;
p_simulator->p_profile->BPWR_PROFILE_crank_tick +=
p_simulator->_cb.tick_incr / (TORQUE_PERIOD * 16);
p_simulator->_cb.tick_incr =
p_simulator->_cb.tick_incr % (TORQUE_PERIOD * 16);
p_simulator->p_profile->BPWR_PROFILE_crank_accumulated_torque += TORQUE_INCR;
p_simulator->p_profile->BPWR_PROFILE_crank_update_event_count++;
break;
default:
break;
}
}
void ant_bpwr_simulator_increment(ant_bpwr_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_increment(&(p_simulator->_cb.power_sensorsim_state),
&(p_simulator->_cb.power_sensorsim_cfg));
sensorsim_increment(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg));
sensorsim_increment(&(p_simulator->_cb.pedal_sensorsim_state),
&(p_simulator->_cb.pedal_sensorsim_cfg));
}
}
void ant_bpwr_simulator_decrement(ant_bpwr_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_decrement(&(p_simulator->_cb.power_sensorsim_state),
&(p_simulator->_cb.power_sensorsim_cfg));
sensorsim_decrement(&(p_simulator->_cb.cadence_sensorsim_state),
&(p_simulator->_cb.cadence_sensorsim_cfg));
sensorsim_decrement(&(p_simulator->_cb.pedal_sensorsim_state),
&(p_simulator->_cb.pedal_sensorsim_cfg));
}
}

View file

@ -0,0 +1,123 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_SIMULATOR_H__
#define ANT_BPWR_SIMULATOR_H__
/** @file
*
* @defgroup ant_sdk_simulators ANT simulators
* @ingroup ant_sdk_utils
* @brief Modules that simulate sensors.
*
* @defgroup ant_sdk_bpwr_simulator ANT BPWR simulator
* @{
* @ingroup ant_sdk_simulators
* @brief ANT BPWR simulator module.
*
* @details This module simulates power for the ANT BPWR profile. The module calculates
* abstract values, which are handled by the BPWR pages data model to ensure that they are
* compatible. It provides a handler for changing the power value manually and functionality
* for changing the power automatically.
*
*/
#include <stdint.h>
#include <stdbool.h>
#include "bsp.h"
#include "ant_bpwr.h"
#include "sensorsim.h"
#include "ant_bpwr_simulator_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BPWR simulator configuration structure. */
typedef struct
{
ant_bpwr_profile_t * p_profile; ///< Related profile.
ant_bpwr_torque_t sensor_type; ///< Type of related sensor.
} ant_bpwr_simulator_cfg_t;
/**@brief BPWR simulator structure. */
typedef struct
{
ant_bpwr_profile_t * p_profile; ///< Related profile.
ant_bpwr_simulator_cb_t _cb; ///< Internal control block.
} ant_bpwr_simulator_t;
/**@brief Function for initializing the ANT BPWR simulator instance.
*
* @param[in] p_simulator Pointer to the simulator instance.
* @param[in] p_config Pointer to the simulator configuration structure.
* @param[in] auto_change Enable or disable automatic changes of the power.
*/
void ant_bpwr_simulator_init(ant_bpwr_simulator_t * p_simulator,
ant_bpwr_simulator_cfg_t const * p_config,
bool auto_change);
/**@brief Function for simulating a device event.
*
* @details Based on this event, the transmitter data is simulated.
*
* This function should be called in the BPWR TX event handler.
*/
void ant_bpwr_simulator_one_iteration(ant_bpwr_simulator_t * p_simulator, ant_bpwr_evt_t event);
/**@brief Function for incrementing the power value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_bpwr_simulator_increment(ant_bpwr_simulator_t * p_simulator);
/**@brief Function for decrementing the power value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_bpwr_simulator_decrement(ant_bpwr_simulator_t * p_simulator);
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_SIMULATOR_H__
/** @} */

View file

@ -0,0 +1,74 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_SIMULATOR_LOCAL_H__
#define ANT_BPWR_SIMULATOR_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "bsp.h"
#include "ant_bpwr.h"
#include "sensorsim.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup ant_sdk_bpwr_simulator
* @brief BPWR simulator control block structure. */
typedef struct
{
bool auto_change; ///< Power will change automatically (if auto_change is set) or manually.
uint32_t tick_incr; ///< Fractional part of tick increment.
sensorsim_state_t power_sensorsim_state; ///< Power state of the simulated sensor.
sensorsim_cfg_t power_sensorsim_cfg; ///< Power configuration of the simulated sensor.
sensorsim_state_t cadence_sensorsim_state; ///< Cadence stated of the simulated sensor.
sensorsim_cfg_t cadence_sensorsim_cfg; ///< Cadence configuration of the simulated sensor.
sensorsim_state_t pedal_sensorsim_state; ///< Pedal state of the simulated sensor.
sensorsim_cfg_t pedal_sensorsim_cfg; ///< Pedal configuration of the simulated sensor.
}ant_bpwr_simulator_cb_t;
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_SIMULATOR_LOCAL_H__

View file

@ -0,0 +1,86 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BPWR_UTILS_H__
#define ANT_BPWR_UTILS_H__
#include "app_util.h"
#include "nrf_assert.h"
#include "nrf.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @file
*
* @defgroup ant_sdk_profiles_bpwr_utils Bicycle Power profile utilities
* @{
* @ingroup ant_bpwr
* @brief This module implements utilities for the Bicycle Power profile.
*
*/
/*@brief A reversal of torque period unit.
*
* @details According to the ANT BPWR specification, the torque period unit is 1/2048 of a second.
*/
#define ANT_BPWR_TORQUE_PERIOD_UNIT_REVERSAL 2048
#define ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION 1000
#define ANT_BPWR_TORQUE_PERIOD_RESCALE(VALUE) value_rescale((VALUE), ANT_BPWR_TORQUE_PERIOD_UNIT_REVERSAL, \
ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION)
/*@brief A reversal of accumulated torque unit.
*
* @details According to the ANT BPWR specification, the accumulated torque unit is 1/32 of a Nm.
*/
#define ANT_BPWR_ACC_TORQUE_UNIT_REVERSAL 32
#define ANT_BPWR_ACC_TORQUE_DISP_PRECISION 10
#define ANT_BPWR_ACC_TORQUE_RESCALE(VALUE) value_rescale((VALUE), ANT_BPWR_ACC_TORQUE_UNIT_REVERSAL, \
ANT_BPWR_ACC_TORQUE_DISP_PRECISION)
/** @} */
#ifdef __cplusplus
}
#endif
#endif // ANT_BPWR_UTILS_H__

View file

@ -0,0 +1,422 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "nrf_assert.h"
#include "nrf_error.h"
#include "app_error.h"
#include "ant_interface.h"
#include "ant_bsc.h"
#include "ant_bsc_utils.h"
#define NRF_LOG_MODULE_NAME ant_bsc
#if ANT_BSC_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_INFO_COLOR
#else // ANT_BSC_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#define MAIN_DATA_INTERVAL 4 /**< The number of background data pages sent between main data pages.*/
#define BACKGROUND_DATA_INTERVAL 64 /**< The number of main data pages sent between background data page.
Background data page is sent every 65th message. */
#define TX_TOGGLE_DIVISOR 4 /**< The number of messages between changing state of toggle bit. */
/**@brief BSC message data layout structure. */
typedef struct
{
ant_bsc_page_t page_number : 7;
uint8_t toggle_bit : 1;
uint8_t page_payload[7];
}ant_bsc_single_message_layout_t;
typedef struct
{
uint8_t page_payload[8];
}ant_bsc_combined_message_layout_t;
typedef union
{
ant_bsc_single_message_layout_t speed_or_cadence;
ant_bsc_combined_message_layout_t combined;
}ant_bsc_message_layout_t;
/**@brief Function for initializing the ANT BSC profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
static ret_code_t ant_bsc_init(ant_bsc_profile_t * p_profile,
ant_channel_config_t const * p_channel_config)
{
p_profile->channel_number = p_channel_config->channel_number;
p_profile->page_0 = DEFAULT_ANT_BSC_PAGE0();
p_profile->page_1 = DEFAULT_ANT_BSC_PAGE1();
p_profile->page_2 = DEFAULT_ANT_BSC_PAGE2();
p_profile->page_3 = DEFAULT_ANT_BSC_PAGE3();
p_profile->page_4 = DEFAULT_ANT_BSC_PAGE4();
p_profile->page_5 = DEFAULT_ANT_BSC_PAGE5();
p_profile->page_comb_0 = DEFAULT_ANT_BSC_COMBINED_PAGE0();
NRF_LOG_INFO("ANT BSC channel %u init", p_profile->channel_number);
return ant_channel_init(p_channel_config);
}
ret_code_t ant_bsc_disp_init(ant_bsc_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bsc_disp_config_t const * p_disp_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_disp_config->evt_handler != NULL);
p_profile->evt_handler = p_disp_config->evt_handler;
p_profile->_cb.p_disp_cb = p_disp_config->p_cb;
p_profile->_cb.p_disp_cb->device_type = p_channel_config->device_type;
return ant_bsc_init(p_profile, p_channel_config);
}
ret_code_t ant_bsc_sens_init(ant_bsc_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bsc_sens_config_t const * p_sens_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_sens_config != NULL);
ASSERT(p_sens_config->p_cb != NULL);
ASSERT(p_sens_config->evt_handler != NULL);
ASSERT((p_sens_config->main_page_number == ANT_BSC_PAGE_0)
|| (p_sens_config->main_page_number == ANT_BSC_PAGE_5)
|| (p_sens_config->main_page_number == ANT_BSC_COMB_PAGE_0));
p_profile->evt_handler = p_sens_config->evt_handler;
p_profile->_cb.p_sens_cb = p_sens_config->p_cb;
p_profile->_cb.p_sens_cb->page_1_present = p_sens_config->page_1_present;
p_profile->_cb.p_sens_cb->page_4_present = p_sens_config->page_4_present;
p_profile->_cb.p_sens_cb->main_page_number = p_sens_config->main_page_number;
p_profile->_cb.p_sens_cb->bkgd_page_number =
p_sens_config->page_1_present ? ANT_BSC_PAGE_1 : ANT_BSC_PAGE_2;
p_profile->_cb.p_sens_cb->message_counter = 0;
p_profile->_cb.p_sens_cb->toggle_bit = true;
p_profile->_cb.p_sens_cb->device_type = p_channel_config->device_type; /* Device type is set up in channel config */
return ant_bsc_init(p_profile, p_channel_config);
}
/**@brief Function for setting the next background page number.
*
* @param[in] p_profile Pointer to the profile instance.
*
*/
__STATIC_INLINE void next_bkgd_page_number_set(ant_bsc_profile_t * p_profile)
{
/* Determine the last background page*/
ant_bsc_page_t last_bkgd_page =
p_profile->_cb.p_sens_cb->page_4_present ? ANT_BSC_PAGE_4 : ANT_BSC_PAGE_3;
/* Switch the background page according to user settings */
++(p_profile->_cb.p_sens_cb->bkgd_page_number);
if (p_profile->_cb.p_sens_cb->bkgd_page_number > last_bkgd_page)
{
p_profile->_cb.p_sens_cb->bkgd_page_number =
p_profile->_cb.p_sens_cb->page_1_present ? ANT_BSC_PAGE_1 : ANT_BSC_PAGE_2;
}
}
/**@brief Function for getting next page number to send.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @return Next page number.
*/
static ant_bsc_page_t next_page_number_get(ant_bsc_profile_t * p_profile)
{
ant_bsc_page_t page_number;
/* This is a single speed or cadence sensor - switch data page */
if (p_profile->_cb.p_sens_cb->message_counter < (BACKGROUND_DATA_INTERVAL))
{
/* Return main page */
page_number = p_profile->_cb.p_sens_cb->main_page_number;
}
else
{
/* Return background page */
page_number = p_profile->_cb.p_sens_cb->bkgd_page_number;
}
/* Set page toggle bit */
if ((p_profile->_cb.p_sens_cb->message_counter % TX_TOGGLE_DIVISOR) == 0)
{
p_profile->_cb.p_sens_cb->toggle_bit ^= 1;
}
/* Update message counter, wrap when counter equals 64 + 4 */
++(p_profile->_cb.p_sens_cb->message_counter);
if (p_profile->_cb.p_sens_cb->message_counter == (BACKGROUND_DATA_INTERVAL + MAIN_DATA_INTERVAL))
{
p_profile->_cb.p_sens_cb->message_counter = 0;
/* Set new background data page number */
next_bkgd_page_number_set(p_profile);
}
return page_number;
}
/**@brief Function for encoding BSC message.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[out] p_message_payload Pointer to the message payload structure.
*
* @note Assume to be called each time when Tx window will occur.
*/
static void sens_message_encode(ant_bsc_profile_t * p_profile, uint8_t * p_message_payload)
{
ant_bsc_message_layout_t * p_bsc_message_payload = (ant_bsc_message_layout_t *)p_message_payload;
ant_bsc_evt_t bsc_sens_event;
if (p_profile->_cb.p_sens_cb->device_type == BSC_COMBINED_DEVICE_TYPE)
{
NRF_LOG_INFO("BSC TX Page: \"Combined Speed & Cadence Page\"");
ant_bsc_combined_page_0_encode(p_bsc_message_payload->combined.page_payload,
&(p_profile->page_comb_0));
bsc_sens_event = (ant_bsc_evt_t) ANT_BSC_COMB_PAGE_0_UPDATED;
}
else
{
p_bsc_message_payload->speed_or_cadence.page_number = next_page_number_get(p_profile);
p_bsc_message_payload->speed_or_cadence.toggle_bit = p_profile->_cb.p_sens_cb->toggle_bit;
NRF_LOG_INFO("BSC TX Page number: %u",
p_bsc_message_payload->speed_or_cadence.page_number);
ant_bsc_page_0_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_0));
bsc_sens_event = (ant_bsc_evt_t) p_bsc_message_payload->speed_or_cadence.page_number;
switch (p_bsc_message_payload->speed_or_cadence.page_number)
{
case ANT_BSC_PAGE_0:
// No implementation needed
break;
case ANT_BSC_PAGE_1:
ant_bsc_page_1_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_1));
break;
case ANT_BSC_PAGE_2:
ant_bsc_page_2_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_2));
break;
case ANT_BSC_PAGE_3:
ant_bsc_page_3_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_3));
break;
case ANT_BSC_PAGE_4:
ant_bsc_page_4_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_4));
break;
case ANT_BSC_PAGE_5:
ant_bsc_page_5_encode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_5));
break;
default:
// No implementation needed
break;
}
}
p_profile->evt_handler(p_profile, bsc_sens_event);
}
/**@brief Function for setting payload for ANT message and sending it.
*
* @param[in] p_profile Pointer to the profile instance.
*/
static void ant_message_send(ant_bsc_profile_t * p_profile)
{
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
uint32_t err_code;
sens_message_encode(p_profile, p_message_payload);
err_code = sd_ant_broadcast_message_tx(p_profile->channel_number,
sizeof(p_message_payload),
p_message_payload);
APP_ERROR_CHECK(err_code);
}
void ant_bsc_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ant_bsc_profile_t * p_profile = (ant_bsc_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
switch (p_ant_evt->event)
{
case EVENT_TX:
ant_message_send(p_profile);
break;
default:
break;
}
}
}
ret_code_t ant_bsc_disp_open(ant_bsc_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
NRF_LOG_INFO("ANT BSC channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
ret_code_t ant_bsc_sens_open(ant_bsc_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
// Fill tx buffer for the first frame
ant_message_send(p_profile);
NRF_LOG_INFO("ANT BSC channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
/**@brief Function for decoding BSC message.
*
* @param[in,out] p_profile Pointer to the profile instance.
* @param[in] p_message_payload Pointer to the message payload structure.
*
* @note Assume to be call each time when Rx window will occur.
*/
static void disp_message_decode(ant_bsc_profile_t * p_profile, uint8_t * p_message_payload)
{
const ant_bsc_message_layout_t * p_bsc_message_payload =
(ant_bsc_message_layout_t *)p_message_payload;
ant_bsc_evt_t bsc_disp_event;
if (p_profile->_cb.p_disp_cb->device_type == BSC_COMBINED_DEVICE_TYPE)
{
NRF_LOG_INFO("BSC RX Page Number: \"Combined Speed & Cadence Page\"");
ant_bsc_combined_page_0_decode(p_bsc_message_payload->combined.page_payload,
&(p_profile->page_comb_0));
bsc_disp_event = (ant_bsc_evt_t) ANT_BSC_COMB_PAGE_0_UPDATED;
}
else
{
NRF_LOG_INFO("BSC RX Page Number: %u",
p_bsc_message_payload->speed_or_cadence.page_number);
ant_bsc_page_0_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_0)); // Page 0 is present in each message
bsc_disp_event = (ant_bsc_evt_t) p_bsc_message_payload->speed_or_cadence.page_number;
switch (p_bsc_message_payload->speed_or_cadence.page_number)
{
case ANT_BSC_PAGE_0:
// No implementation needed
break;
case ANT_BSC_PAGE_1:
ant_bsc_page_1_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_1));
break;
case ANT_BSC_PAGE_2:
ant_bsc_page_2_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_2));
break;
case ANT_BSC_PAGE_3:
ant_bsc_page_3_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_3));
break;
case ANT_BSC_PAGE_4:
ant_bsc_page_4_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_4));
break;
case ANT_BSC_PAGE_5:
ant_bsc_page_5_decode(p_bsc_message_payload->speed_or_cadence.page_payload,
&(p_profile->page_5));
break;
default:
// No implementation needed
break;
}
}
p_profile->evt_handler(p_profile, bsc_disp_event);
}
void ant_bsc_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ant_bsc_profile_t * p_profile = (ant_bsc_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
switch (p_ant_evt->event)
{
case EVENT_RX:
if (p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
{
disp_message_decode(p_profile, p_ant_evt->message.ANT_MESSAGE_aucPayload);
}
break;
default:
break;
}
}
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,359 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ant_bsc Bicycle Speed and Cadence profile
* @{
* @ingroup ant_sdk_profiles
* @brief This module implements the Bicycle Speed and Cadence profile.
*
*/
#ifndef ANT_BSC_H__
#define ANT_BSC_H__
#include <stdint.h>
#include <stdbool.h>
#include "sdk_errors.h"
#include "ant_parameters.h"
#include "nrf_sdh_ant.h"
#include "ant_channel_config.h"
#include "ant_bsc_pages.h"
#define BSC_ANTPLUS_RF_FREQ 0x39u ///< Frequency, decimal 57 (2457 MHz).
#define BSC_SPEED_DEVICE_TYPE 0x7B ///< Device type reserved for ANT+ bike speed sensor.
#define BSC_CADENCE_DEVICE_TYPE 0x7A ///< Device type reserved for ANT+ bike cadence sensor.
#define BSC_COMBINED_DEVICE_TYPE 0x79 ///< Device type reserved for ANT+ bike combined speed and cadence sensor.
#define BSC_MSG_PERIOD_4Hz 1u ///< Message period, 4 Hz (in basic period counts, where basic period time = 0.25 s).
#define BSC_MSG_PERIOD_2Hz 2u ///< Message period, 2 Hz (in basic period counts).
#define BSC_MSG_PERIOD_1Hz 4u ///< Message period, 1 Hz (in basic period counts).
#define BSC_MSG_PERIOD_SPEED 0x1FB6u ///< Message period in ticks, decimal 8118 (4.04 Hz).
#define BSC_MSG_PERIOD_CADENCE 0x1FA6u ///< Message period in ticks, decimal 8102 (4.04 Hz).
#define BSC_MSG_PERIOD_COMBINED 0x1F96u ///< Message period in ticks, decimal 8086 (4.05 Hz).
#define BSC_EXT_ASSIGN 0x00 ///< ANT ext assign (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
#define BSC_DISP_CHANNEL_TYPE CHANNEL_TYPE_SLAVE_RX_ONLY ///< Display BSC channel type.
#define BSC_SENS_CHANNEL_TYPE CHANNEL_TYPE_MASTER ///< Sensor BSC channel type.
/**@brief Select the basic ANT channel period (in ticks) for the BSC profile depending on the device type.
*
* @param[in] DEVICE_TYPE Type of device. Supported types: @ref BSC_SPEED_DEVICE_TYPE, @ref BSC_CADENCE_DEVICE_TYPE,
* @ref BSC_COMBINED_DEVICE_TYPE.
*/
#define BSC_DEVICE_TICKS(DEVICE_TYPE) \
((DEVICE_TYPE) == (BSC_SPEED_DEVICE_TYPE) ? (BSC_MSG_PERIOD_SPEED) : \
((DEVICE_TYPE) == (BSC_CADENCE_DEVICE_TYPE) ? (BSC_MSG_PERIOD_CADENCE) : \
((DEVICE_TYPE) == (BSC_COMBINED_DEVICE_TYPE) ? (BSC_MSG_PERIOD_COMBINED) : 0u)))
/**@brief Calculate the channel period (in ticks) depending on the device type and the chosen message frequency.
*
* @param[in] DEVICE_TYPE Type of device. Supported types: @ref BSC_SPEED_DEVICE_TYPE, @ref BSC_CADENCE_DEVICE_TYPE,
* @ref BSC_COMBINED_DEVICE_TYPE.
* @param[in] BSC_MSG_PERIOD Channel data period. The BSC profile supports only the following periods:
* @ref BSC_MSG_PERIOD_4Hz, @ref BSC_MSG_PERIOD_2Hz, @ref BSC_MSG_PERIOD_1Hz.
*/
#define BSC_PERIOD_TICKS(DEVICE_TYPE, BSC_MSG_PERIOD) \
((BSC_DEVICE_TICKS(DEVICE_TYPE)) * (BSC_MSG_PERIOD))
/**@brief Initialize an ANT channel configuration structure for the BSC profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_TYPE Type of device. Supported types: @ref BSC_SPEED_DEVICE_TYPE, @ref BSC_CADENCE_DEVICE_TYPE,
* @ref BSC_COMBINED_DEVICE_TYPE.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
* @param[in] BSC_MSG_PERIOD Channel data frequency in Hz. The BSC profile supports only the following frequencies:
* @ref BSC_MSG_PERIOD_4Hz, @ref BSC_MSG_PERIOD_2Hz, @ref BSC_MSG_PERIOD_1Hz.
*/
#define BSC_DISP_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER, \
BSC_MSG_PERIOD) \
static const ant_channel_config_t CONCAT_2(NAME, _channel_bsc_disp_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = BSC_DISP_CHANNEL_TYPE, \
.ext_assign = BSC_EXT_ASSIGN, \
.rf_freq = BSC_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = (DEVICE_TYPE), \
.device_number = (DEVICE_NUMBER), \
.channel_period = BSC_PERIOD_TICKS(DEVICE_TYPE, BSC_MSG_PERIOD), \
.network_number = (NETWORK_NUMBER), \
}
#define BSC_DISP_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME, _channel_bsc_disp_config)
/**@brief Initialize an ANT channel configuration structure for the BSC profile (Transmitter).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_TYPE Type of device. Supported types: @ref BSC_SPEED_DEVICE_TYPE, @ref BSC_CADENCE_DEVICE_TYPE,
* @ref BSC_COMBINED_DEVICE_TYPE.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
*/
#define BSC_SENS_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER) \
static const ant_channel_config_t NAME##_channel_bsc_sens_config = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = BSC_SENS_CHANNEL_TYPE, \
.ext_assign = BSC_EXT_ASSIGN, \
.rf_freq = BSC_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = (DEVICE_TYPE), \
.device_number = (DEVICE_NUMBER), \
.channel_period = BSC_PERIOD_TICKS(DEVICE_TYPE, BSC_MSG_PERIOD_4Hz), \
.network_number = (NETWORK_NUMBER), \
}
#define BSC_SENS_CHANNEL_CONFIG(NAME) &NAME##_channel_bsc_sens_config
/**@brief Initialize an ANT profile configuration structure for the BSC profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BSC profile.
*/
#define BSC_DISP_PROFILE_CONFIG_DEF(NAME, \
EVT_HANDLER) \
static ant_bsc_disp_cb_t CONCAT_2(NAME, _bsc_disp_cb); \
static const ant_bsc_disp_config_t CONCAT_2(NAME, _profile_bsc_disp_config) = \
{ \
.p_cb = &CONCAT_2(NAME, _bsc_disp_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define BSC_DISP_PROFILE_CONFIG(NAME) &CONCAT_2(NAME, _profile_bsc_disp_config)
/**@brief Initialize an ANT profile configuration structure for the BSC profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] PAGE_1_PRESENT Determines whether page 1 is included.
* @param[in] PAGE_4_PRESENT Determines whether page 4 is included.
* @param[in] MAIN_PAGE_NUMBER Determines the main data page (@ref ANT_BSC_PAGE_0 or @ref ANT_BSC_PAGE_5 or @ref ANT_BSC_COMB_PAGE_0).
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BSC profile.
*/
#define BSC_SENS_PROFILE_CONFIG_DEF(NAME, \
PAGE_1_PRESENT, \
PAGE_4_PRESENT, \
MAIN_PAGE_NUMBER, \
EVT_HANDLER) \
static ant_bsc_sens_cb_t CONCAT_2(NAME, _bsc_sens_cb); \
static const ant_bsc_sens_config_t CONCAT_2(NAME, _profile_bsc_sens_config) = \
{ \
.page_1_present = (PAGE_1_PRESENT), \
.page_4_present = (PAGE_4_PRESENT), \
.main_page_number = (MAIN_PAGE_NUMBER), \
.p_cb = &CONCAT_2(NAME, _bsc_sens_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define BSC_SENS_PROFILE_CONFIG(NAME) &CONCAT_2(NAME, _profile_bsc_sens_config)
/**@brief BSC page number type. */
typedef enum{
ANT_BSC_PAGE_0, ///< Main data page number 0.
ANT_BSC_PAGE_1, ///< Background data page number 1. This page is optional.
ANT_BSC_PAGE_2, ///< Background data page number 2.
ANT_BSC_PAGE_3, ///< Background data page number 3.
ANT_BSC_PAGE_4, ///< Background data page number 4. This page is optional.
ANT_BSC_PAGE_5, ///< Main data page number 5. This page is optional.
ANT_BSC_COMB_PAGE_0 ///< Main data page number 0 for combined speed and cadence sensor.
} ant_bsc_page_t;
/**@brief BSC profile event type. */
typedef enum{
ANT_BSC_PAGE_0_UPDATED = ANT_BSC_PAGE_0, ///< Data page 0 has been updated (Display) or sent (Sensor).
ANT_BSC_PAGE_1_UPDATED = ANT_BSC_PAGE_1, ///< Data page 0 and page 1 have been updated (Display) or sent (Sensor).
ANT_BSC_PAGE_2_UPDATED = ANT_BSC_PAGE_2, ///< Data page 0 and page 2 have been updated (Display) or sent (Sensor).
ANT_BSC_PAGE_3_UPDATED = ANT_BSC_PAGE_3, ///< Data page 0 and page 3 have been updated (Display) or sent (Sensor).
ANT_BSC_PAGE_4_UPDATED = ANT_BSC_PAGE_4, ///< Data page 0 and page 4 have been updated (Display) or sent (Sensor).
ANT_BSC_PAGE_5_UPDATED = ANT_BSC_PAGE_5, ///< Data page 0 and page 5 have been updated (Display) or sent (Sensor).
ANT_BSC_COMB_PAGE_0_UPDATED = ANT_BSC_COMB_PAGE_0, ///< Combined Speed and cadence data page has been updated (Display) or sent (Sensor).
} ant_bsc_evt_t;
// Forward declaration of the ant_bsc_profile_t type.
typedef struct ant_bsc_profile_s ant_bsc_profile_t;
/**@brief BSC event handler type. */
typedef void (* ant_bsc_evt_handler_t) (ant_bsc_profile_t *, ant_bsc_evt_t);
#include "ant_bsc_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BSC Display configuration structure. */
typedef struct
{
ant_bsc_disp_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_bsc_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BSC profile.
} ant_bsc_disp_config_t;
/**@brief BSC Sensor configuration structure. */
typedef struct
{
bool page_1_present; ///< Determines whether page 1 is included.
bool page_4_present; ///< Determines whether page 4 is included.
ant_bsc_page_t main_page_number; ///< Determines the main data page (@ref ANT_BSC_PAGE_0 or @ref ANT_BSC_PAGE_5 or @ref ANT_BSC_COMB_PAGE_0).
ant_bsc_sens_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_bsc_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BSC profile.
} ant_bsc_sens_config_t;
/**@brief BSC profile structure. */
struct ant_bsc_profile_s
{
uint8_t channel_number; ///< Channel number assigned to the profile.
union {
ant_bsc_disp_cb_t * p_disp_cb;
ant_bsc_sens_cb_t * p_sens_cb;
} _cb; ///< Pointer to internal control block.
ant_bsc_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BSC profile.
ant_bsc_page0_data_t page_0; ///< Page 0.
ant_bsc_page1_data_t page_1; ///< Page 1.
ant_bsc_page2_data_t page_2; ///< Page 2.
ant_bsc_page3_data_t page_3; ///< Page 3.
ant_bsc_page4_data_t page_4; ///< Page 4.
ant_bsc_page5_data_t page_5; ///< Page 5.
ant_bsc_combined_page0_data_t page_comb_0; ///< Page 0 for combined speed and cadence sensor.
};
/** @name Defines for accessing ant_bsc_profile_t member variables
@{ */
#define BSC_PROFILE_event_time page_0.event_time
#define BSC_PROFILE_rev_count page_0.rev_count
#define BSC_PROFILE_operating_time page_1.operating_time
#define BSC_PROFILE_manuf_id page_2.manuf_id
#define BSC_PROFILE_serial_num page_2.serial_num
#define BSC_PROFILE_hw_version page_3.hw_version
#define BSC_PROFILE_sw_version page_3.sw_version
#define BSC_PROFILE_model_num page_3.model_num
#define BSC_PROFILE_fract_bat_volt page_4.fract_bat_volt
#define BSC_PROFILE_coarse_bat_volt page_4.coarse_bat_volt
#define BSC_PROFILE_bat_status page_4.bat_status
#define BSC_PROFILE_stop_indicator page_5.stop_indicator
#define BSC_PROFILE_cadence_event_time page_comb_0.cadence_event_time
#define BSC_PROFILE_cadence_rev_count page_comb_0.cadence_rev_count
#define BSC_PROFILE_speed_event_time page_comb_0.speed_event_time
#define BSC_PROFILE_speed_rev_count page_comb_0.speed_rev_count
/** @} */
/**@brief Function for initializing the ANT BSC profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_disp_config Pointer to the BSC display configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_bsc_disp_init(ant_bsc_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bsc_disp_config_t const * p_disp_config);
/**@brief Function for initializing the ANT BSC profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_sens_config Pointer to the BSC sensor configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_bsc_sens_init(ant_bsc_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_bsc_sens_config_t const * p_sens_config);
/**@brief Function for opening the profile instance channel for the ANT BSC Display.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_bsc_disp_open(ant_bsc_profile_t * p_profile);
/**@brief Function for opening the profile instance channel for the ANT BSC Sensor.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_bsc_sens_open(ant_bsc_profile_t * p_profile);
/**@brief Function for handling the Sensor ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Speed and Cadence Sensor profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_bsc_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
/**@brief Function for handling the Display ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Speed and Cadence Display profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_bsc_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_H__
/** @} */

View file

@ -0,0 +1,83 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_LOCAL_H__
#define ANT_BSC_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_bsc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup ant_bsc
* @{
*/
/**@brief BSC Sensor control block. */
typedef struct
{
uint8_t device_type;
uint8_t toggle_bit : 1;
ant_bsc_page_t main_page_number : 7;
uint8_t page_1_present : 1;
uint8_t page_4_present : 1;
ant_bsc_page_t bkgd_page_number : 6;
uint8_t message_counter;
}ant_bsc_sens_cb_t;
/**@brief BSC Display control block. */
typedef struct
{
uint8_t device_type;
}ant_bsc_disp_cb_t;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_LOCAL_H__

View file

@ -0,0 +1,129 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_combined_page_0.h"
#include "ant_bsc_utils.h"
#define NRF_LOG_MODULE_NAME ant_bcs_combined_page_0
#if ANT_BSC_COMBINED_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_COMBINED_PAGE_0_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_COMBINED_PAGE_0_INFO_COLOR
#else // ANT_BSC_COMBINED_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_COMBINED_PAGE_0_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 0 data layout structure. */
typedef struct
{
uint8_t cadence_evt_time_LSB;
uint8_t cadence_evt_time_MSB;
uint8_t cadence_rev_count_LSB;
uint8_t cadence_rev_count_MSB;
uint8_t speed_evt_time_LSB;
uint8_t speed_evt_time_MSB;
uint8_t speed_rev_count_LSB;
uint8_t speed_rev_count_MSB;
}ant_bsc_combined_page0_data_layout_t;
/**@brief Function for printing combined speed and cadence page0 data. */
static void comb_page0_data_log(ant_bsc_combined_page0_data_t const * p_page_data)
{
NRF_LOG_INFO("Cadence Revolution count: %u",
(unsigned int)p_page_data->cadence_rev_count);
NRF_LOG_INFO("Cadence event time: %u.%03us",
(unsigned int)ANT_BSC_EVENT_TIME_SEC(p_page_data->cadence_event_time),
(unsigned int)ANT_BSC_EVENT_TIME_MSEC(p_page_data->cadence_event_time));
NRF_LOG_INFO("Speed Revolution count: %u",
(unsigned int)p_page_data->speed_rev_count);
NRF_LOG_INFO("Speed event time: %u.%03us\r\n\n",
(unsigned int)ANT_BSC_EVENT_TIME_SEC(p_page_data->speed_event_time),
(unsigned int)ANT_BSC_EVENT_TIME_MSEC(p_page_data->speed_event_time));
}
void ant_bsc_combined_page_0_encode(uint8_t * p_page_buffer, ant_bsc_combined_page0_data_t const * p_page_data)
{
ant_bsc_combined_page0_data_layout_t * p_outcoming_data = (ant_bsc_combined_page0_data_layout_t *) p_page_buffer;
uint16_t cadence_event_time = p_page_data->cadence_event_time;
uint16_t cadence_rev_count = p_page_data->cadence_rev_count;
uint16_t speed_event_time = p_page_data->speed_event_time;
uint16_t speed_rev_count = p_page_data->speed_rev_count;
p_outcoming_data->cadence_evt_time_LSB = (uint8_t)(cadence_event_time & UINT8_MAX);
p_outcoming_data->cadence_evt_time_MSB = (uint8_t)((cadence_event_time >> 8) & UINT8_MAX);
p_outcoming_data->cadence_rev_count_LSB = (uint8_t)(cadence_rev_count & UINT8_MAX);
p_outcoming_data->cadence_rev_count_MSB = (uint8_t)((cadence_rev_count >> 8) & UINT8_MAX);
p_outcoming_data->speed_evt_time_LSB = (uint8_t)(speed_event_time & UINT8_MAX);
p_outcoming_data->speed_evt_time_MSB = (uint8_t)((speed_event_time >> 8) & UINT8_MAX);
p_outcoming_data->speed_rev_count_LSB = (uint8_t)(speed_rev_count & UINT8_MAX);
p_outcoming_data->speed_rev_count_MSB = (uint8_t)((speed_rev_count >> 8) & UINT8_MAX);
comb_page0_data_log(p_page_data);
}
void ant_bsc_combined_page_0_decode(uint8_t const * p_page_buffer, ant_bsc_combined_page0_data_t * p_page_data)
{
ant_bsc_combined_page0_data_layout_t const * p_incoming_data = (ant_bsc_combined_page0_data_layout_t *)p_page_buffer;
uint16_t cadence_event_time = (uint16_t)((p_incoming_data->cadence_evt_time_MSB << 8)
+ p_incoming_data->cadence_evt_time_LSB);
uint16_t cadence_revolution_count = (uint16_t) ((p_incoming_data->cadence_rev_count_MSB << 8)
+ p_incoming_data->cadence_rev_count_LSB);
uint16_t speed_event_time = (uint16_t)((p_incoming_data->speed_evt_time_MSB << 8)
+ p_incoming_data->speed_evt_time_LSB);
uint16_t speed_revolution_count = (uint16_t) ((p_incoming_data->speed_rev_count_MSB << 8)
+ p_incoming_data->speed_rev_count_LSB);
p_page_data->cadence_event_time = cadence_event_time;
p_page_data->cadence_rev_count = cadence_revolution_count;
p_page_data->speed_event_time = speed_event_time;
p_page_data->speed_rev_count = speed_revolution_count;
comb_page0_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_COMBINED_PAGE_0_H__
#define ANT_BSC_COMBINED_PAGE_0_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_combined_page0 BSC profile page 0 (combined speed & cadence)
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for Bicycle Combined Speed and Cadence data page 0.
*
* This structure is used as a common page.
*/
typedef struct
{
uint16_t cadence_event_time; ///< Cadence event time.
uint16_t cadence_rev_count; ///< Cadence revolution count.
uint16_t speed_event_time; ///< Speed event time.
uint16_t speed_rev_count; ///< Speed revolution count.
} ant_bsc_combined_page0_data_t;
/**@brief Initialize page 0.
*/
#define DEFAULT_ANT_BSC_COMBINED_PAGE0() \
(ant_bsc_combined_page0_data_t) \
{ \
.cadence_event_time = 0, \
.cadence_rev_count = 0, \
.speed_event_time = 0, \
.speed_rev_count = 0, \
}
/**@brief Function for encoding page 0.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_combined_page_0_encode(uint8_t * p_page_buffer, ant_bsc_combined_page0_data_t const * p_page_data);
/**@brief Function for decoding page 0.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_combined_page_0_decode(uint8_t const * p_page_buffer, ant_bsc_combined_page0_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_COMBINED_PAGE_0_H__
/** @} */

View file

@ -0,0 +1,111 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_0.h"
#include "ant_bsc_utils.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_0
#if ANT_BSC_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_0_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_0_INFO_COLOR
#else // ANT_BSC_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_0_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 0 data layout structure. */
typedef struct
{
uint8_t reserved[3];
uint8_t bsc_evt_time_LSB;
uint8_t bsc_evt_time_MSB;
uint8_t bsc_rev_count_LSB;
uint8_t bsc_rev_count_MSB;
}ant_bsc_page0_data_layout_t;
/**@brief Function for printing speed or cadence page0 data. */
static void page0_data_log(ant_bsc_page0_data_t const * p_page_data)
{
NRF_LOG_INFO("Revolution count: %u", (unsigned int)p_page_data->rev_count);
NRF_LOG_INFO("BSC event time: %u.%03us",
(unsigned int)ANT_BSC_EVENT_TIME_SEC(p_page_data->event_time),
(unsigned int)ANT_BSC_EVENT_TIME_MSEC(p_page_data->event_time));
// NRF_LOG_INFO("%03us", (unsigned int)ANT_BSC_EVENT_TIME_MSEC(p_page_data->event_time));
}
void ant_bsc_page_0_encode(uint8_t * p_page_buffer, ant_bsc_page0_data_t const * p_page_data)
{
ant_bsc_page0_data_layout_t * p_outcoming_data = (ant_bsc_page0_data_layout_t *) p_page_buffer;
uint16_t event_time = p_page_data->event_time;
uint16_t rev_count = p_page_data->rev_count;
p_outcoming_data->reserved[0] = UINT8_MAX;
p_outcoming_data->reserved[1] = UINT8_MAX;
p_outcoming_data->reserved[2] = UINT8_MAX;
p_outcoming_data->bsc_evt_time_LSB = (uint8_t)(event_time & UINT8_MAX);
p_outcoming_data->bsc_evt_time_MSB = (uint8_t)((event_time >> 8) & UINT8_MAX);
p_outcoming_data->bsc_rev_count_LSB = (uint8_t)(rev_count & UINT8_MAX);
p_outcoming_data->bsc_rev_count_MSB = (uint8_t)((rev_count >> 8) & UINT8_MAX);
page0_data_log(p_page_data);
}
void ant_bsc_page_0_decode(uint8_t const * p_page_buffer, ant_bsc_page0_data_t * p_page_data)
{
ant_bsc_page0_data_layout_t const * p_incoming_data = (ant_bsc_page0_data_layout_t *)p_page_buffer;
uint16_t event_time = (uint16_t)((p_incoming_data->bsc_evt_time_MSB << 8)
+ p_incoming_data->bsc_evt_time_LSB);
uint16_t revolution_count = (uint16_t) ((p_incoming_data->bsc_rev_count_MSB << 8)
+ p_incoming_data->bsc_rev_count_LSB);
p_page_data->event_time = event_time;
p_page_data->rev_count = revolution_count;
page0_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,95 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_0_H__
#define ANT_BSC_PAGE_0_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page0 BSC profile page 0
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BSC data page 0.
*
* This structure is used as a common page.
*/
typedef struct
{
uint16_t event_time; ///< Speed or cadence event time.
uint16_t rev_count; ///< Speed or cadence revolution count.
} ant_bsc_page0_data_t;
/**@brief Initialize page 0.
*/
#define DEFAULT_ANT_BSC_PAGE0() \
(ant_bsc_page0_data_t) \
{ \
.event_time = 0, \
.rev_count = 0 \
}
/**@brief Function for encoding page 0.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_0_encode(uint8_t * p_page_buffer, ant_bsc_page0_data_t const * p_page_data);
/**@brief Function for decoding page 0.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_0_decode(uint8_t const * p_page_buffer, ant_bsc_page0_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_0_H__
/** @} */

View file

@ -0,0 +1,94 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_1.h"
#include "ant_bsc_utils.h"
#include "app_util.h"
#include "nordic_common.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_1
#if ANT_BSC_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_1_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_1_INFO_COLOR
#else // ANT_BSC_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_1_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 1 data layout structure. */
typedef struct
{
uint8_t cumulative_operating_time[3];
uint8_t reserved[4];
}ant_bsc_page1_data_layout_t;
/**@brief Function for printing speed or cadence page1 data. */
static void page1_data_log(ant_bsc_page1_data_t const * p_page_data)
{
NRF_LOG_INFO("Cumulative operating time: %ud %uh %um %us",
(unsigned int)ANT_BSC_OPERATING_DAYS(p_page_data->operating_time),
(unsigned int)ANT_BSC_OPERATING_HOURS(p_page_data->operating_time),
(unsigned int)ANT_BSC_OPERATING_MINUTES(p_page_data->operating_time),
(unsigned int)ANT_BSC_OPERATING_SECONDS(p_page_data->operating_time));
}
void ant_bsc_page_1_encode(uint8_t * p_page_buffer, ant_bsc_page1_data_t const * p_page_data)
{
ant_bsc_page1_data_layout_t * p_outcoming_data = (ant_bsc_page1_data_layout_t *)p_page_buffer;
UNUSED_PARAMETER(uint24_encode(p_page_data->operating_time,
p_outcoming_data->cumulative_operating_time));
page1_data_log( p_page_data);
}
void ant_bsc_page_1_decode(uint8_t const * p_page_buffer, ant_bsc_page1_data_t * p_page_data)
{
ant_bsc_page1_data_layout_t const * p_incoming_data = (ant_bsc_page1_data_layout_t *)p_page_buffer;
p_page_data->operating_time = uint24_decode(p_incoming_data->cumulative_operating_time);
page1_data_log( p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,93 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_1_H__
#define ANT_BSC_PAGE_1_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page1 BSC profile page 1
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BSC data page 1.
*
* This structure implements only page 1 specific data.
*/
typedef struct
{
uint32_t operating_time; ///< Operating time.
} ant_bsc_page1_data_t;
/**@brief Initialize page 1.
*/
#define DEFAULT_ANT_BSC_PAGE1() \
(ant_bsc_page1_data_t) \
{ \
.operating_time = 0, \
}
/**@brief Function for encoding page 1.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_1_encode(uint8_t * p_page_buffer, ant_bsc_page1_data_t const * p_page_data);
/**@brief Function for decoding page 1.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_1_decode(uint8_t const * p_page_buffer, ant_bsc_page1_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_1_H__
/** @} */

View file

@ -0,0 +1,96 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_2.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_2
#if ANT_BSC_PAGE_2_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_2_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_2_INFO_COLOR
#else // ANT_BSC_PAGE_2_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_2_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 2 data layout structure. */
typedef struct
{
uint8_t manuf_id;
uint8_t serial_num_LSB;
uint8_t serial_num_MSB;
uint8_t reserved[4];
}ant_bsc_page2_data_layout_t;
/**@brief Function for printing speed or cadence page2 data. */
static void page2_data_log(ant_bsc_page2_data_t const * p_page_data)
{
NRF_LOG_INFO("Manufacturer ID: %u", (unsigned int)p_page_data->manuf_id);
NRF_LOG_INFO("Serial No (upper 16-bits): 0x%X",
(unsigned int)p_page_data->serial_num);
}
void ant_bsc_page_2_encode(uint8_t * p_page_buffer, ant_bsc_page2_data_t const * p_page_data)
{
ant_bsc_page2_data_layout_t * p_outcoming_data = (ant_bsc_page2_data_layout_t *)p_page_buffer;
uint32_t serial_num = p_page_data->serial_num;
p_outcoming_data->manuf_id = (uint8_t)p_page_data->manuf_id;
p_outcoming_data->serial_num_LSB = (uint8_t)(serial_num & UINT8_MAX);
p_outcoming_data->serial_num_MSB = (uint8_t)((serial_num >> 8) & UINT8_MAX);
page2_data_log( p_page_data);
}
void ant_bsc_page_2_decode(uint8_t const * p_page_buffer, ant_bsc_page2_data_t * p_page_data)
{
ant_bsc_page2_data_layout_t const * p_incoming_data = (ant_bsc_page2_data_layout_t *)p_page_buffer;
uint32_t serial_num = (uint32_t)((p_incoming_data->serial_num_MSB << 8)
+ p_incoming_data->serial_num_LSB);
p_page_data->manuf_id = (uint32_t)p_incoming_data->manuf_id;
p_page_data->serial_num = serial_num;
page2_data_log( p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,95 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_2_H__
#define ANT_BSC_PAGE_2_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page2 BSC profile page 2
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BSC data page 2.
*
* This structure implements only page 2 specific data.
*/
typedef struct
{
uint8_t manuf_id; ///< Manufacturer ID.
uint16_t serial_num; ///< Serial number.
} ant_bsc_page2_data_t;
/**@brief Initialize page 2.
*/
#define DEFAULT_ANT_BSC_PAGE2() \
(ant_bsc_page2_data_t) \
{ \
.manuf_id = 0, \
.serial_num = 0, \
}
/**@brief Function for encoding page 2.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_2_encode(uint8_t * p_page_buffer, ant_bsc_page2_data_t const * p_page_data);
/**@brief Function for decoding page 2.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_2_decode(uint8_t const * p_page_buffer, ant_bsc_page2_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_2_H__
/** @} */

View file

@ -0,0 +1,94 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_3.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_3
#if ANT_BSC_PAGE_3_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_3_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_3_INFO_COLOR
#else // ANT_BSC_PAGE_3_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_3_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 3 data layout structure. */
typedef struct
{
uint8_t hw_version;
uint8_t sw_version;
uint8_t model_num;
uint8_t reserved[4];
}ant_bsc_page3_data_layout_t;
/**@brief Function for printing speed or cadence page3 data. */
static void page3_data_log(ant_bsc_page3_data_t const * p_page_data)
{
NRF_LOG_INFO("Hardware Rev ID: %u", (unsigned int)p_page_data->hw_version);
NRF_LOG_INFO("Model Number: %u", (unsigned int)p_page_data->model_num);
NRF_LOG_INFO("Software Ver ID: %u", (unsigned int)p_page_data->sw_version);
}
void ant_bsc_page_3_encode(uint8_t * p_page_buffer, ant_bsc_page3_data_t const * p_page_data)
{
ant_bsc_page3_data_layout_t * p_outcoming_data = (ant_bsc_page3_data_layout_t *)p_page_buffer;
p_outcoming_data->hw_version = (uint8_t)p_page_data->hw_version;
p_outcoming_data->sw_version = (uint8_t)p_page_data->sw_version;
p_outcoming_data->model_num = (uint8_t)p_page_data->model_num;
page3_data_log( p_page_data);
}
void ant_bsc_page_3_decode(uint8_t const * p_page_buffer, ant_bsc_page3_data_t * p_page_data)
{
ant_bsc_page3_data_layout_t const * p_incoming_data = (ant_bsc_page3_data_layout_t *)p_page_buffer;
p_page_data->hw_version = (uint32_t)p_incoming_data->hw_version;
p_page_data->sw_version = (uint32_t)p_incoming_data->sw_version;
p_page_data->model_num = (uint32_t)p_incoming_data->model_num;
page3_data_log( p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,97 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_3_H__
#define ANT_BSC_PAGE_3_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page3 BSC profile page 3
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BSC data page 3.
*
* This structure implements only page 3 specific data.
*/
typedef struct
{
uint8_t hw_version; ///< Hardware version.
uint8_t sw_version; ///< Software version.
uint8_t model_num; ///< Model number.
} ant_bsc_page3_data_t;
/**@brief Initialize page 3.
*/
#define DEFAULT_ANT_BSC_PAGE3() \
(ant_bsc_page3_data_t) \
{ \
.hw_version = 0, \
.sw_version = 0, \
.model_num = 0, \
}
/**@brief Function for encoding page 3.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_3_encode(uint8_t * p_page_buffer, ant_bsc_page3_data_t const * p_page_data);
/**@brief Function for decoding page 3.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_3_decode(uint8_t const * p_page_buffer, ant_bsc_page3_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_3_H__
/** @} */

View file

@ -0,0 +1,104 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_4.h"
#include "ant_bsc_utils.h"
#include "app_util.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_4
#if ANT_BSC_PAGE_4_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_4_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_4_INFO_COLOR
#else // ANT_BSC_PAGE_4_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_4_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC page 4 data layout structure. */
typedef struct
{
uint8_t reserved_byte;
uint8_t fract_bat_volt;
uint8_t coarse_bat_volt : 4;
uint8_t bat_status : 3;
uint8_t bitfield_reserved : 1;
uint8_t reserved[4];
}ant_bsc_page4_data_layout_t;
/* Display precission must be updated. */
STATIC_ASSERT(ANT_BSC_BAT_VOLTAGE_PRECISION == 1000);
/**@brief Function for printing speed or cadence page4 data. */
static void page4_data_log( ant_bsc_page4_data_t const * p_page_data)
{
NRF_LOG_INFO("Battery voltage: %u.%03uV",
(unsigned int)p_page_data->coarse_bat_volt,
(unsigned int)ANT_BSC_BAT_VOLTAGE_FRACTION_MV(p_page_data->fract_bat_volt));
NRF_LOG_INFO("Battery status: %u", (unsigned int)p_page_data->bat_status);
}
void ant_bsc_page_4_encode(uint8_t * p_page_buffer, ant_bsc_page4_data_t const * p_page_data)
{
ant_bsc_page4_data_layout_t * p_outcoming_data = (ant_bsc_page4_data_layout_t *)p_page_buffer;
p_outcoming_data->reserved_byte = UINT8_MAX;
p_outcoming_data->fract_bat_volt = p_page_data->fract_bat_volt;
p_outcoming_data->coarse_bat_volt = p_page_data->coarse_bat_volt;
p_outcoming_data->bat_status = p_page_data->bat_status;
p_outcoming_data->bitfield_reserved = 0;
page4_data_log( p_page_data);
}
void ant_bsc_page_4_decode(uint8_t const * p_page_buffer, ant_bsc_page4_data_t * p_page_data)
{
ant_bsc_page4_data_layout_t const * p_incoming_data = (ant_bsc_page4_data_layout_t *)p_page_buffer;
p_page_data->fract_bat_volt = p_incoming_data->fract_bat_volt;
p_page_data->coarse_bat_volt = p_incoming_data->coarse_bat_volt;
p_page_data->bat_status = p_incoming_data->bat_status;
page4_data_log( p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,113 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_4_H__
#define ANT_BSC_PAGE_4_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page4 BSC profile page 4
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BSC profile battery status.
*
* This enum represents possible battery status values for the ANT BSC profile.
*/
typedef enum
{
RESERVED0 = 0, ///< Reserved.
BSC_BAT_STATUS_NEW = 1, ///< Battery status: new.
BSC_BAT_STATUS_GOOD = 2, ///< Battery status: good.
BSC_BAT_STATUS_OK = 3, ///< Battery status: ok.
BSC_BAT_STATUS_LOW = 4, ///< Battery status: low.
BSC_BAT_STATUS_CRITICAL = 5, ///< Battery status: critical.
RESERVED1 = 6, ///< Reserved.
BSC_BAT_STATUS_INVALID = 7 ///< Invalid battery status.
} ant_bsc_bat_status_t;
/**@brief Data structure for BSC data page 4.
*
* This structure implements only page 4 specific data.
*/
typedef struct
{
uint8_t fract_bat_volt; ///< Fractional battery voltage.
uint8_t coarse_bat_volt : 4; ///< Coarse battery voltage.
uint8_t bat_status : 3; ///< Battery status.
} ant_bsc_page4_data_t;
/**@brief Initialize page 4.
*/
#define DEFAULT_ANT_BSC_PAGE4() \
(ant_bsc_page4_data_t) \
{ \
.fract_bat_volt = 0, \
.coarse_bat_volt = 0, \
.bat_status = BSC_BAT_STATUS_INVALID \
}
/**@brief Function for encoding page 4.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_4_encode(uint8_t * p_page_buffer, ant_bsc_page4_data_t const * p_page_data);
/**@brief Function for decoding page 4.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_4_decode(uint8_t const * p_page_buffer, ant_bsc_page4_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_4_H__
/** @} */

View file

@ -0,0 +1,97 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_BSC)
#include "ant_bsc_page_5.h"
#include "ant_bsc_utils.h"
#define NRF_LOG_MODULE_NAME ant_bcs_page_5
#if ANT_BSC_PAGE_5_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_BSC_PAGE_5_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_BSC_PAGE_5_INFO_COLOR
#else // ANT_BSC_PAGE_5_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_BSC_PAGE_5_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief BSC profile page 5 bitfields definitions. */
#define ANT_BSC_STOP_IND_MASK 0x01
/**@brief BSC page 5 data layout structure. */
typedef struct
{
uint8_t flags;
uint8_t reserved[6];
}ant_bsc_page5_data_layout_t;
/**@brief Function for printing speed or cadence page5 data. */
static void page5_data_log(ant_bsc_page5_data_t const * p_page_data)
{
if (p_page_data->stop_indicator)
{
NRF_LOG_INFO("Bicycle stopped.");
}
else
{
NRF_LOG_INFO("Bicycle moving.");
}
}
void ant_bsc_page_5_encode(uint8_t * p_page_buffer, ant_bsc_page5_data_t const * p_page_data)
{
ant_bsc_page5_data_layout_t * p_outcoming_data = (ant_bsc_page5_data_layout_t *)p_page_buffer;
p_outcoming_data->flags = (uint8_t)p_page_data->stop_indicator;
page5_data_log( p_page_data);
}
void ant_bsc_page_5_decode(uint8_t const * p_page_buffer, ant_bsc_page5_data_t * p_page_data)
{
ant_bsc_page5_data_layout_t const * p_incoming_data = (ant_bsc_page5_data_layout_t *)p_page_buffer;
p_page_data->stop_indicator = (p_incoming_data->flags) & ANT_BSC_STOP_IND_MASK;
page5_data_log( p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_BSC)

View file

@ -0,0 +1,95 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_PAGE_5_H__
#define ANT_BSC_PAGE_5_H__
/** @file
*
* @defgroup ant_sdk_profiles_bsc_page5 BSC profile page 5
* @{
* @ingroup ant_sdk_profiles_bsc_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for BSC data page 5.
*
* This structure implements only page 5 specific data.
*/
typedef struct
{
uint8_t stop_indicator:1; ///< Stop indication bit.
uint8_t reserved:7; ///< Reserved.
} ant_bsc_page5_data_t;
/**@brief Initialize page 5.
*/
#define DEFAULT_ANT_BSC_PAGE5() \
(ant_bsc_page5_data_t) \
{ \
.stop_indicator = 0, \
.reserved = 0, \
}
/**@brief Function for encoding page 5.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_bsc_page_5_encode(uint8_t * p_page_buffer, ant_bsc_page5_data_t const * p_page_data);
/**@brief Function for decoding page 5.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_bsc_page_5_decode(uint8_t const * p_page_buffer, ant_bsc_page5_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_PAGE_5_H__
/** @} */

View file

@ -0,0 +1,69 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __ANT_BSC_PAGES_H
#define __ANT_BSC_PAGES_H
/** @file
*
* @defgroup ant_sdk_profiles_bsc_pages Bicycle Speed and Cadence profile pages
* @{
* @ingroup ant_bsc
* @brief This module implements functions for the BSC data pages.
*/
#include "ant_bsc_page_0.h"
#include "ant_bsc_page_1.h"
#include "ant_bsc_page_2.h"
#include "ant_bsc_page_3.h"
#include "ant_bsc_page_4.h"
#include "ant_bsc_page_5.h"
#include "ant_bsc_combined_page_0.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // __ANT_BSC_PAGES_H
/** @} */

View file

@ -0,0 +1,280 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ant_bsc_simulator.h"
#include "ant_bsc_utils.h"
#include "app_util.h"
#define ITERATION_ANT_CYCLES(DEVICE_TYPE) \
(BSC_PERIOD_TICKS(DEVICE_TYPE, BSC_MSG_PERIOD_4Hz)) ///< period of calculation [1/32678 s], defined in ANT device profile
// use the same DEVICE TYPE as in profile definition
#define ITERATION_PERIOD(DEVICE_TYPE) \
((ITERATION_ANT_CYCLES(DEVICE_TYPE)) * 1024 / ANT_CLOCK_FREQUENCY) ///< integer part of calculation's period [1/1024 s]
#define ITERATION_FRACTION(DEVICE_TYPE) \
((ITERATION_ANT_CYCLES(DEVICE_TYPE)) * 1024 % ANT_CLOCK_FREQUENCY) ///< fractional part of calculation's period [1/32678 s]
#define SPEED_SIM_MIN_VAL 0u ///< speed simulation minimum value [m/s]
#define SPEED_SIM_MAX_VAL 16u ///< speed simulation maximum value [m/s]
#define SPEED_SIM_INCREMENT 1u ///< speed simulation value increment [m/s]
#define CADENCE_SIM_MIN_VAL 70u ///< cadence simulation minimum value [rpm]
#define CADENCE_SIM_MAX_VAL 120u ///< cadence simulation maximum value [rpm]
#define CADENCE_SIM_INCREMENT 1u ///< cadence simulation value increment [rpm]
#define WHEEL_CIRCUMFERENCE 1766u ///< bike wheel circumference [mm]
#define MM_TO_METERS(MM_VAL) ((MM_VAL) / 1000u)
#define TWO_SEC_TO_TICKS 2048 ///< number of [1/1024s] ticks in 2 sec period
#define CUMULATIVE_TIME_UNIT 2 ///< cumulative time unit
void ant_bsc_simulator_init(ant_bsc_simulator_t * p_simulator,
ant_bsc_simulator_cfg_t const * p_config,
bool auto_change)
{
p_simulator->p_profile = p_config->p_profile;
p_simulator->_cb.auto_change = auto_change;
p_simulator->_cb.speed_sim_val = SPEED_SIM_MIN_VAL;
p_simulator->_cb.cadence_sim_val = CADENCE_SIM_MIN_VAL;
p_simulator->_cb.time_since_last_s_evt = 0;
p_simulator->_cb.fraction_since_last_s_evt = 0;
p_simulator->_cb.time_since_last_c_evt = 0;
p_simulator->_cb.fraction_since_last_c_evt = 0;
p_simulator->_cb.device_type = p_config->device_type;
p_simulator->_cb.sensorsim_s_cfg.min = SPEED_SIM_MIN_VAL;
p_simulator->_cb.sensorsim_s_cfg.max = SPEED_SIM_MAX_VAL;
p_simulator->_cb.sensorsim_s_cfg.incr = SPEED_SIM_INCREMENT;
p_simulator->_cb.sensorsim_s_cfg.start_at_max = false;
sensorsim_init(&(p_simulator->_cb.sensorsim_s_state),
&(p_simulator->_cb.sensorsim_s_cfg));
p_simulator->_cb.sensorsim_c_cfg.min = CADENCE_SIM_MIN_VAL;
p_simulator->_cb.sensorsim_c_cfg.max = CADENCE_SIM_MAX_VAL;
p_simulator->_cb.sensorsim_c_cfg.incr = CADENCE_SIM_INCREMENT;
p_simulator->_cb.sensorsim_c_cfg.start_at_max = false;
p_simulator->_cb.stop_cnt = 0;
sensorsim_init(&(p_simulator->_cb.sensorsim_c_state),
&(p_simulator->_cb.sensorsim_c_cfg));
}
void ant_bsc_simulator_one_iteration(ant_bsc_simulator_t * p_simulator)
{
// Set constant battery voltage
p_simulator->p_profile->BSC_PROFILE_coarse_bat_volt = 2;
p_simulator->p_profile->BSC_PROFILE_fract_bat_volt = 200;
p_simulator->p_profile->BSC_PROFILE_bat_status = BSC_BAT_STATUS_GOOD;
// Calculate speed and cadence values
if (p_simulator->_cb.auto_change)
{
p_simulator->_cb.speed_sim_val = sensorsim_measure(&(p_simulator->_cb.sensorsim_s_state),
&(p_simulator->_cb.sensorsim_s_cfg));
p_simulator->_cb.cadence_sim_val = sensorsim_measure(&(p_simulator->_cb.sensorsim_c_state),
&(p_simulator->_cb.sensorsim_c_cfg));
}
else
{
p_simulator->_cb.speed_sim_val = p_simulator->_cb.sensorsim_s_state.current_val;
p_simulator->_cb.cadence_sim_val = p_simulator->_cb.sensorsim_c_state.current_val;
}
// Simulate bicycle stopped for around 10s and go for around 5s only in auto-simulation
if (p_simulator->_cb.auto_change)
{
if ((p_simulator->p_profile->_cb.p_sens_cb->main_page_number == ANT_BSC_PAGE_5) &&
(p_simulator->_cb.stop_cnt++ < 40))
{
p_simulator->_cb.speed_sim_val = 0;
p_simulator->_cb.cadence_sim_val = 0;
}
else
{
if (p_simulator->_cb.stop_cnt == 60)
{
p_simulator->_cb.stop_cnt = 0;
}
}
}
if (p_simulator->_cb.speed_sim_val == 0)
{
p_simulator->p_profile->BSC_PROFILE_stop_indicator = 1;
}
else
{
p_simulator->p_profile->BSC_PROFILE_stop_indicator = 0;
}
// @note: Take a local copy within scope in order to assist the compiler in variable register
// allocation.
const uint32_t computed_speed = p_simulator->_cb.speed_sim_val;
const uint32_t computed_cadence = p_simulator->_cb.cadence_sim_val;
// @note: This implementation assumes that the current instantaneous speed/cadence can vary and this
// function is called with static frequency.
// value and the speed/cadence pulse interval is derived from it. The computation is based on 60
// seconds in a minute and the used time base is 1/1024 seconds.
const uint32_t current_speed_pulse_interval =
MM_TO_METERS((WHEEL_CIRCUMFERENCE * 1024u) / computed_speed);
const uint32_t current_cadence_pulse_interval = (60u * 1024u) / computed_cadence;
//update time from last evt detected
p_simulator->_cb.time_since_last_s_evt += ITERATION_PERIOD(p_simulator->_cb.device_type);
p_simulator->_cb.time_since_last_c_evt += ITERATION_PERIOD(p_simulator->_cb.device_type);
// extended calculation by fraction make calculating accurate in long time perspective
p_simulator->_cb.fraction_since_last_s_evt += ITERATION_FRACTION(p_simulator->_cb.device_type);
p_simulator->_cb.fraction_since_last_c_evt += ITERATION_FRACTION(p_simulator->_cb.device_type);
uint32_t add_period = p_simulator->_cb.fraction_since_last_s_evt / ANT_CLOCK_FREQUENCY;
if (add_period > 0)
{
p_simulator->_cb.time_since_last_s_evt++;
p_simulator->_cb.fraction_since_last_s_evt %= ANT_CLOCK_FREQUENCY;
}
add_period = p_simulator->_cb.fraction_since_last_c_evt / ANT_CLOCK_FREQUENCY;
if (add_period > 0)
{
p_simulator->_cb.time_since_last_c_evt++;
p_simulator->_cb.fraction_since_last_c_evt %= ANT_CLOCK_FREQUENCY;
}
// Calculate cumulative time based on time since last event (from profile data) in [1/1024] ticks
int16_t diff = p_simulator->p_profile->BSC_PROFILE_event_time -
p_simulator->_cb.prev_time_since_evt;
p_simulator->_cb.prev_time_since_evt = p_simulator->p_profile->BSC_PROFILE_event_time;
if (diff >= 0) // Check for time count overflow
{
// No overflow
p_simulator->_cb.cumulative_time += diff / TWO_SEC_TO_TICKS;
p_simulator->_cb.cumulative_time_frac += diff % TWO_SEC_TO_TICKS;
}
else
{
p_simulator->_cb.cumulative_time += (UINT16_MAX + diff) / TWO_SEC_TO_TICKS;
p_simulator->_cb.cumulative_time_frac += (UINT16_MAX + diff) % TWO_SEC_TO_TICKS;
}
// Check fraction
if ((p_simulator->_cb.cumulative_time_frac / TWO_SEC_TO_TICKS) > 0)
{
p_simulator->_cb.cumulative_time += p_simulator->_cb.cumulative_time_frac / TWO_SEC_TO_TICKS;
p_simulator->_cb.cumulative_time_frac %= TWO_SEC_TO_TICKS;
}
// Update page data if necessary
if (p_simulator->_cb.cumulative_time != p_simulator->p_profile->BSC_PROFILE_operating_time)
{
p_simulator->p_profile->BSC_PROFILE_operating_time = p_simulator->_cb.cumulative_time;
}
//calc number of events as will fill
uint32_t new_s_events = p_simulator->_cb.time_since_last_s_evt /
current_speed_pulse_interval;
uint32_t add_speed_event_time = new_s_events * current_speed_pulse_interval;
if ((new_s_events > 0) && ((p_simulator->_cb.device_type == BSC_SPEED_DEVICE_TYPE) ||
(p_simulator->_cb.device_type == BSC_COMBINED_DEVICE_TYPE)))
{
p_simulator->p_profile->BSC_PROFILE_rev_count += new_s_events;
p_simulator->p_profile->BSC_PROFILE_speed_rev_count += new_s_events;
// Current speed event time is the previous event time plus the current speed
// pulse interval.
uint32_t current_speed_event_time = p_simulator->p_profile->BSC_PROFILE_event_time +
add_speed_event_time;
// Set current event time.
p_simulator->p_profile->BSC_PROFILE_event_time = current_speed_event_time; // <- B<4,5> <-
current_speed_event_time = p_simulator->p_profile->BSC_PROFILE_speed_event_time +
add_speed_event_time;
// Set current event time for combined device.
p_simulator->p_profile->BSC_PROFILE_speed_event_time = current_speed_event_time;
p_simulator->_cb.time_since_last_s_evt -= add_speed_event_time;
}
uint32_t new_c_events = p_simulator->_cb.time_since_last_c_evt /
current_cadence_pulse_interval;
uint32_t add_cadence_event_time = new_c_events * current_cadence_pulse_interval;
if ((new_c_events > 0) && ((p_simulator->_cb.device_type == BSC_CADENCE_DEVICE_TYPE) ||
(p_simulator->_cb.device_type == BSC_COMBINED_DEVICE_TYPE)))
{
p_simulator->p_profile->BSC_PROFILE_rev_count += new_c_events;
p_simulator->p_profile->BSC_PROFILE_cadence_rev_count += new_c_events;
// Current speed event time is the previous event time plus the current speed
// pulse interval.
uint32_t current_cadence_event_time = p_simulator->p_profile->BSC_PROFILE_event_time +
add_cadence_event_time;
// Set current event time.
p_simulator->p_profile->BSC_PROFILE_event_time = current_cadence_event_time; //<- B<4,5> <-
current_cadence_event_time = p_simulator->p_profile->BSC_PROFILE_cadence_event_time +
add_cadence_event_time;
// Set current event time for combined device.
p_simulator->p_profile->BSC_PROFILE_cadence_event_time = current_cadence_event_time;
p_simulator->_cb.time_since_last_c_evt -= add_cadence_event_time;
}
}
void ant_bsc_simulator_increment(ant_bsc_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
// Speed
sensorsim_increment(&(p_simulator->_cb.sensorsim_s_state),
&(p_simulator->_cb.sensorsim_s_cfg));
// Cadence
sensorsim_increment(&(p_simulator->_cb.sensorsim_c_state),
&(p_simulator->_cb.sensorsim_c_cfg));
}
}
void ant_bsc_simulator_decrement(ant_bsc_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
// Speed
sensorsim_decrement(&(p_simulator->_cb.sensorsim_s_state),
&(p_simulator->_cb.sensorsim_s_cfg));
// Cadence
sensorsim_decrement(&(p_simulator->_cb.sensorsim_c_state),
&(p_simulator->_cb.sensorsim_c_cfg));
}
}

View file

@ -0,0 +1,120 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_SIMULATOR_H__
#define ANT_BSC_SIMULATOR_H__
/** @file
*
* @defgroup ant_sdk_bsc_simulator ANT BSC simulator
* @{
* @ingroup ant_sdk_simulators
* @brief ANT BSC simulator module.
*
* @details This module simulates a pulse for the ANT Bicycle Speed and Cadence profile. The module
* calculates abstract values, which are handled by the BSC pages data model to ensure that
* they are compatible. It provides a handler for changing the cadence and speed values manually
* as well as functionality to change the values automatically.
*
*/
#include <stdint.h>
#include <stdbool.h>
#include "ant_bsc.h"
#include "ant_bsc_utils.h"
#include "sensorsim.h"
#include "ant_bsc_simulator_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BSC simulator configuration structure. */
typedef struct
{
ant_bsc_profile_t * p_profile; ///< Related profile.
uint8_t device_type; ///< BSC device type (must be consistent with the type chosen for the profile). Supported types:
// @ref BSC_SPEED_DEVICE_TYPE, @ref BSC_CADENCE_DEVICE_TYPE, @ref BSC_COMBINED_DEVICE_TYPE.
} ant_bsc_simulator_cfg_t;
/**@brief BSC simulator structure. */
typedef struct
{
ant_bsc_profile_t * p_profile; ///< Related profile.
ant_bsc_simulator_cb_t _cb; ///< Internal control block.
} ant_bsc_simulator_t;
/**@brief Function for initializing the ANT BSC simulator instance.
*
* @param[in] p_simulator Pointer to the simulator instance.
* @param[in] p_config Pointer to the simulator configuration structure.
* @param[in] auto_change Enable or disable automatic changes of speed or cadence.
*/
void ant_bsc_simulator_init(ant_bsc_simulator_t * p_simulator,
ant_bsc_simulator_cfg_t const * p_config,
bool auto_change);
/**@brief Function for simulating a device event.
*
* @details Based on this event, the transmitter data is simulated.
*
* This function should be called in the BSC Sensor event handler.
*/
void ant_bsc_simulator_one_iteration(ant_bsc_simulator_t * p_simulator);
/**@brief Function for incrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_bsc_simulator_increment(ant_bsc_simulator_t * p_simulator);
/**@brief Function for decrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_bsc_simulator_decrement(ant_bsc_simulator_t * p_simulator);
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_SIMULATOR_H__
/** @} */

View file

@ -0,0 +1,79 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_SIMULATOR_LOCAL_H__
#define ANT_BSC_SIMULATOR_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_bsc.h"
#include "sensorsim.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief BSC simulator control block structure. */
typedef struct
{
uint8_t device_type;
bool auto_change; ///< Cadence will change automatically (if auto_change is set) or manually.
uint16_t speed_sim_val; ///< Instantaneous speed value.
uint16_t cadence_sim_val; ///< Instantaneous cadence value.
uint32_t time_since_last_s_evt; ///< Time since last speed event occurred (integer part).
uint64_t fraction_since_last_s_evt; ///< Time since last speed event occurred (fractional part).
uint32_t time_since_last_c_evt; ///< Time since last cadence event occurred (integer part).
uint64_t fraction_since_last_c_evt; ///< Time since last cadence event occurred (fractional part).
sensorsim_state_t sensorsim_s_state; ///< State of the simulated speed sensor.
sensorsim_cfg_t sensorsim_s_cfg; ///< Configuration of the simulated speed sensor.
sensorsim_state_t sensorsim_c_state; ///< State of the simulated cadence sensor.
sensorsim_cfg_t sensorsim_c_cfg; ///< Configuration of the simulated cadence sensor.
uint16_t prev_time_since_evt; ///< Previous value of time since the last event.
uint32_t cumulative_time; ///< Cumulative time in 2 s ticks used for updating the cumulative time.
uint32_t cumulative_time_frac; ///< Cumulative time in 2 s ticks (fractional part), used for updating the cumulative time.
uint8_t stop_cnt; ///< Counter used for simulating bicycle stopped state.
} ant_bsc_simulator_cb_t;
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_SIMULATOR_LOCAL_H__

View file

@ -0,0 +1,128 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_BSC_UTILS_H__
#define ANT_BSC_UTILS_H__
#include "nrf.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @file
*
* @defgroup ant_sdk_profiles_bsc_utils Bicycle Speed and Cadence profile utilities
* @{
* @ingroup ant_bsc
* @brief This module implements utilities for the Bicycle Speed and Cadence profile.
*
*/
/**@brief Unit for BSC operating time.
*
* @details According to the ANT BSC specification, the operating time unit is 2 seconds.
*/
#define ANT_BSC_OPERATING_TIME_UNIT 2u
/**@brief This macro should be used to get the seconds part of the operating time.
*/
#define ANT_BSC_OPERATING_SECONDS(OPERATING_TIME) (((OPERATING_TIME) * ANT_BSC_OPERATING_TIME_UNIT) % 60)
/**@brief This macro should be used to get the minutes part of the operating time.
*/
#define ANT_BSC_OPERATING_MINUTES(OPERATING_TIME) ((((OPERATING_TIME) * ANT_BSC_OPERATING_TIME_UNIT) / 60) % 60)
/**@brief This macro should be used to get the hours part of the operating time.
*/
#define ANT_BSC_OPERATING_HOURS(OPERATING_TIME) ((((OPERATING_TIME) * ANT_BSC_OPERATING_TIME_UNIT) / (60 * 60)) % 24)
/**@brief This macro should be used to get the days part of the operating time.
*/
#define ANT_BSC_OPERATING_DAYS(OPERATING_TIME) ((((OPERATING_TIME) * ANT_BSC_OPERATING_TIME_UNIT) / (60 * 60)) / 24)
/**@brief Number of Bicycle Speed or Cadence event time counts per second.
*
* @details According to the ANT BSC specification, the speed or cadence event time unit is 1/1024 of a second.
*/
#define ANT_BSC_EVENT_TIME_COUNTS_PER_SEC 1024u
/**@brief BSC event time display required precision.
*
* @details This value is used to decode the number of milliseconds.
*/
#define ANT_BSC_EVENT_TIME_PRECISION 1000u
/**@brief This macro should be used to get the seconds part of the BSC event time.
*/
#define ANT_BSC_EVENT_TIME_SEC(EVENT_TIME) ((EVENT_TIME) / ANT_BSC_EVENT_TIME_COUNTS_PER_SEC)
/**@brief This macro should be used to get the milliseconds part of the BSC event time.
*/
#define ANT_BSC_EVENT_TIME_MSEC(EVENT_TIME) (((((EVENT_TIME) % ANT_BSC_EVENT_TIME_COUNTS_PER_SEC) * ANT_BSC_EVENT_TIME_PRECISION) \
+ ANT_BSC_EVENT_TIME_COUNTS_PER_SEC / 2) \
/ ANT_BSC_EVENT_TIME_COUNTS_PER_SEC)
/**@brief Battery voltage display required precision.
*
* @details This value is used to decode the number of mV.
*/
#define ANT_BSC_BAT_VOLTAGE_PRECISION 1000u
/**@brief Bike Speed and Cadence profile, unit divisor of the fractional part of the battery voltage.
*
* @details According to the ANT BSC specification, the battery voltage fraction unit is (1/256) V.
*/
#define ANT_BSC_BAT_VOLTAGE_FRACTION_PER_VOLT 256u
/**@brief This macro should be used to get the mV part of the BSC battery voltage.
*/
#define ANT_BSC_BAT_VOLTAGE_FRACTION_MV(VOLT_FRACT) ((((VOLT_FRACT) * ANT_BSC_BAT_VOLTAGE_PRECISION) \
+ ANT_BSC_BAT_VOLTAGE_FRACTION_PER_VOLT / 2) \
/ ANT_BSC_BAT_VOLTAGE_FRACTION_PER_VOLT)
/** @} */
#ifdef __cplusplus
}
#endif
#endif // ANT_BSC_UTILS_H__

View file

@ -0,0 +1,224 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_REQUEST_CONTROLLER)
#include "ant_request_controller.h"
#include "ant_interface.h"
#include "ant_parameters.h"
#include "app_error.h"
#include "nrf_assert.h"
#include "nrf.h"
/**@brief Common message data layout structure. */
typedef struct
{
uint8_t page_number; ///< Page number.
uint8_t page_payload[7]; ///< Page payload.
}ant_common_message_layout_t;
void ant_request_controller_init(ant_request_controller_t * p_controller)
{
ASSERT(p_controller != NULL);
p_controller->state = ANT_REQUEST_CONTROLLER_IDLE;
p_controller->page_70 = DEFAULT_ANT_COMMON_PAGE70();
}
uint32_t ant_request_controller_request(ant_request_controller_t * p_controller,
uint8_t channel_number,
ant_common_page70_data_t * p_page_70)
{
ASSERT(p_controller != NULL);
ASSERT(p_page_70 != NULL);
ant_common_message_layout_t message;
message.page_number = ANT_COMMON_PAGE_70;
ant_common_page_70_encode(message.page_payload, p_page_70);
p_controller->state = ANT_REQUEST_CONTROLLER_SENDED;
return sd_ant_acknowledge_message_tx(channel_number, sizeof (message), (uint8_t *)&message);
}
bool ant_request_controller_pending_get(ant_request_controller_t * p_controller,
uint8_t * p_page_number)
{
ASSERT(p_controller != NULL);
ASSERT(p_page_number != NULL);
if ((p_controller->state == ANT_REQUEST_CONTROLLER_ACK_UNTIL_SUCCESS_REQUESTED)
|| (p_controller->state == ANT_REQUEST_CONTROLLER_ACK_REQUESTED)
|| (p_controller->state == ANT_REQUEST_CONTROLLER_BROADCAST_REQUESTED))
{
*p_page_number = p_controller->page_70.page_number;
return true;
}
return false;
}
bool ant_request_controller_ack_needed(ant_request_controller_t * p_controller)
{
ASSERT(p_controller != NULL);
return ((p_controller->state == ANT_REQUEST_CONTROLLER_ACK_UNTIL_SUCCESS_REQUESTED)
|| (p_controller->state == ANT_REQUEST_CONTROLLER_ACK_REQUESTED));
}
ant_request_controller_evt_t ant_request_controller_disp_evt_handler(
ant_request_controller_t * p_controller,
ant_evt_t * p_ant_evt)
{
ASSERT(p_controller != NULL);
ASSERT(p_ant_evt != NULL);
if ( p_controller->state == ANT_REQUEST_CONTROLLER_SENDED)
{
switch (p_ant_evt->event)
{
case EVENT_TRANSFER_TX_FAILED:
p_controller->state = ANT_REQUEST_CONTROLLER_IDLE;
return ANT_REQUEST_CONTROLLER_FAILED;
case EVENT_TRANSFER_TX_COMPLETED:
p_controller->state = ANT_REQUEST_CONTROLLER_IDLE;
return ANT_REQUEST_CONTROLLER_SUCCESS;
default:
break;
}
}
return ANT_REQUEST_CONTROLLER_NONE;
}
/**@brief Function for confirmation of page sending.
*
* @param[in] p_controller Pointer to the controller instance.
*/
__STATIC_INLINE void page_sended(ant_request_controller_t * p_controller)
{
if (!((p_controller->page_70.transmission_response.items.transmit_count)--))
{
p_controller->state = ANT_REQUEST_CONTROLLER_IDLE;
}
}
/**@brief Function for handling page request.
*
* @param[in] p_controller Pointer to the controller instance.
* @param[in] p_message_payload Pointer to the message payload.
*/
__STATIC_INLINE void page_requested(ant_request_controller_t * p_controller,
ant_common_message_layout_t * p_message_payload)
{
ant_common_page_70_decode(p_message_payload->page_payload, &(p_controller->page_70));
if ((p_controller->page_70.command_type == ANT_PAGE70_COMMAND_PAGE_DATA_REQUEST)
&& (p_controller->page_70.transmission_response.specyfic != ANT_PAGE70_RESPONSE_INVALID))
{
if (p_controller->page_70.transmission_response.items.ack_resposne)
{
if (p_controller->page_70.transmission_response.specyfic ==
ANT_PAGE70_RESPONSE_TRANSMIT_UNTIL_SUCCESS)
{
p_controller->state = ANT_REQUEST_CONTROLLER_ACK_UNTIL_SUCCESS_REQUESTED;
}
else
{
p_controller->state = ANT_REQUEST_CONTROLLER_ACK_REQUESTED;
}
}
else
{
p_controller->state = ANT_REQUEST_CONTROLLER_BROADCAST_REQUESTED;
}
}
}
void ant_request_controller_sens_evt_handler(ant_request_controller_t * p_controller,
ant_evt_t * p_ant_evt)
{
ASSERT(p_controller != NULL);
ASSERT(p_ant_evt != NULL);
ant_common_message_layout_t * p_message_payload =
(ant_common_message_layout_t *)p_ant_evt->message.ANT_MESSAGE_aucPayload;
switch (p_ant_evt->event)
{
case EVENT_RX:
if (p_message_payload->page_number == ANT_COMMON_PAGE_70)
{
page_requested(p_controller, p_message_payload);
}
break;
case EVENT_TRANSFER_TX_COMPLETED:
if (p_controller->state == ANT_REQUEST_CONTROLLER_ACK_UNTIL_SUCCESS_REQUESTED)
{
p_controller->state = ANT_REQUEST_CONTROLLER_IDLE;
}
/* fall through */
case EVENT_TX:
if (p_controller->state == ANT_REQUEST_CONTROLLER_BROADCAST_REQUESTED
|| p_controller->state == ANT_REQUEST_CONTROLLER_ACK_REQUESTED)
{
page_sended(p_controller);
}
break;
default:
break;
}
}
#endif // NRF_MODULE_ENABLED(ANT_REQUEST_CONTROLLER)

View file

@ -0,0 +1,157 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ant_request_controller ANT request controller
* @{
* @ingroup ant_sdk_utils
*
* @brief Module for handling page requests related to page 70.
*/
#ifndef ANT_REQUEST_CONTROLLER_H__
#define ANT_REQUEST_CONTROLLER_H__
#include <stdbool.h>
#include "ant_common_page_70.h"
#include "nrf_sdh_ant.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Request controller events types. */
typedef enum
{
ANT_REQUEST_CONTROLLER_NONE, ///< No event.
ANT_REQUEST_CONTROLLER_SUCCESS, ///< Page request successful.
ANT_REQUEST_CONTROLLER_FAILED, ///< Page request failed.
} ant_request_controller_evt_t;
/**@brief Request controller states. */
typedef enum
{
ANT_REQUEST_CONTROLLER_IDLE, ///< Module is in idle state.
ANT_REQUEST_CONTROLLER_SENDED, ///< Module waits for acknowledgment of its request.
ANT_REQUEST_CONTROLLER_BROADCAST_REQUESTED, ///< Module is requested to send page n times using broadcast.
ANT_REQUEST_CONTROLLER_ACK_REQUESTED, ///< Module is requested to send page n times using acknowledgment.
ANT_REQUEST_CONTROLLER_ACK_UNTIL_SUCCESS_REQUESTED, ///< Module is requested to send page until success using acknowledgment.
} ant_request_controller_state_t;
/**@brief ANT request controller structure. */
typedef struct
{
ant_request_controller_state_t state; ///< Actual module state.
ant_common_page70_data_t page_70; ///< Page 70.
} ant_request_controller_t;
/**@brief Function for initializing the ANT request controller instance.
*
* @param[in] p_controller Pointer to the controller instance.
*/
void ant_request_controller_init(ant_request_controller_t * p_controller);
/**@brief Function for sending a request.
*
* @param[in] p_controller Pointer to the controller instance.
* @param[in] channel_number Channel number.
* @param[in] p_page_70 Pointer to the prepared page 70.
*
* @return Error code returned by @ref sd_ant_acknowledge_message_tx().
*/
uint32_t ant_request_controller_request(ant_request_controller_t * p_controller,
uint8_t channel_number,
ant_common_page70_data_t * p_page_70);
/**@brief Function for getting pending page number.
*
* @details This function checks whether a page number was requested.
*
* @param[in] p_controller Pointer to the controller instance.
* @param[out] p_page_number Pending page number (valid if true was returned).
*
* @retval TRUE If there was a pending page.
* @retval FALSE If no page was pending.
*/
bool ant_request_controller_pending_get(ant_request_controller_t * p_controller,
uint8_t * p_page_number);
/**@brief Function for checking whether the next page must be sent with acknowledgment.
*
* @param[in] p_controller Pointer to the controller instance.
*
* @retval TRUE If the next transmission needs acknowledgment.
* @retval FALSE If the next transmission does not need acknowledgment.
*/
bool ant_request_controller_ack_needed(ant_request_controller_t * p_controller);
/**
* @brief Function for handling ANT events on display side.
*
* @details All events from the ANT stack that are related to the appropriate channel number
* should be propagated.
*
* @param[in] p_controller Pointer to the controller instance.
* @param[in] p_ant_evt Event received from the ANT stack.
*/
ant_request_controller_evt_t ant_request_controller_disp_evt_handler(
ant_request_controller_t * p_controller,
ant_evt_t * p_ant_evt);
/**
* @brief Function for handling ANT events on sensor side.
*
* @details All events from the ANT stack that are related to the appropriate channel number
* should be propagated.
*
* @param[in] p_controller Pointer to the controller instance.
* @param[in] p_ant_evt Event received from the ANT stack.
* @retval TRUE If there was a pending page.
*/
void ant_request_controller_sens_evt_handler(ant_request_controller_t * p_controller,
ant_evt_t * p_ant_evt);
#ifdef __cplusplus
}
#endif
#endif // ANT_REQUEST_CONTROLLER_H__
/** @} */

View file

@ -0,0 +1,141 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_COMMON_PAGE_70)
#include <string.h>
#include "ant_common_page_70.h"
#define NRF_LOG_MODULE_NAME ant_common_page_70
#if ANT_COMMON_PAGE_70_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_COMMON_PAGE_70_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_COMMON_PAGE_70_INFO_COLOR
#else // ANT_COMMON_PAGE_70_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_COMMON_PAGE_70_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief ANT+ common page 70 data layout structure. */
typedef struct
{
uint8_t reserved[2];
uint8_t descriptor[2];
uint8_t req_trans_response;
uint8_t req_page_number;
uint8_t command_type;
}ant_common_page70_data_layout_t;
/**@brief Function for tracing page 70 data.
*
* @param[in] p_page_data Pointer to the page 70 data.
*/
static void page70_data_log(volatile ant_common_page70_data_t const * p_page_data)
{
NRF_LOG_INFO("Page %d request", p_page_data->page_number);
switch (p_page_data->transmission_response.specyfic)
{
case ANT_PAGE70_RESPONSE_TRANSMIT_UNTIL_SUCCESS:
NRF_LOG_INFO("Try to send until ACK");
break;
case ANT_PAGE70_RESPONSE_INVALID:
NRF_LOG_INFO("Invalid requested transmission response");
break;
default:
if (p_page_data->transmission_response.items.ack_resposne)
{
NRF_LOG_INFO("Answer with acknowledged messages");
}
NRF_LOG_INFO("Requested number of transmissions: %d",
p_page_data->transmission_response.items.transmit_count);
}
switch (p_page_data->command_type)
{
case ANT_PAGE70_COMMAND_PAGE_DATA_REQUEST:
NRF_LOG_INFO("Request Data Page");
break;
case ANT_PAGE70_COMMAND_ANT_FS_SESSION_REQUEST:
NRF_LOG_INFO("Request ANT-FS Session");
break;
default:
NRF_LOG_INFO("Invalid request");
}
NRF_LOG_INFO("Descriptor %x\r\n\n", p_page_data->descriptor);
}
void ant_common_page_70_encode(uint8_t * p_page_buffer,
volatile ant_common_page70_data_t const * p_page_data)
{
ant_common_page70_data_layout_t * p_outcoming_data =
(ant_common_page70_data_layout_t *)p_page_buffer;
memset(p_outcoming_data->reserved, UINT8_MAX, sizeof (p_outcoming_data->reserved));
UNUSED_PARAMETER(uint16_encode(p_page_data->descriptor, p_outcoming_data->descriptor));
p_outcoming_data->req_trans_response = p_page_data->transmission_response.byte;
p_outcoming_data->req_page_number = p_page_data->page_number;
p_outcoming_data->command_type = p_page_data->command_type;
page70_data_log(p_page_data);
}
void ant_common_page_70_decode(uint8_t const * p_page_buffer,
volatile ant_common_page70_data_t * p_page_data)
{
ant_common_page70_data_layout_t const * p_incoming_data =
(ant_common_page70_data_layout_t *)p_page_buffer;
p_page_data->descriptor = uint16_decode(p_incoming_data->descriptor);
p_page_data->transmission_response.byte = p_incoming_data->req_trans_response;
p_page_data->page_number = p_incoming_data->req_page_number;
p_page_data->command_type = (ant_page70_command_t)p_incoming_data->command_type;
page70_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_COMMON_PAGE_70)

View file

@ -0,0 +1,135 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_COMMON_PAGE_70_H__
#define ANT_COMMON_PAGE_70_H__
/** @file
*
* @defgroup ant_common_page_70 ANT+ common page 70
* @{
* @ingroup ant_sdk_common_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ANT_COMMON_PAGE_70 (70) ///< @brief ID value of common page 70.
#define ANT_PAGE70_INVALID_DESCRIPTOR UINT16_MAX ///< Invalid descriptor.
/**@brief Command type.
*/
typedef enum
{
ANT_PAGE70_COMMAND_PAGE_DATA_REQUEST = 0x01, ///< Page request.
ANT_PAGE70_COMMAND_ANT_FS_SESSION_REQUEST = 0x02, ///< ANT FS session request.
} ant_page70_command_t;
/**@brief Data structure for ANT+ common data page 70.
*/
typedef struct
{
uint8_t page_number; ///< Requested page number.
uint16_t descriptor; ///< Descriptor.
ant_page70_command_t command_type; ///< Command type.
union
{
enum
{
ANT_PAGE70_RESPONSE_INVALID = 0x00, ///< Invalid response type.
ANT_PAGE70_RESPONSE_TRANSMIT_UNTIL_SUCCESS = 0x80, ///< Transmit until a successful acknowledge is received.
} specyfic;
struct
{
uint8_t transmit_count :7; ///< Number of re-transmissions.
uint8_t ack_resposne :1; ///< Acknowledge transmission is required.
} items;
uint8_t byte;
} transmission_response;
} ant_common_page70_data_t;
/**@brief Initialize page 70 with default values.
*/
#define DEFAULT_ANT_COMMON_PAGE70() \
(ant_common_page70_data_t) \
{ \
.page_number = 0x00, \
.command_type = (ant_page70_command_t)0x00, \
.transmission_response.specyfic = ANT_PAGE70_RESPONSE_INVALID, \
.descriptor = ANT_PAGE70_INVALID_DESCRIPTOR, \
}
/**@brief Initialize page 70 with the page request.
*/
#define ANT_COMMON_PAGE_DATA_REQUEST(PAGE_NUMBER) \
(ant_common_page70_data_t) \
{ \
.page_number = (PAGE_NUMBER), \
.command_type = ANT_PAGE70_COMMAND_PAGE_DATA_REQUEST, \
.transmission_response.specyfic = ANT_PAGE70_RESPONSE_TRANSMIT_UNTIL_SUCCESS, \
.descriptor = ANT_PAGE70_INVALID_DESCRIPTOR, \
}
/**@brief Function for encoding page 70.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_common_page_70_encode(uint8_t * p_page_buffer,
volatile ant_common_page70_data_t const * p_page_data);
/**@brief Function for decoding page 70.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_common_page_70_decode(uint8_t const * p_page_buffer,
volatile ant_common_page70_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_COMMON_PAGE_70_H__
/** @} */

View file

@ -0,0 +1,110 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_COMMON_PAGE_80)
#include <string.h>
#include "ant_common_page_80.h"
#define NRF_LOG_MODULE_NAME ant_common_page_80
#if ANT_COMMON_PAGE_80_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_COMMON_PAGE_80_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_COMMON_PAGE_80_INFO_COLOR
#else // ANT_COMMON_PAGE_80_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_COMMON_PAGE_80_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief ant+ common page 80 data layout structure. */
typedef struct
{
uint8_t reserved[2]; ///< unused, fill by 0xFF
uint8_t hw_revision;
uint8_t manufacturer_id[2];
uint8_t model_number[2];
}ant_common_page80_data_layout_t;
/**@brief Function for tracing page 80 data.
*
* @param[in] p_page_data Pointer to the page 80 data.
*/
static void page80_data_log(volatile ant_common_page80_data_t const * p_page_data)
{
NRF_LOG_INFO("hw revision: %u", p_page_data->hw_revision);
NRF_LOG_INFO("manufacturer id: %u", p_page_data->manufacturer_id);
NRF_LOG_INFO("model number: %u\r\n\n", p_page_data->model_number);
}
void ant_common_page_80_encode(uint8_t * p_page_buffer,
volatile ant_common_page80_data_t const * p_page_data)
{
ant_common_page80_data_layout_t * p_outcoming_data =
(ant_common_page80_data_layout_t *)p_page_buffer;
memset(p_page_buffer, UINT8_MAX, sizeof (p_outcoming_data->reserved));
p_outcoming_data->hw_revision = p_page_data->hw_revision;
UNUSED_PARAMETER(uint16_encode(p_page_data->manufacturer_id,
p_outcoming_data->manufacturer_id));
UNUSED_PARAMETER(uint16_encode(p_page_data->model_number, p_outcoming_data->model_number));
page80_data_log(p_page_data);
}
void ant_common_page_80_decode(uint8_t const * p_page_buffer,
volatile ant_common_page80_data_t * p_page_data)
{
ant_common_page80_data_layout_t const * p_incoming_data =
(ant_common_page80_data_layout_t *)p_page_buffer;
p_page_data->hw_revision = p_incoming_data->hw_revision;
p_page_data->manufacturer_id = uint16_decode(p_incoming_data->manufacturer_id);
p_page_data->model_number = uint16_decode(p_incoming_data->model_number);
page80_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_COMMON_PAGE_80)

View file

@ -0,0 +1,120 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_COMMON_PAGE_80_H__
#define ANT_COMMON_PAGE_80_H__
/** @file
*
* @defgroup ant_sdk_common_pages ANT+ common pages
* @{
* @ingroup ant_sdk_profiles
* @brief This module implements functions for the ANT+ common pages.
* @details ANT+ common data pages define common data formats that can be used by any device on any ANT network. The ability to send and receive these common pages is defined by the transmission type of the ANT channel parameter.
*
* Note that all unused pages in this section are not defined and therefore cannot be used.
* @}
*
* @defgroup ant_common_page_80 ANT+ common page 80
* @{
* @ingroup ant_sdk_common_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ANT_COMMON_PAGE_80 (80) ///< @brief ID value of common page 80.
/**@brief Data structure for ANT+ common data page 80.
*
* @note This structure implements only page 80 specific data.
*/
typedef struct
{
uint8_t hw_revision; ///< Hardware revision.
uint16_t manufacturer_id; ///< Manufacturer ID.
uint16_t model_number; ///< Model number.
} ant_common_page80_data_t;
/**@brief Initialize page 80.
*/
#define DEFAULT_ANT_COMMON_page80() \
(ant_common_page80_data_t) \
{ \
.hw_revision = 0x00, \
.manufacturer_id = UINT8_MAX, \
.model_number = 0x00, \
}
/**@brief Initialize page 80.
*/
#define ANT_COMMON_page80(hw_rev, man_id, mod_num) \
(ant_common_page80_data_t) \
{ \
.hw_revision = (hw_rev), \
.manufacturer_id = (man_id), \
.model_number = (mod_num), \
}
/**@brief Function for encoding page 80.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_common_page_80_encode(uint8_t * p_page_buffer,
volatile ant_common_page80_data_t const * p_page_data);
/**@brief Function for decoding page 80.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_common_page_80_decode(uint8_t const * p_page_buffer,
volatile ant_common_page80_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_COMMON_PAGE_80_H__
/** @} */

View file

@ -0,0 +1,117 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_COMMON_PAGE_81)
#include "ant_common_page_81.h"
#define NRF_LOG_MODULE_NAME ant_common_page_81
#if ANT_COMMON_PAGE_81_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_COMMON_PAGE_81_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_COMMON_PAGE_81_INFO_COLOR
#else // ANT_COMMON_PAGE_81_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_COMMON_PAGE_81_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief ant+ common page 81 data layout structure. */
typedef struct
{
uint8_t reserved; ///< unused, fill by 0xFF
uint8_t sw_revision_minor;
uint8_t sw_revision_major;
uint8_t serial_number[4];
}ant_common_page81_data_layout_t;
/**@brief Function for tracing page 80 data.
*
* @param[in] p_page_data Pointer to the page 80 data.
*/
static void page81_data_log(volatile ant_common_page81_data_t const * p_page_data)
{
if (p_page_data->sw_revision_minor != UINT8_MAX)
{
NRF_LOG_INFO("sw revision: %u.%u",
((ant_common_page81_data_t const *) p_page_data)->sw_revision_major,
((ant_common_page81_data_t const *) p_page_data)->sw_revision_minor);
}
else
{
NRF_LOG_INFO("sw revision: %u", p_page_data->sw_revision_major);
}
NRF_LOG_INFO("serial number: %u\r\n\n", (unsigned int) p_page_data->serial_number);
}
void ant_common_page_81_encode(uint8_t * p_page_buffer,
volatile ant_common_page81_data_t const * p_page_data)
{
ant_common_page81_data_layout_t * p_outcoming_data =
(ant_common_page81_data_layout_t *)p_page_buffer;
p_outcoming_data->reserved = UINT8_MAX;
p_outcoming_data->sw_revision_minor = p_page_data->sw_revision_minor;
p_outcoming_data->sw_revision_major = p_page_data->sw_revision_major;
UNUSED_PARAMETER(uint32_encode(p_page_data->serial_number, p_outcoming_data->serial_number));
page81_data_log(p_page_data);
}
void ant_common_page_81_decode(uint8_t const * p_page_buffer,
volatile ant_common_page81_data_t * p_page_data)
{
ant_common_page81_data_layout_t const * p_incoming_data =
(ant_common_page81_data_layout_t *)p_page_buffer;
p_page_data->sw_revision_minor = p_incoming_data->sw_revision_minor;
p_page_data->sw_revision_major = p_incoming_data->sw_revision_major;
p_page_data->serial_number = uint32_decode(p_incoming_data->serial_number);
page81_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_COMMON_PAGE_81)

View file

@ -0,0 +1,111 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_COMMON_PAGE_81_H__
#define ANT_COMMON_PAGE_81_H__
/** @file
*
* @defgroup ant_common_page_81 ANT+ common page 81
* @{
* @ingroup ant_sdk_common_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ANT_COMMON_PAGE_81 (81) ///< @brief ID value of common page 81.
/**@brief Data structure for ANT+ common data page 81.
*
* @note This structure implements only page 81 specific data.
*/
typedef struct
{
uint8_t sw_revision_minor; ///< Supplemental, fill by 0xFF if unused.
uint8_t sw_revision_major; ///< Main software version.
uint32_t serial_number; ///< Lowest 32 b of serial number, fill by 0xFFFFFFFFF if unused.
} ant_common_page81_data_t;
/**@brief Initialize page 81.
*/
#define DEFAULT_ANT_COMMON_page81() \
(ant_common_page81_data_t) \
{ \
.sw_revision_minor = UINT8_MAX, \
.sw_revision_major = UINT8_MAX, \
.serial_number = UINT32_MAX, \
}
/**@brief Initialize page 81.
*/
#define ANT_COMMON_page81(sw_major_rev, sw_minor_rev, seril_no) \
(ant_common_page81_data_t) \
{ \
.sw_revision_minor = (sw_minor_rev), \
.sw_revision_major = (sw_major_rev), \
.serial_number = (seril_no), \
}
/**@brief Function for encoding page 81.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_common_page_81_encode(uint8_t * p_page_buffer,
volatile ant_common_page81_data_t const * p_page_data);
/**@brief Function for decoding page 81.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_common_page_81_decode(uint8_t const * p_page_buffer,
volatile ant_common_page81_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_COMMON_PAGE_81_H__
/** @} */

View file

@ -0,0 +1,346 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_config.h"
#if ANT_HRM_ENABLED
#include "nrf_assert.h"
#include "app_error.h"
#include "ant_interface.h"
#include "app_util.h"
#include "ant_hrm.h"
#include "ant_hrm_utils.h"
#include "app_error.h"
#define NRF_LOG_MODULE_NAME ant_hrm
#if ANT_HRM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_INFO_COLOR
#else // ANT_HRM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#define BACKGROUND_DATA_INTERVAL 64 /**< The number of main data pages sent between background data page.
Background data page is sent every 65th message. */
#define TX_TOGGLE_DIVISOR 4 /**< The number of messages between changing state of toggle bit. */
/**@brief HRM message data layout structure. */
typedef struct
{
ant_hrm_page_t page_number : 7;
uint8_t toggle_bit : 1;
uint8_t page_payload[7];
} ant_hrm_message_layout_t;
/**@brief Function for initializing the ANT HRM profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
static ret_code_t ant_hrm_init(ant_hrm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config)
{
p_profile->channel_number = p_channel_config->channel_number;
p_profile->page_0 = DEFAULT_ANT_HRM_PAGE0();
p_profile->page_1 = DEFAULT_ANT_HRM_PAGE1();
p_profile->page_2 = DEFAULT_ANT_HRM_PAGE2();
p_profile->page_3 = DEFAULT_ANT_HRM_PAGE3();
p_profile->page_4 = DEFAULT_ANT_HRM_PAGE4();
NRF_LOG_INFO("ANT HRM channel %u init", p_profile->channel_number);
return ant_channel_init(p_channel_config);
}
ret_code_t ant_hrm_disp_init(ant_hrm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_hrm_evt_handler_t evt_handler)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(evt_handler != NULL);
p_profile->evt_handler = evt_handler;
return ant_hrm_init(p_profile, p_channel_config);
}
ret_code_t ant_hrm_sens_init(ant_hrm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_hrm_sens_config_t const * p_sens_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_sens_config != NULL);
ASSERT(p_sens_config->p_cb != NULL);
ASSERT(p_sens_config->evt_handler != NULL);
ASSERT((p_sens_config->main_page_number == ANT_HRM_PAGE_0)
|| (p_sens_config->main_page_number == ANT_HRM_PAGE_4));
p_profile->evt_handler = p_sens_config->evt_handler;
p_profile->_cb.p_sens_cb = p_sens_config->p_cb;
ant_hrm_sens_cb_t * p_hrm_cb = p_profile->_cb.p_sens_cb;
p_hrm_cb->page_1_present = p_sens_config->page_1_present;
p_hrm_cb->main_page_number = p_sens_config->main_page_number;
p_hrm_cb->ext_page_number = p_hrm_cb->page_1_present ? ANT_HRM_PAGE_1 : ANT_HRM_PAGE_2;
p_hrm_cb->message_counter = 0;
p_hrm_cb->toggle_bit = true;
return ant_hrm_init(p_profile, p_channel_config);
}
/**@brief Function for getting next page number to send.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @return Next page number.
*/
static ant_hrm_page_t next_page_number_get(ant_hrm_profile_t * p_profile)
{
ant_hrm_sens_cb_t * p_hrm_cb = p_profile->_cb.p_sens_cb;
ant_hrm_page_t page_number;
if (p_hrm_cb->message_counter == (BACKGROUND_DATA_INTERVAL))
{
page_number = p_hrm_cb->ext_page_number;
p_hrm_cb->message_counter = 0;
p_hrm_cb->ext_page_number++;
if (p_hrm_cb->ext_page_number > ANT_HRM_PAGE_3)
{
p_hrm_cb->ext_page_number = p_hrm_cb->page_1_present ? ANT_HRM_PAGE_1 : ANT_HRM_PAGE_2;
}
}
else
{
page_number = p_hrm_cb->main_page_number;
}
if (p_hrm_cb->message_counter % TX_TOGGLE_DIVISOR == 0)
{
p_hrm_cb->toggle_bit ^= 1;
}
p_hrm_cb->message_counter++;
return page_number;
}
/**@brief Function for encoding HRM message.
*
* @note Assume to be call each time when Tx window will occur.
*/
static void sens_message_encode(ant_hrm_profile_t * p_profile, uint8_t * p_message_payload)
{
ant_hrm_message_layout_t * p_hrm_message_payload =
(ant_hrm_message_layout_t *)p_message_payload;
ant_hrm_sens_cb_t * p_hrm_cb = p_profile->_cb.p_sens_cb;
p_hrm_message_payload->page_number = next_page_number_get(p_profile);
p_hrm_message_payload->toggle_bit = p_hrm_cb->toggle_bit;
NRF_LOG_INFO("HRM TX Page number: %u", p_hrm_message_payload->page_number);
ant_hrm_page_0_encode(p_hrm_message_payload->page_payload, &(p_profile->page_0)); // Page 0 is present in each message
switch (p_hrm_message_payload->page_number)
{
case ANT_HRM_PAGE_0:
// No implementation needed
break;
case ANT_HRM_PAGE_1:
ant_hrm_page_1_encode(p_hrm_message_payload->page_payload, &(p_profile->page_1));
break;
case ANT_HRM_PAGE_2:
ant_hrm_page_2_encode(p_hrm_message_payload->page_payload, &(p_profile->page_2));
break;
case ANT_HRM_PAGE_3:
ant_hrm_page_3_encode(p_hrm_message_payload->page_payload, &(p_profile->page_3));
break;
case ANT_HRM_PAGE_4:
ant_hrm_page_4_encode(p_hrm_message_payload->page_payload, &(p_profile->page_4));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_hrm_evt_t)p_hrm_message_payload->page_number);
}
/**@brief Function for setting payload for ANT message and sending it.
*
* @param[in] p_profile Pointer to the profile instance.
*/
static void ant_message_send(ant_hrm_profile_t * p_profile)
{
uint32_t err_code;
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
sens_message_encode(p_profile, p_message_payload);
err_code =
sd_ant_broadcast_message_tx(p_profile->channel_number,
sizeof (p_message_payload),
p_message_payload);
APP_ERROR_CHECK(err_code);
}
void ant_hrm_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ant_hrm_profile_t * p_profile = (ant_hrm_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
switch (p_ant_evt->event)
{
case EVENT_TX:
ant_message_send(p_profile);
break;
default:
break;
}
}
}
ret_code_t ant_hrm_disp_open(ant_hrm_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
NRF_LOG_INFO("ANT HRM channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
ret_code_t ant_hrm_sens_open(ant_hrm_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
// Fill tx buffer for the first frame
ant_message_send(p_profile);
NRF_LOG_INFO("ANT HRM channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
/**@brief Function for decoding HRM message.
*
* @note Assume to be call each time when Rx window will occur.
*/
static void disp_message_decode(ant_hrm_profile_t * p_profile, uint8_t * p_message_payload)
{
const ant_hrm_message_layout_t * p_hrm_message_payload =
(ant_hrm_message_layout_t *)p_message_payload;
NRF_LOG_INFO("HRM RX Page Number: %u", p_hrm_message_payload->page_number);
ant_hrm_page_0_decode(p_hrm_message_payload->page_payload, &(p_profile->page_0)); // Page 0 is present in each message
switch (p_hrm_message_payload->page_number)
{
case ANT_HRM_PAGE_0:
// No implementation needed
break;
case ANT_HRM_PAGE_1:
ant_hrm_page_1_decode(p_hrm_message_payload->page_payload, &(p_profile->page_1));
break;
case ANT_HRM_PAGE_2:
ant_hrm_page_2_decode(p_hrm_message_payload->page_payload, &(p_profile->page_2));
break;
case ANT_HRM_PAGE_3:
ant_hrm_page_3_decode(p_hrm_message_payload->page_payload, &(p_profile->page_3));
break;
case ANT_HRM_PAGE_4:
ant_hrm_page_4_decode(p_hrm_message_payload->page_payload, &(p_profile->page_4));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_hrm_evt_t)p_hrm_message_payload->page_number);
}
void ant_hrm_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ant_hrm_profile_t * p_profile = ( ant_hrm_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
switch (p_ant_evt->event)
{
case EVENT_RX:
if (p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
{
disp_message_decode(p_profile, p_ant_evt->message.ANT_MESSAGE_aucPayload);
}
break;
default:
break;
}
}
}
#endif // ANT_HRM_ENABLED

View file

@ -0,0 +1,292 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ant_hrm Heart Rate Monitor profile
* @{
* @ingroup ant_sdk_profiles
* @brief This module implements the Heart Rate Monitor profile.
*
*/
#ifndef ANT_HRM_H__
#define ANT_HRM_H__
#include <stdint.h>
#include <stdbool.h>
#include "app_util.h"
#include "ant_parameters.h"
#include "nrf_sdh_ant.h"
#include "ant_channel_config.h"
#include "ant_hrm_pages.h"
#include "sdk_errors.h"
#define HRM_DEVICE_TYPE 0x78u ///< Device type reserved for ANT+ heart rate monitor.
#define HRM_ANTPLUS_RF_FREQ 0x39u ///< Frequency, decimal 57 (2457 MHz).
#define HRM_MSG_PERIOD_4Hz 0x1F86u ///< Message period, decimal 8070 (4.06 Hz).
#define HRM_MSG_PERIOD_2Hz 0x3F0Cu ///< Message period, decimal 16140 (2.03 Hz).
#define HRM_MSG_PERIOD_1Hz 0x7E18u ///< Message period, decimal 32280 (1.02 Hz).
#define HRM_EXT_ASSIGN 0x00 ///< ANT ext assign.
#define HRM_DISP_CHANNEL_TYPE CHANNEL_TYPE_SLAVE ///< Display HRM channel type.
#define HRM_SENS_CHANNEL_TYPE CHANNEL_TYPE_MASTER ///< Sensor HRM channel type.
/**@brief Initialize an ANT channel configuration structure for the HRM profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
* @param[in] HRM_MSG_PERIOD Channel period in 32 kHz counts. The HRM profile supports only the following periods:
* @ref HRM_MSG_PERIOD_4Hz, @ref HRM_MSG_PERIOD_2Hz, @ref HRM_MSG_PERIOD_1Hz.
*/
#define HRM_DISP_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER, \
HRM_MSG_PERIOD) \
static const ant_channel_config_t CONCAT_2(NAME,_channel_hrm_disp_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = HRM_DISP_CHANNEL_TYPE, \
.ext_assign = HRM_EXT_ASSIGN, \
.rf_freq = HRM_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = HRM_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = (HRM_MSG_PERIOD), \
.network_number = (NETWORK_NUMBER), \
}
#define HRM_DISP_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME,_channel_hrm_disp_config)
/**@brief Initialize an ANT channel configuration structure for the HRM profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
*/
#define HRM_SENS_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER) \
static const ant_channel_config_t CONCAT_2(NAME,_channel_hrm_sens_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = HRM_SENS_CHANNEL_TYPE, \
.ext_assign = HRM_EXT_ASSIGN, \
.rf_freq = HRM_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = HRM_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = HRM_MSG_PERIOD_4Hz, \
.network_number = (NETWORK_NUMBER), \
}
#define HRM_SENS_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME,_channel_hrm_sens_config)
/**@brief Initialize an ANT profile configuration structure for the HRM profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] PAGE_1_PRESENT Determines whether page 1 is included.
* @param[in] MAIN_PAGE_NUMBER Determines the main data page (@ref ANT_HRM_PAGE_0 or @ref ANT_HRM_PAGE_4).
* @param[in] EVT_HANDLER Event handler to be called for handling events in the HRM profile.
*/
#define HRM_SENS_PROFILE_CONFIG_DEF(NAME, \
PAGE_1_PRESENT, \
MAIN_PAGE_NUMBER, \
EVT_HANDLER) \
static ant_hrm_sens_cb_t CONCAT_2(NAME,_hrm_sens_cb); \
static const ant_hrm_sens_config_t CONCAT_2(NAME,_profile_hrm_sens_config) = \
{ \
.page_1_present = (PAGE_1_PRESENT), \
.main_page_number = (MAIN_PAGE_NUMBER), \
.p_cb = &CONCAT_2(NAME,_hrm_sens_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define HRM_SENS_PROFILE_CONFIG(NAME) &CONCAT_2(NAME,_profile_hrm_sens_config)
/**@brief HRM page number type. */
typedef enum
{
ANT_HRM_PAGE_0, ///< Main data page number 0.
ANT_HRM_PAGE_1, ///< Background data page number 1. This page is optional.
ANT_HRM_PAGE_2, ///< Background data page number 2.
ANT_HRM_PAGE_3, ///< Background data page number 3.
ANT_HRM_PAGE_4 ///< Main data page number 4.
} ant_hrm_page_t;
/**@brief HRM profile event type. */
typedef enum
{
ANT_HRM_PAGE_0_UPDATED = ANT_HRM_PAGE_0, ///< Data page 0 has been updated (Display) or sent (Sensor).
ANT_HRM_PAGE_1_UPDATED = ANT_HRM_PAGE_1, ///< Data page 0 and page 1 have been updated (Display) or sent (Sensor).
ANT_HRM_PAGE_2_UPDATED = ANT_HRM_PAGE_2, ///< Data page 0 and page 2 have been updated (Display) or sent (Sensor).
ANT_HRM_PAGE_3_UPDATED = ANT_HRM_PAGE_3, ///< Data page 0 and page 3 have been updated (Display) or sent (Sensor).
ANT_HRM_PAGE_4_UPDATED = ANT_HRM_PAGE_4, ///< Data page 0 and page 4 have been updated (Display) or sent (Sensor).
} ant_hrm_evt_t;
// Forward declaration of the ant_hrm_profile_t type.
typedef struct ant_hrm_profile_s ant_hrm_profile_t;
/**@brief HRM event handler type. */
typedef void (* ant_hrm_evt_handler_t) (ant_hrm_profile_t *, ant_hrm_evt_t);
#include "ant_hrm_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief HRM sensor configuration structure. */
typedef struct
{
bool page_1_present; ///< Determines whether page 1 is included.
ant_hrm_page_t main_page_number; ///< Determines the main data page (@ref ANT_HRM_PAGE_0 or @ref ANT_HRM_PAGE_4).
ant_hrm_sens_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_hrm_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the HRM profile.
} ant_hrm_sens_config_t;
/**@brief HRM profile structure. */
struct ant_hrm_profile_s
{
uint8_t channel_number; ///< Channel number assigned to the profile.
union {
void * p_none;
ant_hrm_sens_cb_t * p_sens_cb;
} _cb; ///< Pointer to internal control block.
ant_hrm_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the HRM profile.
ant_hrm_page0_data_t page_0; ///< Page 0.
ant_hrm_page1_data_t page_1; ///< Page 1.
ant_hrm_page2_data_t page_2; ///< Page 2.
ant_hrm_page3_data_t page_3; ///< Page 3.
ant_hrm_page4_data_t page_4; ///< Page 4.
};
/** @name Defines for accessing ant_hrm_profile_t member variables
@{ */
#define HRM_PROFILE_beat_count page_0.beat_count
#define HRM_PROFILE_computed_heart_rate page_0.computed_heart_rate
#define HRM_PROFILE_beat_time page_0.beat_time
#define HRM_PROFILE_operating_time page_1.operating_time
#define HRM_PROFILE_manuf_id page_2.manuf_id
#define HRM_PROFILE_serial_num page_2.serial_num
#define HRM_PROFILE_hw_version page_3.hw_version
#define HRM_PROFILE_sw_version page_3.sw_version
#define HRM_PROFILE_model_num page_3.model_num
#define HRM_PROFILE_manuf_spec page_4.manuf_spec
#define HRM_PROFILE_prev_beat page_4.prev_beat
/** @} */
/**@brief Function for initializing the ANT HRM Display profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] evt_handler Event handler to be called for handling events in the HRM profile.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_hrm_disp_init(ant_hrm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_hrm_evt_handler_t evt_handler);
/**@brief Function for initializing the ANT HRM Sensor profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_sens_config Pointer to the HRM sensor configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_hrm_sens_init(ant_hrm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_hrm_sens_config_t const * p_sens_config);
/**@brief Function for opening the profile instance channel for ANT HRM Display.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_hrm_disp_open(ant_hrm_profile_t * p_profile);
/**@brief Function for opening the profile instance channel for ANT HRM Sensor.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_hrm_sens_open(ant_hrm_profile_t * p_profile);
/**@brief Function for handling the sensor ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Heart Rate Monitor Sensor profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_hrm_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
/**@brief Function for handling the display ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the Heart Rate Monitor Display profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_hrm_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_H__
/** @} */

View file

@ -0,0 +1,75 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_LOCAL_H__
#define ANT_HRM_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_hrm.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup ant_hrm
* @{
*/
/** @brief HRM Sensor control block. */
typedef struct
{
uint8_t toggle_bit;
ant_hrm_page_t main_page_number;
uint8_t page_1_present;
ant_hrm_page_t ext_page_number;
uint8_t message_counter;
} ant_hrm_sens_cb_t;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_LOCAL_H__

View file

@ -0,0 +1,116 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_HRM)
#include "ant_hrm_page_0.h"
#include "ant_hrm_utils.h"
#define NRF_LOG_MODULE_NAME ant_hrm_page_0
#if ANT_HRM_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_PAGE_0_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_PAGE_0_INFO_COLOR
#else // ANT_HRM_PAGE_0_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_PAGE_0_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief HRM page 0 data layout structure. */
typedef struct
{
uint8_t reserved[3];
uint8_t heart_beat_evt_time_LSB;
uint8_t heart_beat_evt_time_MSB;
uint8_t heart_beat_count;
uint8_t computed_heart_rate;
}ant_hrm_page0_data_layout_t;
/**@brief Function for tracing page 0 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 0 data.
*/
static void page0_data_log(ant_hrm_page0_data_t const * p_page_data)
{
NRF_LOG_INFO("Heart beat count: %u", (unsigned int)p_page_data->beat_count);
NRF_LOG_INFO("Computed heart rate: %u",
(unsigned int) p_page_data->computed_heart_rate);
NRF_LOG_INFO("Heart beat event time: %u.%03us\r\n\n",
(unsigned int) ANT_HRM_BEAT_TIME_SEC(p_page_data->beat_time),
(unsigned int) ANT_HRM_BEAT_TIME_MSEC(p_page_data->beat_time));
}
void ant_hrm_page_0_encode(uint8_t * p_page_buffer,
ant_hrm_page0_data_t const * p_page_data)
{
ant_hrm_page0_data_layout_t * p_outcoming_data = (ant_hrm_page0_data_layout_t *)p_page_buffer;
uint32_t beat_time = p_page_data->beat_time;
p_outcoming_data->reserved[0] = UINT8_MAX;
p_outcoming_data->reserved[1] = UINT8_MAX;
p_outcoming_data->reserved[2] = UINT8_MAX;
p_outcoming_data->heart_beat_evt_time_LSB = (uint8_t)(beat_time & UINT8_MAX);
p_outcoming_data->heart_beat_evt_time_MSB = (uint8_t)((beat_time >> 8) & UINT8_MAX);
p_outcoming_data->heart_beat_count = (uint8_t)p_page_data->beat_count;
p_outcoming_data->computed_heart_rate = (uint8_t)p_page_data->computed_heart_rate;
page0_data_log(p_page_data);
}
void ant_hrm_page_0_decode(uint8_t const * p_page_buffer,
ant_hrm_page0_data_t * p_page_data)
{
ant_hrm_page0_data_layout_t const * p_incoming_data =
(ant_hrm_page0_data_layout_t *)p_page_buffer;
uint32_t beat_time = (uint32_t)((p_incoming_data->heart_beat_evt_time_MSB << 8)
+ p_incoming_data->heart_beat_evt_time_LSB);
p_page_data->beat_count = (uint32_t)p_incoming_data->heart_beat_count;
p_page_data->computed_heart_rate = (uint32_t)p_incoming_data->computed_heart_rate;
p_page_data->beat_time = beat_time;
page0_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_HRM)

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_PAGE_0_H__
#define ANT_HRM_PAGE_0_H__
/** @file
*
* @defgroup ant_sdk_profiles_hrm_page0 HRM profile page 0
* @{
* @ingroup ant_sdk_profiles_hrm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for HRM data page 0.
*
* This structure is used as a common page.
*/
typedef struct
{
uint8_t beat_count; ///< Beat count.
uint8_t computed_heart_rate; ///< Computed heart rate.
uint16_t beat_time; ///< Beat time.
} ant_hrm_page0_data_t;
/**@brief Initialize page 0.
*/
#define DEFAULT_ANT_HRM_PAGE0() \
(ant_hrm_page0_data_t) \
{ \
.beat_count = 0, \
.computed_heart_rate = 0, \
.beat_time = 0, \
}
/**@brief Function for encoding page 0.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_hrm_page_0_encode(uint8_t * p_page_buffer,
ant_hrm_page0_data_t const * p_page_data);
/**@brief Function for decoding page 0.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_hrm_page_0_decode(uint8_t const * p_page_buffer,
ant_hrm_page0_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_PAGE_0_H__
/** @} */

View file

@ -0,0 +1,102 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_HRM)
#include "ant_hrm_page_1.h"
#include "ant_hrm_utils.h"
#define NRF_LOG_MODULE_NAME ant_hrm_page_1
#if ANT_HRM_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_PAGE_1_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_PAGE_1_INFO_COLOR
#else // ANT_HRM_PAGE_1_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_PAGE_1_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief HRM page 1 data layout structure. */
typedef struct
{
uint8_t cumulative_operating_time[3];
uint8_t reserved[4];
}ant_hrm_page1_data_layout_t;
/**@brief Function for tracing page 1 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 1 data.
*/
static void page1_data_log(ant_hrm_page1_data_t const * p_page_data)
{
NRF_LOG_INFO("Cumulative operating time: %ud %uh %um %us\r\n\n",
(unsigned int) ANT_HRM_OPERATING_DAYS(p_page_data->operating_time),
(unsigned int) ANT_HRM_OPERATING_HOURS(p_page_data->operating_time),
(unsigned int) ANT_HRM_OPERATING_MINUTES(p_page_data->operating_time),
(unsigned int) ANT_HRM_OPERATING_SECONDS(p_page_data->operating_time));
}
void ant_hrm_page_1_encode(uint8_t * p_page_buffer,
ant_hrm_page1_data_t const * p_page_data)
{
ant_hrm_page1_data_layout_t * p_outcoming_data = (ant_hrm_page1_data_layout_t *)p_page_buffer;
uint32_t operating_time = p_page_data->operating_time;
UNUSED_PARAMETER(uint24_encode(operating_time, p_outcoming_data->cumulative_operating_time));
page1_data_log(p_page_data);
}
void ant_hrm_page_1_decode(uint8_t const * p_page_buffer,
ant_hrm_page1_data_t * p_page_data)
{
ant_hrm_page1_data_layout_t const * p_incoming_data =
(ant_hrm_page1_data_layout_t *)p_page_buffer;
uint32_t operating_time = uint24_decode(p_incoming_data->cumulative_operating_time);
p_page_data->operating_time = operating_time;
page1_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_HRM)

View file

@ -0,0 +1,95 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_PAGE_1_H__
#define ANT_HRM_PAGE_1_H__
/** @file
*
* @defgroup ant_sdk_profiles_hrm_page1 HRM profile page 1
* @{
* @ingroup ant_sdk_profiles_hrm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for HRM data page 1.
*
* This structure implements only page 1 specific data.
*/
typedef struct
{
uint32_t operating_time; ///< Operating time.
} ant_hrm_page1_data_t;
/**@brief Initialize page 1.
*/
#define DEFAULT_ANT_HRM_PAGE1() \
(ant_hrm_page1_data_t) \
{ \
.operating_time = 0, \
}
/**@brief Function for encoding page 1.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_hrm_page_1_encode(uint8_t * p_page_buffer,
ant_hrm_page1_data_t const * p_page_data);
/**@brief Function for decoding page 1.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_hrm_page_1_decode(uint8_t const * p_page_buffer,
ant_hrm_page1_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_PAGE_1_H__
/** @} */

View file

@ -0,0 +1,106 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_HRM)
#include "ant_hrm_page_2.h"
#define NRF_LOG_MODULE_NAME ant_hrm_page_2
#if ANT_HRM_PAGE_2_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_PAGE_2_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_PAGE_2_INFO_COLOR
#else // ANT_HRM_PAGE_2_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_PAGE_2_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief HRM page 2 data layout structure. */
typedef struct
{
uint8_t manuf_id;
uint8_t serial_num_LSB;
uint8_t serial_num_MSB;
uint8_t reserved[4];
}ant_hrm_page2_data_layout_t;
/**@brief Function for tracing page 2 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 2 data.
*/
static void page2_data_log(ant_hrm_page2_data_t const * p_page_data)
{
NRF_LOG_INFO("Manufacturer ID: %u", (unsigned int)p_page_data->manuf_id);
NRF_LOG_INFO("Serial No (upper 16-bits): 0x%X\r\n\n", (unsigned int)p_page_data->serial_num);
}
void ant_hrm_page_2_encode(uint8_t * p_page_buffer,
ant_hrm_page2_data_t const * p_page_data)
{
ant_hrm_page2_data_layout_t * p_outcoming_data = (ant_hrm_page2_data_layout_t *)p_page_buffer;
uint32_t serial_num = p_page_data->serial_num;
p_outcoming_data->manuf_id = (uint8_t)p_page_data->manuf_id;
p_outcoming_data->serial_num_LSB = (uint8_t)(serial_num & UINT8_MAX);
p_outcoming_data->serial_num_MSB = (uint8_t)((serial_num >> 8) & UINT8_MAX);
page2_data_log(p_page_data);
}
void ant_hrm_page_2_decode(uint8_t const * p_page_buffer,
ant_hrm_page2_data_t * p_page_data)
{
ant_hrm_page2_data_layout_t const * p_incoming_data =
(ant_hrm_page2_data_layout_t *)p_page_buffer;
uint32_t serial_num =
(uint32_t)((p_incoming_data->serial_num_MSB << 8)
+ p_incoming_data->
serial_num_LSB);
p_page_data->manuf_id = (uint32_t)p_incoming_data->manuf_id;
p_page_data->serial_num = serial_num;
page2_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_HRM)

View file

@ -0,0 +1,97 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_PAGE_2_H__
#define ANT_HRM_PAGE_2_H__
/** @file
*
* @defgroup ant_sdk_profiles_hrm_page2 HRM profile page 2
* @{
* @ingroup ant_sdk_profiles_hrm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for HRM data page 2.
*
* This structure implements only page 2 specific data.
*/
typedef struct
{
uint8_t manuf_id; ///< Manufacturer ID.
uint16_t serial_num; ///< Serial number.
} ant_hrm_page2_data_t;
/**@brief Initialize page 2.
*/
#define DEFAULT_ANT_HRM_PAGE2() \
(ant_hrm_page2_data_t) \
{ \
.manuf_id = 0, \
.serial_num = 0, \
}
/**@brief Function for encoding page 2.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_hrm_page_2_encode(uint8_t * p_page_buffer,
ant_hrm_page2_data_t const * p_page_data);
/**@brief Function for decoding page 2.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_hrm_page_2_decode(uint8_t const * p_page_buffer,
ant_hrm_page2_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_PAGE_2_H__
/** @} */

View file

@ -0,0 +1,103 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_HRM)
#include "ant_hrm_page_3.h"
#define NRF_LOG_MODULE_NAME ant_hrm_page_3
#if ANT_HRM_PAGE_3_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_PAGE_3_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_PAGE_3_INFO_COLOR
#else // ANT_HRM_PAGE_3_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_PAGE_3_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief HRM page 3 data layout structure. */
typedef struct
{
uint8_t hw_version;
uint8_t sw_version;
uint8_t model_num;
uint8_t reserved[4];
}ant_hrm_page3_data_layout_t;
/**@brief Function for tracing page 3 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 3 data.
*/
static void page3_data_log(ant_hrm_page3_data_t const * p_page_data)
{
NRF_LOG_INFO("Hardware Rev ID %u", (unsigned int)p_page_data->hw_version);
NRF_LOG_INFO("Model %u", (unsigned int)p_page_data->model_num);
NRF_LOG_INFO("Software Ver ID %u\r\n\n", (unsigned int)p_page_data->sw_version);
}
void ant_hrm_page_3_encode(uint8_t * p_page_buffer,
ant_hrm_page3_data_t const * p_page_data)
{
ant_hrm_page3_data_layout_t * p_outcoming_data = (ant_hrm_page3_data_layout_t *)p_page_buffer;
p_outcoming_data->hw_version = (uint8_t)p_page_data->hw_version;
p_outcoming_data->sw_version = (uint8_t)p_page_data->sw_version;
p_outcoming_data->model_num = (uint8_t)p_page_data->model_num;
page3_data_log(p_page_data);
}
void ant_hrm_page_3_decode(uint8_t const * p_page_buffer,
ant_hrm_page3_data_t * p_page_data)
{
ant_hrm_page3_data_layout_t const * p_incoming_data =
(ant_hrm_page3_data_layout_t *)p_page_buffer;
p_page_data->hw_version = (uint32_t)p_incoming_data->hw_version;
p_page_data->sw_version = (uint32_t)p_incoming_data->sw_version;
p_page_data->model_num = (uint32_t)p_incoming_data->model_num;
page3_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_HRM)

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_PAGE_3_H__
#define ANT_HRM_PAGE_3_H__
/** @file
*
* @defgroup ant_sdk_profiles_hrm_page3 HRM profile page 3
* @{
* @ingroup ant_sdk_profiles_hrm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for HRM data page 3.
*
* This structure implements only page 3 specific data.
*/
typedef struct
{
uint8_t hw_version; ///< Hardware version.
uint8_t sw_version; ///< Software version.
uint8_t model_num; ///< Model number.
} ant_hrm_page3_data_t;
/**@brief Initialize page 3.
*/
#define DEFAULT_ANT_HRM_PAGE3() \
(ant_hrm_page3_data_t) \
{ \
.hw_version = 0, \
.sw_version = 0, \
.model_num = 0, \
}
/**@brief Function for encoding page 3.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_hrm_page_3_encode(uint8_t * p_page_buffer,
ant_hrm_page3_data_t const * p_page_data);
/**@brief Function for decoding page 3.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_hrm_page_3_decode(uint8_t const * p_page_buffer,
ant_hrm_page3_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_PAGE_3_H__
/** @} */

View file

@ -0,0 +1,107 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_HRM)
#include "ant_hrm_page_4.h"
#include "ant_hrm_utils.h"
#define NRF_LOG_MODULE_NAME ant_hrm_page_4
#if ANT_HRM_PAGE_4_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_HRM_PAGE_4_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_HRM_PAGE_4_INFO_COLOR
#else // ANT_HRM_PAGE_4_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_HRM_PAGE_4_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
/**@brief HRM page 4 data layout structure. */
typedef struct
{
uint8_t manuf_spec;
uint8_t prev_beat_LSB;
uint8_t prev_beat_MSB;
uint8_t reserved[4];
}ant_hrm_page4_data_layout_t;
/**@brief Function for tracing page 4 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 4 data.
*/
static void page4_data_log(ant_hrm_page4_data_t const * p_page_data)
{
NRF_LOG_INFO("Previous heart beat event time: %u.%03us\r\n\n",
(unsigned int)ANT_HRM_BEAT_TIME_SEC(p_page_data->prev_beat),
(unsigned int)ANT_HRM_BEAT_TIME_MSEC(p_page_data->prev_beat));
}
void ant_hrm_page_4_encode(uint8_t * p_page_buffer,
ant_hrm_page4_data_t const * p_page_data)
{
ant_hrm_page4_data_layout_t * p_outcoming_data = (ant_hrm_page4_data_layout_t *)p_page_buffer;
uint32_t prev_beat = p_page_data->prev_beat;
p_outcoming_data->manuf_spec = p_page_data->manuf_spec;
p_outcoming_data->prev_beat_LSB = (uint8_t)(prev_beat & UINT8_MAX);
p_outcoming_data->prev_beat_MSB = (uint8_t)((prev_beat >> 8) & UINT8_MAX);
page4_data_log(p_page_data);
}
void ant_hrm_page_4_decode(uint8_t const * p_page_buffer,
ant_hrm_page4_data_t * p_page_data)
{
ant_hrm_page4_data_layout_t const * p_incoming_data =
(ant_hrm_page4_data_layout_t *)p_page_buffer;
uint32_t prev_beat = (uint32_t)((p_incoming_data->prev_beat_MSB << 8)
+ p_incoming_data->prev_beat_LSB);
p_page_data->manuf_spec = p_incoming_data->manuf_spec;
p_page_data->prev_beat = prev_beat;
page4_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_HRM)

View file

@ -0,0 +1,97 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_PAGE_4_H__
#define ANT_HRM_PAGE_4_H__
/** @file
*
* @defgroup ant_sdk_profiles_hrm_page4 HRM profile page 4
* @{
* @ingroup ant_sdk_profiles_hrm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for HRM data page 4.
*
* This structure implements only page 4 specific data.
*/
typedef struct
{
uint8_t manuf_spec; ///< Manufacturer specific byte.
uint16_t prev_beat; ///< Previous beat.
} ant_hrm_page4_data_t;
/**@brief Initialize page 4.
*/
#define DEFAULT_ANT_HRM_PAGE4() \
(ant_hrm_page4_data_t) \
{ \
.manuf_spec = 0, \
.prev_beat = 0, \
}
/**@brief Function for encoding page 4.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_hrm_page_4_encode(uint8_t * p_page_buffer,
ant_hrm_page4_data_t const * p_page_data);
/**@brief Function for decoding page 4.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_hrm_page_4_decode(uint8_t const * p_page_buffer,
ant_hrm_page4_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_PAGE_3_H__
/** @} */

View file

@ -0,0 +1,67 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __ANT_HRM_PAGES_H
#define __ANT_HRM_PAGES_H
/** @file
*
* @defgroup ant_sdk_profiles_hrm_pages Heart Rate Monitor profile pages
* @{
* @ingroup ant_hrm
* @brief This module implements functions for the HRM data pages.
*/
#include "ant_hrm_page_0.h"
#include "ant_hrm_page_1.h"
#include "ant_hrm_page_2.h"
#include "ant_hrm_page_3.h"
#include "ant_hrm_page_4.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // __ANT_HRM_PAGES_H
/** @} */

View file

@ -0,0 +1,148 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_config.h"
#if ANT_HRM_ENABLED
#include "ant_hrm_simulator.h"
#include "ant_hrm_utils.h"
#include "nordic_common.h"
#define ITERATION_ANT_CYCLES HRM_MSG_PERIOD_4Hz ///< period of calculation [1/32678 s], defined in ANT device profile
#define ITERATION_PERIOD (ITERATION_ANT_CYCLES * 1024 / ANT_CLOCK_FREQUENCY) ///< integer part of calculation's period [1/1024 s]
#define ITERATION_FRACTION (ITERATION_ANT_CYCLES * 1024 % ANT_CLOCK_FREQUENCY) ///< fractional part of calculation's period [1/32678 s]
void ant_hrm_simulator_init(ant_hrm_simulator_t * p_simulator,
ant_hrm_simulator_cfg_t const * p_config,
bool auto_change)
{
p_simulator->p_profile = p_config->p_profile;
p_simulator->_cb.sensorsim_cfg = p_config->sensorsim_cfg;
p_simulator->_cb.auto_change = auto_change;
p_simulator->_cb.sensorsim_state.current_val = p_simulator->_cb.sensorsim_cfg.min;
p_simulator->_cb.time_since_last_hb = 0;
p_simulator->_cb.fraction_since_last_hb = 0;
sensorsim_init(&(p_simulator->_cb.sensorsim_state), &(p_simulator->_cb.sensorsim_cfg));
}
void ant_hrm_simulator_one_iteration(ant_hrm_simulator_t * p_simulator)
{
if (p_simulator->_cb.auto_change)
{
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg)));
}
// @note: Take a local copy within scope in order to assist the compiler in variable register
// allocation.
const uint32_t computed_heart_rate_value = p_simulator->_cb.sensorsim_state.current_val;
// @note: This implementation assumes that the current instantaneous heart can vary and this
// function is called with static frequency.
// value and the heart rate pulse interval is derived from it. The computation is based on 60
// seconds in a minute and the used time base is 1/1024 seconds.
const uint32_t current_hb_pulse_interval = (60u * 1024u) / computed_heart_rate_value;
// update time from last hb detected
p_simulator->_cb.time_since_last_hb += ITERATION_PERIOD;
// extended celculadion by fraction make calculating accurat in long time perspective
p_simulator->_cb.fraction_since_last_hb += ITERATION_FRACTION;
uint32_t add_period = p_simulator->_cb.fraction_since_last_hb / ANT_CLOCK_FREQUENCY;
if (add_period > 0)
{
p_simulator->_cb.time_since_last_hb++;
p_simulator->_cb.fraction_since_last_hb %= ANT_CLOCK_FREQUENCY;
}
// calc number of hb as will fill
uint32_t new_beats = p_simulator->_cb.time_since_last_hb / current_hb_pulse_interval;
uint32_t add_event_time = new_beats * current_hb_pulse_interval;
if (new_beats > 0)
{
p_simulator->p_profile->HRM_PROFILE_computed_heart_rate =
(uint8_t)computed_heart_rate_value;
// Current heart beat event time is the previous event time added with the current heart rate
// pulse interval.
uint32_t current_heart_beat_event_time = p_simulator->p_profile->HRM_PROFILE_beat_time +
add_event_time;
// Set current event time.
p_simulator->p_profile->HRM_PROFILE_beat_time = current_heart_beat_event_time; // <- B<4,5> <-
// Set previous event time. // p4.B<2,3> <- B<4,5>
p_simulator->p_profile->HRM_PROFILE_prev_beat =
p_simulator->p_profile->HRM_PROFILE_beat_time - current_hb_pulse_interval;
// Event count.
p_simulator->p_profile->HRM_PROFILE_beat_count += new_beats; // B<6>
p_simulator->_cb.time_since_last_hb -= add_event_time;
}
}
void ant_hrm_simulator_increment(ant_hrm_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_increment(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg));
}
}
void ant_hrm_simulator_decrement(ant_hrm_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_decrement(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg));
}
}
#endif // ANT_HRM_ENABLED

View file

@ -0,0 +1,130 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_SIMULATOR_H__
#define ANT_HRM_SIMULATOR_H__
/** @file
*
* @defgroup ant_sdk_hrm_simulator ANT HRM simulator
* @{
* @ingroup ant_sdk_simulators
* @brief ANT HRM simulator module.
*
* @details This module simulates a pulse for the ANT HRM profile. The module calculates abstract values, which are handled
* by the HRM pages data model to ensure that they are compatible. It provides a handler for changing the heart rate
* value manually and functionality to change the heart rate value automatically.
*
*/
#include <stdint.h>
#include <stdbool.h>
#include "ant_hrm.h"
#include "ant_hrm_utils.h"
#include "sensorsim.h"
#include "ant_hrm_simulator_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief HRM simulator configuration structure. */
typedef struct
{
ant_hrm_profile_t * p_profile; ///< Related profile.
sensorsim_cfg_t sensorsim_cfg; ///< Sensorsim configuration.
} ant_hrm_simulator_cfg_t;
/**@brief Initialize @ref ant_hrm_simulator_cfg_t.
*/
#define DEFAULT_ANT_HRM_SIMULATOR_CFG(P_PROFILE, MIN_HEART_RATE, MAX_HEART_RATE, INCREMENT) \
{ \
.p_profile = (P_PROFILE), \
.sensorsim_cfg.min = (MIN_HEART_RATE), \
.sensorsim_cfg.max = (MAX_HEART_RATE), \
.sensorsim_cfg.incr = (INCREMENT), \
.sensorsim_cfg.start_at_max = false, \
}
/**@brief HRM simulator structure. */
typedef struct
{
ant_hrm_profile_t * p_profile; ///< Related profile.
ant_hrm_simulator_cb_t _cb; ///< Internal control block.
} ant_hrm_simulator_t;
/**@brief Function for initializing the ANT HRM simulator instance.
*
* @param[in] p_simulator Pointer to the simulator instance.
* @param[in] p_config Pointer to the simulator configuration structure.
* @param[in] auto_change Enable or disable automatic changes of the cadence.
*/
void ant_hrm_simulator_init(ant_hrm_simulator_t * p_simulator,
ant_hrm_simulator_cfg_t const * p_config,
bool auto_change);
/**@brief Function for simulating a device event.
*
* @details Based on this event, the transmitter data is simulated.
*
* This function should be called in the HRM TX event handler.
*/
void ant_hrm_simulator_one_iteration(ant_hrm_simulator_t * p_simulator);
/**@brief Function for incrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_hrm_simulator_increment(ant_hrm_simulator_t * p_simulator);
/**@brief Function for decrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_hrm_simulator_decrement(ant_hrm_simulator_t * p_simulator);
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_SIMULATOR_H__
/** @} */

View file

@ -0,0 +1,69 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_SIMULATOR_LOCAL_H__
#define ANT_HRM_SIMULATOR_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_hrm.h"
#include "sensorsim.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup ant_sdk_hrm_simulator
* @brief HRM simulator control block structure. */
typedef struct
{
bool auto_change; ///< Cadence will change automatically (if auto_change is set) or manually.
uint32_t time_since_last_hb; ///< Time since last heart beat occurred (integer part).
uint64_t fraction_since_last_hb; ///< Time since last heart beat occurred (fractional part).
sensorsim_state_t sensorsim_state; ///< State of the simulated sensor.
sensorsim_cfg_t sensorsim_cfg; ///< Configuration of the simulated sensor.
} ant_hrm_simulator_cb_t;
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_SIMULATOR_LOCAL_H__

View file

@ -0,0 +1,111 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_HRM_UTILS_H__
#define ANT_HRM_UTILS_H__
#include "app_util.h"
#include "nrf_assert.h"
#include "nrf.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @file
*
* @defgroup ant_sdk_profiles_hrm_utils Heart Rate Monitor profile utilities
* @{
* @ingroup ant_hrm
* @brief This module implements utilities for the Heart Rate Monitor profile.
*
*/
/**@brief Unit for HRM operating time.
*
* @details According to the ANT HRM specification, the operating time unit is 2 seconds.
*/
#define ANT_HRM_OPERATING_TIME_UNIT 2u
/**@brief This macro should be used to get the seconds part of the operating time.
*/
#define ANT_HRM_OPERATING_SECONDS(OPERATING_TIME) (((OPERATING_TIME) * ANT_HRM_OPERATING_TIME_UNIT) % 60)
/**@brief This macro should be used to get the minutes part of the operating time.
*/
#define ANT_HRM_OPERATING_MINUTES(OPERATING_TIME) ((((OPERATING_TIME) * ANT_HRM_OPERATING_TIME_UNIT) / 60) % 60)
/**@brief This macro should be used to get the hours part of the operating time.
*/
#define ANT_HRM_OPERATING_HOURS(OPERATING_TIME) ((((OPERATING_TIME) * ANT_HRM_OPERATING_TIME_UNIT) / (60 * 60)) % 24)
/**@brief This macro should be used to get the days part of the operating time.
*/
#define ANT_HRM_OPERATING_DAYS(OPERATING_TIME) ((((OPERATING_TIME) * ANT_HRM_OPERATING_TIME_UNIT) / (60 * 60)) / 24)
/**@brief Number of HRM beat time counts per second.
*
* @details According to the ANT HRM specification, the beat time unit is 1/1024 of a second.
*/
#define ANT_HRM_BEAT_TIME_COUNTS_PER_SEC 1024u
/**@brief Beat time display required precision.
*
* @details This value is used to decode the number of milliseconds.
*/
#define ANT_HRM_BEAT_TIME_PRECISION 1000u
/**@brief This macro should be used to get the seconds part of the HRM beat time.
*/
#define ANT_HRM_BEAT_TIME_SEC(BEAT_TIME) ((BEAT_TIME) / ANT_HRM_BEAT_TIME_COUNTS_PER_SEC)
/**@brief This macro should be used to get the milliseconds part of the HRM beat time.
*/
#define ANT_HRM_BEAT_TIME_MSEC(BEAT_TIME) (((((BEAT_TIME) % ANT_HRM_BEAT_TIME_COUNTS_PER_SEC) * ANT_HRM_BEAT_TIME_PRECISION) \
+ (ANT_HRM_BEAT_TIME_COUNTS_PER_SEC / 2)) \
/ ANT_HRM_BEAT_TIME_COUNTS_PER_SEC)
/** @} */
#ifdef __cplusplus
}
#endif
#endif // ANT_HRM_UTILS_H__

View file

@ -0,0 +1,409 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "nrf_assert.h"
#include "app_error.h"
#include "ant_interface.h"
#include "ant_sdm.h"
#include "app_error.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#define COMMON_DATA_INTERVAL 64 /**< Common data page is sent every 65th message. */
/**@brief SDM message data layout structure. */
typedef struct
{
ant_sdm_page_t page_number;
uint8_t page_payload[7];
}ant_sdm_message_layout_t;
/**@brief Function for initializing the ANT SDM profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
*
* @retval NRF_SUCCESS Successful initialization.
* Error code when initialization failed.
*/
static ret_code_t ant_sdm_init(ant_sdm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config)
{
p_profile->channel_number = p_channel_config->channel_number;
p_profile->page_1 = DEFAULT_ANT_SDM_PAGE1();
p_profile->page_2 = DEFAULT_ANT_SDM_PAGE2();
p_profile->page_3 = DEFAULT_ANT_SDM_PAGE3();
p_profile->page_22 = DEFAULT_ANT_SDM_PAGE22();
p_profile->common = DEFAULT_ANT_SDM_COMMON_DATA();
p_profile->page_80 = DEFAULT_ANT_COMMON_page80();
p_profile->page_81 = DEFAULT_ANT_COMMON_page81();
NRF_LOG_INFO("ANT SDM channel %u init", p_profile->channel_number);
return ant_channel_init(p_channel_config);
}
ret_code_t ant_sdm_disp_init(ant_sdm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_sdm_disp_config_t const * p_disp_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_disp_config != NULL);
ASSERT(p_disp_config->p_cb != NULL);
ASSERT(p_disp_config->evt_handler != NULL);
p_profile->evt_handler = p_disp_config->evt_handler;
p_profile->_cb.p_disp_cb = p_disp_config->p_cb;
ant_request_controller_init(&(p_profile->_cb.p_disp_cb->req_controller));
return ant_sdm_init(p_profile, p_channel_config);
}
ret_code_t ant_sdm_sens_init(ant_sdm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_sdm_sens_config_t const * p_sens_config)
{
ASSERT(p_profile != NULL);
ASSERT(p_channel_config != NULL);
ASSERT(p_sens_config != NULL);
ASSERT(p_sens_config->p_cb != NULL);
ASSERT(p_sens_config->evt_handler != NULL);
ASSERT(p_sens_config->supplementary_page_number == ANT_SDM_PAGE_1
|| p_sens_config->supplementary_page_number == ANT_SDM_PAGE_2
|| p_sens_config->supplementary_page_number == ANT_SDM_PAGE_3);
p_profile->evt_handler = p_sens_config->evt_handler;
p_profile->_cb.p_sens_cb = p_sens_config->p_cb;
ant_request_controller_init(&(p_profile->_cb.p_sens_cb->req_controller));
p_profile->_cb.p_sens_cb->message_counter = 0;
p_profile->_cb.p_sens_cb->supp_page_control = 0;
p_profile->_cb.p_sens_cb->supp_page_number = p_sens_config->supplementary_page_number;
p_profile->_cb.p_sens_cb->common_page_number = ANT_SDM_PAGE_80;
return ant_sdm_init(p_profile, p_channel_config);
}
ret_code_t ant_sdm_page_request(ant_sdm_profile_t * p_profile, ant_common_page70_data_t * p_page_70)
{
ASSERT(p_profile != NULL);
ASSERT(p_page_70 != NULL);
uint32_t err_code = ant_request_controller_request(&(p_profile->_cb.p_disp_cb->req_controller),
p_profile->channel_number, p_page_70);
NRF_LOG_INFO("");
return err_code;
}
/**@brief Function for getting next page number to send.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @return Next page number.
*/
static ant_sdm_page_t next_page_number_get(ant_sdm_profile_t * p_profile)
{
ant_sdm_sens_cb_t * p_sdm_cb = p_profile->_cb.p_sens_cb;
ant_sdm_page_t page_number;
if (ant_request_controller_pending_get(&(p_sdm_cb->req_controller), (uint8_t *)&page_number))
{
// No implementation needed
}
else if (p_sdm_cb->message_counter == (COMMON_DATA_INTERVAL))
{
page_number = p_sdm_cb->common_page_number;
p_sdm_cb->message_counter++;
}
else if (p_sdm_cb->message_counter == (COMMON_DATA_INTERVAL + 1))
{
page_number = p_sdm_cb->common_page_number;
p_sdm_cb->common_page_number = (p_sdm_cb->common_page_number == ANT_SDM_PAGE_80)
? ANT_SDM_PAGE_81 : ANT_SDM_PAGE_80;
p_sdm_cb->message_counter = 0;
}
else
{
if (p_sdm_cb->supp_page_control)
{
page_number = p_sdm_cb->supp_page_number;
}
else
{
page_number = ANT_SDM_PAGE_1;
}
if ((p_sdm_cb->message_counter % 2) == 1)
{
p_sdm_cb->supp_page_control = !p_sdm_cb->supp_page_control;
}
p_sdm_cb->message_counter++;
}
return page_number;
}
/**@brief Function for encoding SDM message.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_message_payload Pointer to the message payload.
*
* @note Assume to be call each time when Tx window will occur.
*/
static void sens_message_encode(ant_sdm_profile_t * p_profile, uint8_t * p_message_payload)
{
ant_sdm_message_layout_t * p_sdm_message_payload =
(ant_sdm_message_layout_t *)p_message_payload;
p_sdm_message_payload->page_number = next_page_number_get(p_profile);
NRF_LOG_INFO("SDM Page number: %u", p_sdm_message_payload->page_number);
switch (p_sdm_message_payload->page_number)
{
case ANT_SDM_PAGE_1:
ant_sdm_page_1_encode(p_sdm_message_payload->page_payload, &(p_profile->page_1),
&(p_profile->common));
ant_sdm_speed_encode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_2:
ant_sdm_page_2_encode(p_sdm_message_payload->page_payload, &(p_profile->page_2));
ant_sdm_speed_encode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_3:
ant_sdm_page_2_encode(p_sdm_message_payload->page_payload, &(p_profile->page_2));
ant_sdm_page_3_encode(p_sdm_message_payload->page_payload, &(p_profile->page_3));
ant_sdm_speed_encode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_16:
ant_sdm_page_16_encode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_22:
ant_sdm_page_22_encode(p_sdm_message_payload->page_payload, &(p_profile->page_22));
break;
case ANT_SDM_PAGE_80:
ant_common_page_80_encode(p_sdm_message_payload->page_payload, &(p_profile->page_80));
break;
case ANT_SDM_PAGE_81:
ant_common_page_81_encode(p_sdm_message_payload->page_payload, &(p_profile->page_81));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_sdm_evt_t)p_sdm_message_payload->page_number);
}
void ant_sdm_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ASSERT(p_context != NULL);
ASSERT(p_ant_evt != NULL);
ant_sdm_profile_t * p_profile = (ant_sdm_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
uint32_t err_code;
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
ant_sdm_sens_cb_t * p_sdm_cb = p_profile->_cb.p_sens_cb;
ant_request_controller_sens_evt_handler(&(p_sdm_cb->req_controller), p_ant_evt);
switch (p_ant_evt->event)
{
case EVENT_TX:
case EVENT_TRANSFER_TX_FAILED:
case EVENT_TRANSFER_TX_COMPLETED:
sens_message_encode(p_profile, p_message_payload);
if (ant_request_controller_ack_needed(&(p_sdm_cb->req_controller)))
{
err_code = sd_ant_acknowledge_message_tx(p_profile->channel_number,
sizeof(p_message_payload),
p_message_payload);
}
else
{
err_code = sd_ant_broadcast_message_tx(p_profile->channel_number,
sizeof(p_message_payload),
p_message_payload);
}
APP_ERROR_CHECK(err_code);
break;
default:
break;
}
}
}
ret_code_t ant_sdm_disp_open(ant_sdm_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
NRF_LOG_INFO("ANT SDM channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
ret_code_t ant_sdm_sens_open(ant_sdm_profile_t * p_profile)
{
ASSERT(p_profile != NULL);
// Fill tx buffer for the first frame
uint32_t err_code;
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
sens_message_encode(p_profile, p_message_payload);
err_code =
sd_ant_broadcast_message_tx(p_profile->channel_number,
sizeof(p_message_payload),
p_message_payload);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("ANT SDM channel %u open", p_profile->channel_number);
return sd_ant_channel_open(p_profile->channel_number);
}
/**@brief Function for decoding SDM message.
*
* @note Assume to be call each time when Rx window will occur.
*/
static void disp_message_decode(ant_sdm_profile_t * p_profile, uint8_t * p_message_payload)
{
const ant_sdm_message_layout_t * p_sdm_message_payload =
(ant_sdm_message_layout_t *)p_message_payload;
NRF_LOG_INFO("SDM Page number: %u", p_sdm_message_payload->page_number);
switch (p_sdm_message_payload->page_number)
{
case ANT_SDM_PAGE_1:
ant_sdm_page_1_decode(p_sdm_message_payload->page_payload,
&(p_profile->page_1),
&(p_profile->common));
ant_sdm_speed_decode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_3:
ant_sdm_page_3_decode(p_sdm_message_payload->page_payload, &(p_profile->page_3));
/* fall through */
case ANT_SDM_PAGE_2:
ant_sdm_page_2_decode(p_sdm_message_payload->page_payload, &(p_profile->page_2));
ant_sdm_speed_decode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_16:
ant_sdm_page_16_decode(p_sdm_message_payload->page_payload, &(p_profile->common));
break;
case ANT_SDM_PAGE_22:
ant_sdm_page_22_decode(p_sdm_message_payload->page_payload, &(p_profile->page_22));
break;
case ANT_SDM_PAGE_80:
ant_common_page_80_decode(p_sdm_message_payload->page_payload, &(p_profile->page_80));
break;
case ANT_SDM_PAGE_81:
ant_common_page_81_decode(p_sdm_message_payload->page_payload, &(p_profile->page_81));
break;
default:
return;
}
p_profile->evt_handler(p_profile, (ant_sdm_evt_t)p_sdm_message_payload->page_number);
}
void ant_sdm_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
ASSERT(p_context != NULL);
ASSERT(p_ant_evt != NULL);
ant_sdm_profile_t * p_profile = ( ant_sdm_profile_t *)p_context;
if (p_ant_evt->channel == p_profile->channel_number)
{
ant_sdm_disp_cb_t * p_sdm_cb = p_profile->_cb.p_disp_cb;
switch (ant_request_controller_disp_evt_handler(&(p_sdm_cb->req_controller), p_ant_evt))
{
case ANT_REQUEST_CONTROLLER_SUCCESS:
p_profile->evt_handler(p_profile, ANT_SDM_PAGE_REQUEST_SUCCESS);
break;
case ANT_REQUEST_CONTROLLER_FAILED:
p_profile->evt_handler(p_profile, ANT_SDM_PAGE_REQUEST_FAILED);
break;
default:
break;
}
switch (p_ant_evt->event)
{
case EVENT_RX:
if (p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
{
disp_message_decode(p_profile, p_ant_evt->message.ANT_MESSAGE_aucPayload);
}
break;
default:
break;
}
}
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,331 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup ant_sdm Stride Based Speed and Distance Monitor profile
* @{
* @ingroup ant_sdk_profiles
* @brief This module implements the Stride Based Speed and Distance Monitor profile.
*
*/
#ifndef ANT_SDM_H__
#define ANT_SDM_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_parameters.h"
#include "nrf_sdh_ant.h"
#include "ant_channel_config.h"
#include "ant_request_controller.h"
#include "ant_sdm_pages.h"
#include "sdk_errors.h"
#define SDM_DEVICE_TYPE 0x7Cu ///< Device type reserved for ANT+ SDM.
#define SDM_ANTPLUS_RF_FREQ 0x39u ///< Frequency, decimal 57 (2457 MHz).
#define SDM_MSG_PERIOD_4Hz 0x1FC6u ///< Message period, decimal 8134 (4.03 Hz).
#define SDM_MSG_PERIOD_2Hz 0x3F8Cu ///< Message period, decimal 16268 (2.01 Hz).
#define SDM_EXT_ASSIGN 0x00 ///< ANT ext assign (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
#define SDM_DISP_CHANNEL_TYPE CHANNEL_TYPE_SLAVE ///< RX SDM channel type.
#define SDM_SENS_CHANNEL_TYPE CHANNEL_TYPE_MASTER ///< TX SDM channel type.
/**@brief Initialize an ANT channel configuration structure for the SDM profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
* @param[in] SDM_MSG_PERIOD Channel period in 32 kHz counts. The SDM profile supports only the following periods:
* @ref SDM_MSG_PERIOD_4Hz, @ref SDM_MSG_PERIOD_2Hz.
*/
#define SDM_DISP_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER, \
SDM_MSG_PERIOD) \
static const ant_channel_config_t CONCAT_2(NAME,_channel_sdm_disp_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = SDM_DISP_CHANNEL_TYPE, \
.ext_assign = SDM_EXT_ASSIGN, \
.rf_freq = SDM_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = SDM_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = (SDM_MSG_PERIOD), \
.network_number = (NETWORK_NUMBER), \
}
#define SDM_DISP_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME,_channel_sdm_disp_config)
/**@brief Initialize an ANT channel configuration structure for the SDM profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
*/
#define SDM_SENS_CHANNEL_CONFIG_DEF(NAME, \
CHANNEL_NUMBER, \
TRANSMISSION_TYPE, \
DEVICE_NUMBER, \
NETWORK_NUMBER) \
static const ant_channel_config_t CONCAT_2(NAME,_channel_sdm_sens_config) = \
{ \
.channel_number = (CHANNEL_NUMBER), \
.channel_type = SDM_SENS_CHANNEL_TYPE, \
.ext_assign = SDM_EXT_ASSIGN, \
.rf_freq = SDM_ANTPLUS_RF_FREQ, \
.transmission_type = (TRANSMISSION_TYPE), \
.device_type = SDM_DEVICE_TYPE, \
.device_number = (DEVICE_NUMBER), \
.channel_period = SDM_MSG_PERIOD_4Hz, \
.network_number = (NETWORK_NUMBER), \
}
#define SDM_SENS_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME,_channel_sdm_sens_config)
/**@brief Initialize an ANT profile configuration structure for the SDM profile (Display).
*
* @param[in] NAME Name of related instance.
* @param[in] EVT_HANDLER Event handler to be called for handling events in the SDM profile.
*/
#define SDM_DISP_PROFILE_CONFIG_DEF(NAME, \
EVT_HANDLER) \
static ant_sdm_disp_cb_t CONCAT_2(NAME,_sdm_disp_cb); \
static const ant_sdm_disp_config_t CONCAT_2(NAME,_profile_sdm_disp_config) = \
{ \
.p_cb = &CONCAT_2(NAME,_sdm_disp_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define SDM_DISP_PROFILE_CONFIG(NAME) &CONCAT_2(NAME,_profile_sdm_disp_config)
/**@brief Initialize an ANT profile configuration structure for the SDM profile (Sensor).
*
* @param[in] NAME Name of related instance.
* @param[in] SUPPLEMENTARY_PAGE_NUMBER Supplementary data page (ANT_SDM_PAGE_2 or ANT_SDM_PAGE_3). Use ANT_SDM_PAGE_1 to disable.
* @param[in] EVT_HANDLER Event handler to be called for handling events in the SDM profile.
*/
#define SDM_SENS_PROFILE_CONFIG_DEF(NAME, \
SUPPLEMENTARY_PAGE_NUMBER, \
EVT_HANDLER) \
static ant_sdm_sens_cb_t CONCAT_2(NAME,_sdm_sens_cb); \
static const ant_sdm_sens_config_t CONCAT_2(NAME,_profile_sdm_sens_config) = \
{ \
.supplementary_page_number = (SUPPLEMENTARY_PAGE_NUMBER), \
.p_cb = &CONCAT_2(NAME,_sdm_sens_cb), \
.evt_handler = (EVT_HANDLER), \
}
#define SDM_SENS_PROFILE_CONFIG(NAME) &CONCAT_2(NAME,_profile_sdm_sens_config)
/**@brief SDM page number type. */
typedef enum{
ANT_SDM_PAGE_1 = 1, ///< Required data page 1.
ANT_SDM_PAGE_2 = 2, ///< Supplementary data page 2.
ANT_SDM_PAGE_3 = 3, ///< Supplementary data page 3.
ANT_SDM_PAGE_16 = 16, ///< Page 16 (sent on request).
ANT_SDM_PAGE_22 = 22, ///< Page 22 (sent on request).
ANT_SDM_PAGE_70 = ANT_COMMON_PAGE_70,
ANT_SDM_PAGE_80 = ANT_COMMON_PAGE_80,
ANT_SDM_PAGE_81 = ANT_COMMON_PAGE_81,
} ant_sdm_page_t;
/**@brief SDM profile event type. */
typedef enum{
ANT_SDM_PAGE_1_UPDATED = ANT_SDM_PAGE_1, ///< Data page 1 and speed have been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_2_UPDATED = ANT_SDM_PAGE_2, ///< Data page 2 and speed have been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_3_UPDATED = ANT_SDM_PAGE_3, ///< Data page 3 and speed have been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_16_UPDATED = ANT_SDM_PAGE_16, ///< Data page 16 has been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_22_UPDATED = ANT_SDM_PAGE_22, ///< Data page 22 has been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_80_UPDATED = ANT_SDM_PAGE_80, ///< Data page 80 has been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_81_UPDATED = ANT_SDM_PAGE_81, ///< Data page 81 has been updated (Display) or sent (Sensor).
ANT_SDM_PAGE_REQUEST_SUCCESS, ///< Data page request reached the destination.
ANT_SDM_PAGE_REQUEST_FAILED, ///< Data page request did not reach the destination.
} ant_sdm_evt_t;
// Forward declaration of the ant_sdm_profile_t type.
typedef struct ant_sdm_profile_s ant_sdm_profile_t;
/**@brief SDM event handler type. */
typedef void (* ant_sdm_evt_handler_t) (ant_sdm_profile_t *, ant_sdm_evt_t);
#include "ant_sdm_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief SDM Sensor configuration structure. */
typedef struct
{
ant_sdm_page_t supplementary_page_number; ///< Supplementary data page (ANT_SDM_PAGE_2 or ANT_SDM_PAGE_3). Use ANT_SDM_PAGE_1 to disable.
ant_sdm_sens_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_sdm_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the SDM profile.
} ant_sdm_sens_config_t;
/**@brief SDM Display configuration structure. */
typedef struct
{
ant_sdm_disp_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
ant_sdm_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the SDM profile.
} ant_sdm_disp_config_t;
/**@brief SDM profile structure. */
struct ant_sdm_profile_s
{
uint8_t channel_number; ///< Channel number assigned to the profile.
union {
ant_sdm_disp_cb_t * p_disp_cb;
ant_sdm_sens_cb_t * p_sens_cb;
} _cb; ///< Pointer to internal control block.
ant_sdm_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the SDM profile.
ant_sdm_page1_data_t page_1; ///< Page 1.
ant_sdm_page2_data_t page_2; ///< Page 2.
ant_sdm_page3_data_t page_3; ///< Page 3.
ant_sdm_page22_data_t page_22; ///< Page 22.
ant_common_page80_data_t page_80; ///< Page 80.
ant_common_page81_data_t page_81; ///< Page 81.
ant_sdm_common_data_t common; ///< SDM common data.
};
/** @name Defines for accessing ant_sdm_profile_t members variables
@{ */
#define SDM_PROFILE_update_latency page_1.update_latency
#define SDM_PROFILE_time page_1.time
#define SDM_PROFILE_status page_2.status.items
#define SDM_PROFILE_cadence page_2.cadence
#define SDM_PROFILE_calories page_3.calories
#define SDM_PROFILE_capabilities page_22.capabilities.items
#define SDM_PROFILE_speed common.speed
#define SDM_PROFILE_distance common.distance
#define SDM_PROFILE_strides common.strides
#define SDM_PROFILE_hw_revision page_80.hw_revision
#define SDM_PROFILE_manufacturer_id page_80.manufacturer_id
#define SDM_PROFILE_model_number page_80.model_number
#define SDM_PROFILE_sw_revision_minor page_81.sw_revision_minor
#define SDM_PROFILE_sw_revision_major page_81.sw_revision_major
#define SDM_PROFILE_serial_number page_81.serial_number
/** @} */
/**@brief Function for initializing the ANT SDM RX profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_disp_config Pointer to the SDM Display configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_sdm_disp_init(ant_sdm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_sdm_disp_config_t const * p_disp_config);
/**@brief Function for initializing the ANT SDM TX profile instance.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
* @param[in] p_sens_config Pointer to the SDM Sensor configuration structure.
*
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
*/
ret_code_t ant_sdm_sens_init(ant_sdm_profile_t * p_profile,
ant_channel_config_t const * p_channel_config,
ant_sdm_sens_config_t const * p_sens_config);
/**@brief Function for opening the profile instance channel for ANT SDM Display.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_sdm_disp_open(ant_sdm_profile_t * p_profile);
/**@brief Function for opening the profile instance channel for ANT SDM Sensor.
*
* Before calling this function, pages should be configured.
*
* @param[in] p_profile Pointer to the profile instance.
*
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
*/
ret_code_t ant_sdm_sens_open(ant_sdm_profile_t * p_profile);
/**@brief Function for sending a data page request.
*
* This function can be called only on the display side.
*
* @param[in] p_profile Pointer to the profile instance.
* @param[in] p_page_70 Pointer to the prepared page 70.
*
* @retval NRF_SUCCESS If the request has been sent. Otherwise, an error code is returned.
*/
ret_code_t ant_sdm_page_request(ant_sdm_profile_t * p_profile, ant_common_page70_data_t * p_page_70);
/**@brief Function for handling the Sensor ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the SDM Sensor profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_sdm_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
/**@brief Function for handling the Display ANT events.
*
* @details This function handles all events from the ANT stack that are of interest to the SDM Display profile.
*
* @param[in] p_ant_evt Event received from the ANT stack.
* @param[in] p_context Pointer to the profile instance.
*/
void ant_sdm_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_H__
/** @} */

View file

@ -0,0 +1,81 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_LOCAL_H__
#define ANT_SDM_LOCAL_H__
#include <stdint.h>
#include <stdbool.h>
#include "ant_sdm.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup ant_sdm
* @{
*/
/** @brief SDM Display control block. */
typedef struct
{
ant_request_controller_t req_controller;
}ant_sdm_disp_cb_t;
/**@brief SDM Sensor control block. */
typedef struct
{
uint8_t supp_page_control;
ant_sdm_page_t supp_page_number;
ant_sdm_page_t common_page_number;
uint8_t message_counter;
ant_request_controller_t req_controller;
}ant_sdm_sens_cb_t;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_LOCAL_H__

View file

@ -0,0 +1,104 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_common_data.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM common page data layout structure. */
typedef struct
{
uint8_t reserved0[3];
uint8_t speed_integer :4;
uint8_t reserved1 :4;
uint8_t speed_fractional;
uint8_t reserved2[2];
}ant_sdm_speed_data_layout_t;
/**@brief Function for tracing common data.
*
* @param[in] p_common_data Pointer to the common data.
*/
static void speed_data_log(ant_sdm_common_data_t const * p_common_data)
{
uint32_t speed = ANT_SDM_SPEED_RESCALE(p_common_data->speed);
UNUSED_VARIABLE(speed);
NRF_LOG_INFO("Speed %u.%02u m/s\r\n\n",
(unsigned int)(speed / ANT_SDM_SPEED_DISP_PRECISION),
(unsigned int)(speed % ANT_SDM_SPEED_DISP_PRECISION));
}
void ant_sdm_speed_encode(uint8_t * p_page_buffer,
ant_sdm_common_data_t const * p_common_data)
{
ant_sdm_speed_data_layout_t * p_outcoming_data = (ant_sdm_speed_data_layout_t *)p_page_buffer;
uint16_t speed = p_common_data->speed;
p_outcoming_data->speed_integer = speed / ANT_SDM_SPEED_UNIT_REVERSAL;
p_outcoming_data->speed_fractional = speed % ANT_SDM_SPEED_UNIT_REVERSAL;
speed_data_log(p_common_data);
}
void ant_sdm_speed_decode(uint8_t const * p_page_buffer,
ant_sdm_common_data_t * p_common_data)
{
ant_sdm_speed_data_layout_t const * p_incoming_data = (ant_sdm_speed_data_layout_t *)p_page_buffer;
uint16_t speed = (p_incoming_data->speed_integer
* ANT_SDM_SPEED_UNIT_REVERSAL)
+ p_incoming_data->speed_fractional;
p_common_data->speed = speed;
speed_data_log(p_common_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,103 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_COMMON_DATA_H__
#define ANT_SDM_COMMON_DATA_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_common_data_page Stride Based Speed and Distance Monitor profile common data
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for SDM common data.
*
* @details This structure stores data that is not associated with a particular page.
*/
typedef struct
{
uint16_t speed; ///< Actual speed.
uint32_t distance; ///< Accumulated distance.
uint32_t strides; ///< Accumulated strides.
} ant_sdm_common_data_t;
/**@brief Initialize common data.
*/
#define DEFAULT_ANT_SDM_COMMON_DATA() \
(ant_sdm_common_data_t) \
{ \
.speed = 0, \
.distance = 0, \
.strides = 0, \
}
/**@brief Function for encoding speed.
*
* This function can be used for pages 2 and 3.
*
* @param[in] p_common_data Pointer to the common data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_speed_encode(uint8_t * p_page_buffer,
ant_sdm_common_data_t const * p_common_data);
/**@brief Function for decoding speed.
*
* This function can be used for pages 2 and 3.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_common_data Pointer to the common data.
*/
void ant_sdm_speed_decode(uint8_t const * p_page_buffer,
ant_sdm_common_data_t * p_common_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_COMMON_DATA_H__
/** @} */

View file

@ -0,0 +1,144 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_page_1.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM page 1 data layout structure. */
typedef struct
{
uint8_t time_fractional;
uint8_t time_integer;
uint8_t distance_integer;
uint8_t reserved0 : 4;
uint8_t distance_fractional : 4;
uint8_t reserved1;
uint8_t strides;
uint8_t update_latency;
}ant_sdm_page1_data_layout_t;
STATIC_ASSERT(ANT_SDM_UPDATE_LATENCY_DISP_PRECISION == 1000); ///< Display format need to be updated
STATIC_ASSERT(ANT_SDM_TIME_DISP_PRECISION == 1000); ///< Display format need to be updated
STATIC_ASSERT(ANT_SDM_DISTANCE_DISP_PRECISION == 10); ///< Display format need to be updated
/**@brief Function for tracing page 1 and common data.
*
* @param[in] p_common_data Pointer to the common data.
* @param[in] p_page_data Pointer to the page 1 data.
*/
static void page_1_data_log(ant_sdm_page1_data_t const * p_page_data,
ant_sdm_common_data_t const * p_common_data)
{
uint32_t strides = p_common_data->strides;
uint64_t distance = ANT_SDM_DISTANCE_RESCALE(p_common_data->distance);
uint16_t update_latency = ANT_SDM_UPDATE_LATENCY_RESCALE(p_page_data->update_latency);
uint32_t time = ANT_SDM_TIME_RESCALE(p_page_data->time);
NRF_LOG_INFO("Update latency %u.%03u s",
update_latency / ANT_SDM_UPDATE_LATENCY_DISP_PRECISION,
update_latency % ANT_SDM_UPDATE_LATENCY_DISP_PRECISION);
NRF_LOG_INFO("Time %u.%03u s",
(unsigned int)(time / ANT_SDM_TIME_DISP_PRECISION),
(unsigned int)(time % ANT_SDM_TIME_DISP_PRECISION));
NRF_LOG_INFO("Distance %u.%01um ",
(unsigned int)(distance / ANT_SDM_DISTANCE_DISP_PRECISION),
(unsigned int)(distance % ANT_SDM_DISTANCE_DISP_PRECISION));
NRF_LOG_INFO("Strides %u", (unsigned int)strides);
}
void ant_sdm_page_1_encode(uint8_t * p_page_buffer,
ant_sdm_page1_data_t const * p_page_data,
ant_sdm_common_data_t const * p_common_data)
{
ant_sdm_page1_data_layout_t * p_outcoming_data = (ant_sdm_page1_data_layout_t *)p_page_buffer;
uint32_t distance = p_common_data->distance;
uint16_t time = p_page_data->time;
p_outcoming_data->time_fractional = time % ANT_SDM_TIME_UNIT_REVERSAL;
p_outcoming_data->time_integer = time / ANT_SDM_TIME_UNIT_REVERSAL;
p_outcoming_data->distance_integer =
(UINT8_MAX & (distance / ANT_SDM_DISTANCE_UNIT_REVERSAL)); // Only LSB
p_outcoming_data->distance_fractional = distance % ANT_SDM_DISTANCE_UNIT_REVERSAL;
p_outcoming_data->strides = (UINT8_MAX & p_common_data->strides); // Only LSB
p_outcoming_data->update_latency = p_page_data->update_latency;
page_1_data_log(p_page_data, p_common_data);
}
void ant_sdm_page_1_decode(uint8_t const * p_page_buffer,
ant_sdm_page1_data_t * p_page_data,
ant_sdm_common_data_t * p_common_data)
{
ant_sdm_page1_data_layout_t const * p_incoming_data =
(ant_sdm_page1_data_layout_t *)p_page_buffer;
uint16_t distance = p_incoming_data->distance_integer * ANT_SDM_DISTANCE_UNIT_REVERSAL
+ p_incoming_data->distance_fractional;
uint16_t time = p_incoming_data->time_integer * ANT_SDM_TIME_UNIT_REVERSAL
+ p_incoming_data->time_fractional;
uint8_t prev_strides = p_common_data->strides;
p_common_data->strides += ((p_incoming_data->strides - prev_strides) & UINT8_MAX);
uint16_t prev_distance = p_common_data->distance;
p_common_data->distance += ((distance - prev_distance) & 0xFFF);
p_page_data->update_latency = p_incoming_data->update_latency;
p_page_data->time = time;
p_page_data->strides = p_incoming_data->strides;
page_1_data_log(p_page_data, p_common_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,101 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_PAGE_1_H__
#define ANT_SDM_PAGE_1_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_page1 Stride Based Speed and Distance Monitor profile page 1
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#include "ant_sdm_common_data.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for SDM data page 1.
*/
typedef struct
{
uint8_t update_latency; ///< Update latency.
uint8_t strides; ///< Strides (writing to this field has no effect).
uint16_t time; ///< Time.
} ant_sdm_page1_data_t;
/**@brief Initialize page 1.
*/
#define DEFAULT_ANT_SDM_PAGE1() \
(ant_sdm_page1_data_t) \
{ \
.update_latency = 0, \
.time = 0, \
}
/**@brief Function for encoding page 1.
*
* @param[in] p_page_data Pointer to the page data.
* @param[in] p_common_data Pointer to the common data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_page_1_encode(uint8_t * p_page_buffer,
ant_sdm_page1_data_t const * p_page_data,
ant_sdm_common_data_t const * p_common_data);
/**@brief Function for decoding page 1.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
* @param[out] p_common_data Pointer to the common data.
*/
void ant_sdm_page_1_decode(uint8_t const * p_page_buffer,
ant_sdm_page1_data_t * p_page_data,
ant_sdm_common_data_t * p_common_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_PAGE_1_H__
/** @} */

View file

@ -0,0 +1,104 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_page_16.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM page 16 data layout structure. */
typedef struct
{
uint8_t strides[3];
uint8_t distance[4];
}ant_sdm_page16_data_layout_t;
STATIC_ASSERT(ANT_SDM_DISTANCE_DISP_PRECISION == 10); ///< Display format need to be updated
/**@brief Function for tracing common data.
*
* @param[in] p_common_data Pointer to the common data.
*/
static void page_16_data_log(ant_sdm_common_data_t const * p_common_data)
{
uint64_t distance = ANT_SDM_DISTANCE_RESCALE(p_common_data->distance);
NRF_LOG_INFO("Distance %u.%01u m",
(unsigned int)(distance / ANT_SDM_DISTANCE_DISP_PRECISION),
(unsigned int)(distance % ANT_SDM_DISTANCE_DISP_PRECISION));
NRF_LOG_INFO("Strides %u\r\n\n",
(unsigned int)p_common_data->strides);
}
void ant_sdm_page_16_encode(uint8_t * p_page_buffer,
ant_sdm_common_data_t const * p_common_data)
{
ant_sdm_page16_data_layout_t * p_outcoming_data = (ant_sdm_page16_data_layout_t *)p_page_buffer;
UNUSED_PARAMETER(uint24_encode(p_common_data->strides, p_outcoming_data->strides));
UNUSED_PARAMETER(uint32_encode(p_common_data->distance << 4, p_outcoming_data->distance));
page_16_data_log(p_common_data);
}
void ant_sdm_page_16_decode(uint8_t const * p_page_buffer,
ant_sdm_common_data_t * p_common_data)
{
ant_sdm_page16_data_layout_t const * p_incoming_data =
(ant_sdm_page16_data_layout_t *)p_page_buffer;
p_common_data->strides = uint24_decode(p_incoming_data->strides);
p_common_data->distance = uint32_decode(p_incoming_data->distance) >> 4;
page_16_data_log(p_common_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,79 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_PAGE_16_H__
#define ANT_SDM_PAGE_16_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_page16 Stride Based Speed and Distance Monitor profile page 16
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#include "ant_sdm_common_data.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Function for encoding page 16.
*
* @param[in] p_common_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_page_16_encode(uint8_t * p_page_buffer,
ant_sdm_common_data_t const * p_common_data);
/**@brief Function for decoding page 16.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_common_data Pointer to the page data.
*/
void ant_sdm_page_16_decode(uint8_t const * p_page_buffer,
ant_sdm_common_data_t * p_common_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_PAGE_16_H__
/** @} */

View file

@ -0,0 +1,128 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_page_2.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM page 2 data layout structure. */
typedef struct
{
uint8_t reserved0[2];
uint8_t cadence_integer;
uint8_t reserved1 : 4;
uint8_t cadence_fractional : 4;
uint8_t reserved2;
uint8_t reserved3;
uint8_t status;
}ant_sdm_page2_data_layout_t;
/**@brief Function for page 2 data.
*
* @param[in] p_common_data Pointer to the page 2 data.
*/
static void page_2_data_log(ant_sdm_page2_data_t const * p_page_data)
{
static const char * p_location[4] = {"Laces", "Midsole", "Other", "Ankle"};
static const char * p_battery[4] = {"New", "Good", "OK", "Low"};
static const char * p_health[4] = {"OK", "Error", "Warning", ""};
static const char * p_state[4] = {"Inactive", "Active", "", ""};
uint16_t cadence = ANT_SDM_CADENCE_RESCALE(p_page_data->cadence);
NRF_LOG_INFO("Status:");
NRF_LOG_INFO("state: %s",
(uint32_t)p_state[p_page_data->status.items.state]);
NRF_LOG_INFO("health: %s",
(uint32_t)p_health[p_page_data->status.items.health]);
NRF_LOG_INFO("battery: %s",
(uint32_t)p_battery[p_page_data->status.items.battery]);
NRF_LOG_INFO("location: %s",
(uint32_t)p_location[p_page_data->status.items.location]);
NRF_LOG_INFO("Cadence %u.%01u strides/min",
cadence / ANT_SDM_CADENCE_DISP_PRECISION,
cadence % ANT_SDM_CADENCE_DISP_PRECISION);
}
void ant_sdm_page_2_encode(uint8_t * p_page_buffer,
ant_sdm_page2_data_t const * p_page_data)
{
ant_sdm_page2_data_layout_t * p_outcoming_data = (ant_sdm_page2_data_layout_t *)p_page_buffer;
uint8_t status = p_page_data->status.byte;
uint16_t cadence = p_page_data->cadence;
p_outcoming_data->reserved0[0] = UINT8_MAX;
p_outcoming_data->reserved0[1] = UINT8_MAX;
p_outcoming_data->cadence_integer = cadence / ANT_SDM_CADENCE_UNIT_REVERSAL;
p_outcoming_data->cadence_fractional = cadence % ANT_SDM_CADENCE_UNIT_REVERSAL;
p_outcoming_data->reserved3 = UINT8_MAX;
p_outcoming_data->status = status;
page_2_data_log(p_page_data);
}
void ant_sdm_page_2_decode(uint8_t const * p_page_buffer,
ant_sdm_page2_data_t * p_page_data)
{
ant_sdm_page2_data_layout_t const * p_incoming_data =
(ant_sdm_page2_data_layout_t *)p_page_buffer;
uint8_t status = p_incoming_data->status;
uint16_t cadence = p_incoming_data->cadence_integer * ANT_SDM_CADENCE_UNIT_REVERSAL
+ p_incoming_data->cadence_fractional;
p_page_data->cadence = cadence;
p_page_data->status.byte = status;
page_2_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,129 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_PAGE_2_H__
#define ANT_SDM_PAGE_2_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_page2 Stride Based Speed and Distance Monitor profile page 2
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for SDM data page 2.
*/
typedef struct
{
union
{
struct
{
enum
{
ANT_SDM_USE_STATE_INACTIVE = 0x00,
ANT_SDM_USE_STATE_ACTIVE = 0x01,
ANT_SDM_STATE_RESERVED0 = 0x02,
ANT_SDM_STATE_RESERVED1 = 0x03,
} state : 2; ///< Use state.
enum
{
ANT_SDM_HEALTH_OK = 0x00,
ANT_SDM_HEALTH_ERROR = 0x01,
ANT_SDM_HEALTH_WARNING = 0x02,
ANT_SDM_HEALTH_RESERVED = 0x03,
} health : 2; ///< SDM health.
enum
{
ANT_SDM_BATTERY_STATUS_NEW = 0x00,
ANT_SDM_BATTERY_STATUS_GOOD = 0x01,
ANT_SDM_BATTERY_STATUS_OK = 0x02,
ANT_SDM_BATTERY_STATUS_LOW = 0x03,
} battery : 2; ///< Battery status.
enum
{
ANT_SDM_LOCATION_LACES = 0x00,
ANT_SDM_LOCATION_MIDSOLE = 0x01,
ANT_SDM_LOCATION_OTHER = 0x02,
ANT_SDM_LOCATION_ANKLE = 0x03,
} location : 2; ///< Location of the SDM sensor.
} items;
uint8_t byte;
} status; ///< Actual status.
uint16_t cadence; ///< Actual cadence.
} ant_sdm_page2_data_t;
/**@brief Initialize page 2.
*/
#define DEFAULT_ANT_SDM_PAGE2() \
(ant_sdm_page2_data_t) \
{ \
.status.byte = 0, \
.cadence = 0, \
}
/**@brief Function for encoding page 2.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_page_2_encode(uint8_t * p_page_buffer,
ant_sdm_page2_data_t const * p_page_data);
/**@brief Function for decoding page 2.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_sdm_page_2_decode(uint8_t const * p_page_buffer,
ant_sdm_page2_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_PAGE_2_H__
/** @} */

View file

@ -0,0 +1,127 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include <string.h>
#include "ant_sdm_page_22.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM page 22 data layout structure. */
typedef struct
{
uint8_t capabilities;
uint8_t reserved[6];
}ant_sdm_page22_data_layout_t;
/**@brief Function for tracing page 22 data.
*
* @param[in] p_page_data Pointer to the page 22 data.
*/
static void page_22_data_log(ant_sdm_page22_data_t const * p_page_data)
{
NRF_LOG_INFO("Capabilities: ");
if (p_page_data->capabilities.items.time_is_valid)
{
NRF_LOG_RAW_INFO(" time");
}
if (p_page_data->capabilities.items.distance_is_valid)
{
NRF_LOG_RAW_INFO(" distance");
}
if (p_page_data->capabilities.items.speed_is_valid)
{
NRF_LOG_RAW_INFO(" speed");
}
if (p_page_data->capabilities.items.latency_is_valid)
{
NRF_LOG_RAW_INFO(" latency");
}
if (p_page_data->capabilities.items.cadency_is_valid)
{
NRF_LOG_RAW_INFO(" cadence");
}
if (p_page_data->capabilities.items.calorie_is_valid)
{
NRF_LOG_RAW_INFO(" calories");
}
NRF_LOG_RAW_INFO("\r\n\n");
}
void ant_sdm_page_22_encode(uint8_t * p_page_buffer,
ant_sdm_page22_data_t const * p_page_data)
{
ant_sdm_page22_data_layout_t * p_outcoming_data = (ant_sdm_page22_data_layout_t *)p_page_buffer;
p_outcoming_data->capabilities = p_page_data->capabilities.byte;
memset(p_outcoming_data->reserved, UINT8_MAX, sizeof (p_outcoming_data->reserved));
page_22_data_log(p_page_data);
}
void ant_sdm_page_22_decode(uint8_t const * p_page_buffer,
ant_sdm_page22_data_t * p_page_data)
{
ant_sdm_page22_data_layout_t const * p_incoming_data =
(ant_sdm_page22_data_layout_t *)p_page_buffer;
p_page_data->capabilities.byte = p_incoming_data->capabilities;
page_22_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,106 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_PAGE_22_H__
#define ANT_SDM_PAGE_22_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_page22 Stride Based Speed and Distance Monitor profile page 22
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for SDM data page 22.
*/
typedef struct
{
union
{
struct
{
bool time_is_valid : 1; ///< Transmitted time is valid.
bool distance_is_valid : 1; ///< Transmitted distance is valid.
bool speed_is_valid : 1; ///< Transmitted speed is valid.
bool latency_is_valid : 1; ///< Transmitted latency is valid.
bool cadency_is_valid : 1; ///< Transmitted cadency is valid.
bool calorie_is_valid : 1; ///< Transmitted calorie is valid.
} items;
uint8_t byte;
} capabilities;
} ant_sdm_page22_data_t;
/**@brief Initialize page 2.
*/
#define DEFAULT_ANT_SDM_PAGE22() \
(ant_sdm_page22_data_t) \
{ \
.capabilities.byte = 0, \
}
/**@brief Function for encoding page 22.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_page_22_encode(uint8_t * p_page_buffer,
ant_sdm_page22_data_t const * p_page_data);
/**@brief Function for decoding page 22.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_sdm_page_22_decode(uint8_t const * p_page_buffer,
ant_sdm_page22_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_PAGE_22_H__
/** @} */

View file

@ -0,0 +1,92 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_page_3.h"
#include "ant_sdm_utils.h"
#define NRF_LOG_MODULE_NAME ant_sdm
#if ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL ANT_SDM_LOG_LEVEL
#define NRF_LOG_INFO_COLOR ANT_SDM_INFO_COLOR
#else // ANT_SDM_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif // ANT_SDM_LOG_ENABLED
#include "nrf_log.h"
/**@brief SDM page 3 data layout structure. */
typedef struct
{
uint8_t reserved0[5];
uint8_t calories;
uint8_t reserved1;
}ant_sdm_page3_data_layout_t;
static void page_3_data_log(ant_sdm_page3_data_t const * p_page_data)
{
NRF_LOG_INFO("Calories: %u\r\n\n", p_page_data->calories);
}
void ant_sdm_page_3_encode(uint8_t * p_page_buffer,
ant_sdm_page3_data_t const * p_page_data)
{
ant_sdm_page3_data_layout_t * p_outcoming_data = (ant_sdm_page3_data_layout_t *)p_page_buffer;
p_outcoming_data->calories = p_page_data->calories;
page_3_data_log(p_page_data);
}
void ant_sdm_page_3_decode(uint8_t const * p_page_buffer,
ant_sdm_page3_data_t * p_page_data)
{
ant_sdm_page3_data_layout_t const * p_incoming_data =
(ant_sdm_page3_data_layout_t *)p_page_buffer;
uint8_t prev_calories = (uint8_t) p_page_data->calories;
p_page_data->calories += ((p_incoming_data->calories - prev_calories) & UINT8_MAX);
page_3_data_log(p_page_data);
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,93 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_PAGE_3_H__
#define ANT_SDM_PAGE_3_H__
/** @file
*
* @defgroup ant_sdk_profiles_sdm_page3 Stride Based Speed and Distance Monitor profile page 3
* @{
* @ingroup ant_sdk_profiles_sdm_pages
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Data structure for SDM data page 3.
*/
typedef struct
{
uint32_t calories; ///< Calories.
} ant_sdm_page3_data_t;
/**@brief Initialize page 3.
*/
#define DEFAULT_ANT_SDM_PAGE3() \
(ant_sdm_page3_data_t) \
{ \
.calories = 0, \
}
/**@brief Function for encoding page 3.
*
* @param[in] p_page_data Pointer to the page data.
* @param[out] p_page_buffer Pointer to the data buffer.
*/
void ant_sdm_page_3_encode(uint8_t * p_page_buffer,
ant_sdm_page3_data_t const * p_page_data);
/**@brief Function for decoding page 3.
*
* @param[in] p_page_buffer Pointer to the data buffer.
* @param[out] p_page_data Pointer to the page data.
*/
void ant_sdm_page_3_decode(uint8_t const * p_page_buffer,
ant_sdm_page3_data_t * p_page_data);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_PAGE_3_H__
/** @} */

View file

@ -0,0 +1,70 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __ANT_SDM_PAGES_H
#define __ANT_SDM_PAGES_H
/** @file
*
* @defgroup ant_sdk_profiles_sdm_pages Stride Based Speed and Distance Monitor profile pages
* @{
* @ingroup ant_sdm
* @brief This module implements functions for the SDM data pages.
*/
#include "ant_sdm_page_1.h"
#include "ant_sdm_page_2.h"
#include "ant_sdm_page_3.h"
#include "ant_sdm_page_16.h"
#include "ant_sdm_page_22.h"
#include "ant_sdm_common_data.h"
#include "ant_common_page_70.h"
#include "ant_common_page_80.h"
#include "ant_common_page_81.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // __ANT_SDM_PAGES_H
/** @} */

View file

@ -0,0 +1,159 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(ANT_SDM)
#include "ant_sdm_simulator.h"
#include "ant_sdm_utils.h"
#define SIMULATOR_STRIDE_LENGTH_UNIT_REVERSAL 100 ///< Stride length unit is cm.
#define SIMULATOR_BURN_RATE_UNIT 1000 ///< Burn rate uinit is kcal per km.
#define SIMULATOR_TIME_INCREMENT SDM_MSG_PERIOD_4Hz ///< Ticks between two cycles.
#define SIMULATOR_TIME_UNIT_REVERSAL ANT_CLOCK_FREQUENCY ///< Simulation time frequency.
#define SEC_PER_MIN 60 ///< Number of seconds per minute.
#define SIMULATOR_STRIDE_UNIT_REVERSAL (SIMULATOR_TIME_UNIT_REVERSAL * \
ANT_SDM_CADENCE_UNIT_REVERSAL * SEC_PER_MIN)
void ant_sdm_simulator_init(ant_sdm_simulator_t * p_simulator,
ant_sdm_simulator_cfg_t const * p_config,
bool auto_change)
{
p_simulator->p_profile = p_config->p_profile;
p_simulator->_cb.stride_length = p_config->stride_length;
p_simulator->_cb.burn_rate = p_config->burn_rate;
p_simulator->_cb.sensorsim_cfg = p_config->sensorsim_cfg;
p_simulator->_cb.auto_change = auto_change;
p_simulator->_cb.sensorsim_state.current_val = p_simulator->_cb.sensorsim_cfg.min;
p_simulator->_cb.stride_incr = 0;
p_simulator->_cb.time = 0;
sensorsim_init(&(p_simulator->_cb.sensorsim_state), &(p_simulator->_cb.sensorsim_cfg));
}
void ant_sdm_simulator_one_iteration(ant_sdm_simulator_t * p_simulator)
{
if (p_simulator->_cb.auto_change)
{
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg)));
}
p_simulator->_cb.time += SIMULATOR_TIME_INCREMENT;
p_simulator->_cb.stride_incr += p_simulator->_cb.sensorsim_state.current_val *
SIMULATOR_TIME_INCREMENT;
p_simulator->p_profile->SDM_PROFILE_strides += p_simulator->_cb.stride_incr /
SIMULATOR_STRIDE_UNIT_REVERSAL;
p_simulator->_cb.stride_incr = p_simulator->_cb.stride_incr %
SIMULATOR_STRIDE_UNIT_REVERSAL;
uint32_t distance = value_rescale(
p_simulator->p_profile->SDM_PROFILE_strides * p_simulator->_cb.stride_length,
SIMULATOR_STRIDE_LENGTH_UNIT_REVERSAL,
ANT_SDM_DISTANCE_UNIT_REVERSAL);
if (p_simulator->p_profile->SDM_PROFILE_capabilities.cadency_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_cadence = p_simulator->_cb.sensorsim_state.current_val;
}
if (p_simulator->p_profile->SDM_PROFILE_capabilities.speed_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_speed = value_rescale(
p_simulator->_cb.sensorsim_state.current_val * p_simulator->_cb.stride_length,
ANT_SDM_CADENCE_UNIT_REVERSAL * SIMULATOR_STRIDE_LENGTH_UNIT_REVERSAL * SEC_PER_MIN,
ANT_SDM_SPEED_UNIT_REVERSAL);
}
if (p_simulator->p_profile->SDM_PROFILE_capabilities.distance_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_distance = distance;
}
if (p_simulator->p_profile->SDM_PROFILE_capabilities.calorie_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_calories = value_rescale(distance,
SIMULATOR_BURN_RATE_UNIT
* ANT_SDM_DISTANCE_UNIT_REVERSAL,
p_simulator->_cb.burn_rate);
}
if (p_simulator->p_profile->SDM_PROFILE_capabilities.time_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_time = value_rescale(p_simulator->_cb.time,
SIMULATOR_TIME_UNIT_REVERSAL,
ANT_SDM_TIME_UNIT_REVERSAL);
}
if (p_simulator->p_profile->SDM_PROFILE_capabilities.latency_is_valid)
{
p_simulator->p_profile->SDM_PROFILE_update_latency =
ROUNDED_DIV(((uint64_t)p_simulator->_cb.stride_incr *
ANT_SDM_UPDATE_LATENCY_UNIT_REVERSAL),
(uint64_t)SIMULATOR_TIME_UNIT_REVERSAL *
p_simulator->_cb.sensorsim_state.current_val);
}
}
void ant_sdm_simulator_increment(ant_sdm_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_increment(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg));
}
}
void ant_sdm_simulator_decrement(ant_sdm_simulator_t * p_simulator)
{
if (!p_simulator->_cb.auto_change)
{
sensorsim_decrement(&(p_simulator->_cb.sensorsim_state),
&(p_simulator->_cb.sensorsim_cfg));
}
}
#endif // NRF_MODULE_ENABLED(ANT_SDM)

View file

@ -0,0 +1,139 @@
/**
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANT_SDM_SIMULATOR_H__
#define ANT_SDM_SIMULATOR_H__
/** @file
*
* @defgroup ant_sdk_sdm_simulator ANT SDM simulator
* @{
* @ingroup ant_sdk_simulators
* @brief ANT SDM simulator module.
*
* @details This module simulates strides for the ANT SDM profile. The module calculates
* abstract values, which are handled by the SDM pages data model to ensure that they are
* compatible. It provides a handler for changing the cadence value manually and functionality
* for changing the cadence automatically.
*
*/
#include <stdint.h>
#include <stdbool.h>
#include "ant_sdm.h"
#include "ant_sdm_utils.h"
#include "sensorsim.h"
#include "ant_sdm_simulator_local.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief SDM simulator configuration structure. */
typedef struct
{
ant_sdm_profile_t * p_profile; ///< Related profile.
uint32_t stride_length; ///< Length of a stride in cm.
uint32_t burn_rate; ///< Kcal per kilometer.
sensorsim_cfg_t sensorsim_cfg; ///< Sensorsim configuration.
} ant_sdm_simulator_cfg_t;
/**@brief Initialize @ref ant_sdm_simulator_cfg_t.
*/
#define DEFAULT_ANT_SDM_SIMULATOR_CFG(P_PROFILE, \
STRIDE_LEN, \
BURN_RATE, \
MIN_CADENCE, \
MAX_CADENCE, \
INCREMENT) \
{ \
.p_profile = (P_PROFILE), \
.stride_length = (STRIDE_LEN), \
.burn_rate = (BURN_RATE), \
.sensorsim_cfg.min = (MIN_CADENCE) *(ANT_SDM_CADENCE_UNIT_REVERSAL), \
.sensorsim_cfg.max = (MAX_CADENCE) *(ANT_SDM_CADENCE_UNIT_REVERSAL), \
.sensorsim_cfg.incr = (INCREMENT) *(ANT_SDM_CADENCE_UNIT_REVERSAL), \
.sensorsim_cfg.start_at_max = false, \
}
/**@brief SDM simulator structure. */
typedef struct
{
ant_sdm_profile_t * p_profile; ///< Related profile.
ant_sdm_simulator_cb_t _cb; ///< Internal control block.
} ant_sdm_simulator_t;
/**@brief Function for initializing the ANT SDM simulator instance.
*
* @param[in] p_simulator Pointer to the simulator instance.
* @param[in] p_config Pointer to the simulator configuration structure.
* @param[in] auto_change Enable or disable automatic changes of the cadence.
*/
void ant_sdm_simulator_init(ant_sdm_simulator_t * p_simulator,
ant_sdm_simulator_cfg_t const * p_config,
bool auto_change);
/**@brief Function for simulating a device event.
*
* @details Based on this event, the transmitter data is simulated.
*
* This function should be called in the SDM TX event handler.
*/
void ant_sdm_simulator_one_iteration(ant_sdm_simulator_t * p_simulator);
/**@brief Function for incrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_sdm_simulator_increment(ant_sdm_simulator_t * p_simulator);
/**@brief Function for decrementing the cadence value.
*
* @param[in] p_simulator Pointer to the simulator instance.
*/
void ant_sdm_simulator_decrement(ant_sdm_simulator_t * p_simulator);
#ifdef __cplusplus
}
#endif
#endif // ANT_SDM_SIMULATOR_H__
/** @} */

Some files were not shown because too many files have changed in this diff Show more