diff options
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc')
22 files changed, 2952 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.c new file mode 100644 index 0000000..1f356c5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.c @@ -0,0 +1,422 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.h new file mode 100644 index 0000000..26f053d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc.h @@ -0,0 +1,359 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc_local.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc_local.h new file mode 100644 index 0000000..44c64cc --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/ant_bsc_local.h @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2015 - 2018, 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__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.c new file mode 100644 index 0000000..4ac5c62 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.c @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.h new file mode 100644 index 0000000..b1e5fef --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_combined_page_0.h @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.c new file mode 100644 index 0000000..3122336 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.c @@ -0,0 +1,111 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.h new file mode 100644 index 0000000..bce264f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_0.h @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.c new file mode 100644 index 0000000..929b655 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2015 - 2018, 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) + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.h new file mode 100644 index 0000000..3739da6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_1.h @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.c new file mode 100644 index 0000000..4fb01d2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.c @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.h new file mode 100644 index 0000000..55d9793 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_2.h @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.c new file mode 100644 index 0000000..ab52197 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.h new file mode 100644 index 0000000..6aa663e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_3.h @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.c new file mode 100644 index 0000000..a8f83f2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.c @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.h new file mode 100644 index 0000000..093ef57 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_4.h @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.c new file mode 100644 index 0000000..c861143 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.c @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2015 - 2018, 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) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.h new file mode 100644 index 0000000..64cd241 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_page_5.h @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_pages.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_pages.h new file mode 100644 index 0000000..f725e66 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/pages/ant_bsc_pages.h @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2015 - 2018, 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 +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.c new file mode 100644 index 0000000..c3499cc --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.c @@ -0,0 +1,280 @@ +/** + * Copyright (c) 2015 - 2018, 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)); + } +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.h new file mode 100644 index 0000000..98e1fc4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator.h @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2015 - 2018, 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__ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator_local.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator_local.h new file mode 100644 index 0000000..cb1aec6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/simulator/ant_bsc_simulator_local.h @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2015 - 2018, 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__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/utils/ant_bsc_utils.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/utils/ant_bsc_utils.h new file mode 100644 index 0000000..7126ebf --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/ant/ant_profiles/ant_bsc/utils/ant_bsc_utils.h @@ -0,0 +1,128 @@ +/** + * Copyright (c) 2015 - 2018, 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__ + |