初始版本
This commit is contained in:
490
components/ant/ant_profiles/ant_bpwr/ant_bpwr.c
Normal file
490
components/ant/ant_profiles/ant_bpwr/ant_bpwr.c
Normal file
@@ -0,0 +1,490 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include "nrf_assert.h"
|
||||
#include "app_error.h"
|
||||
#include "ant_interface.h"
|
||||
#include "ant_bpwr.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr
|
||||
#if ANT_BPWR_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_INFO_COLOR
|
||||
#else // ANT_BPWR_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
#define BPWR_CALIB_INT_TIMEOUT ((ANT_CLOCK_FREQUENCY * BPWR_CALIBRATION_TIMOUT_S) / BPWR_MSG_PERIOD) // calibration timeout in ant message period's unit
|
||||
|
||||
// for torque sensor Minimum: Interleave every 9th message
|
||||
#define BPWR_PAGE_16_INTERVAL 5 // Preferred: Interleave every 5th message
|
||||
#define BPWR_PAGE_16_INTERVAL_OFS 2 // Permissible offset
|
||||
#define COMMON_PAGE_80_INTERVAL 119 // Minimum: Interleave every 121 messages
|
||||
#define COMMON_PAGE_81_INTERVAL 120 // Minimum: Interleave every 121 messages
|
||||
#define AUTO_ZERO_SUPPORT_INTERVAL 120 // Minimum: Interleave every 121 messages
|
||||
|
||||
/**@brief Bicycle power message data layout structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t page_number;
|
||||
uint8_t page_payload[7];
|
||||
} ant_bpwr_message_layout_t;
|
||||
|
||||
|
||||
/**@brief Function for initializing the ANT Bicycle Power Profile instance.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
|
||||
*
|
||||
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
|
||||
*/
|
||||
static ret_code_t ant_bpwr_init(ant_bpwr_profile_t * p_profile,
|
||||
ant_channel_config_t const * p_channel_config)
|
||||
{
|
||||
p_profile->channel_number = p_channel_config->channel_number;
|
||||
|
||||
p_profile->page_1 = DEFAULT_ANT_BPWR_PAGE1();
|
||||
p_profile->page_16 = DEFAULT_ANT_BPWR_PAGE16();
|
||||
p_profile->page_17 = DEFAULT_ANT_BPWR_PAGE17();
|
||||
p_profile->page_18 = DEFAULT_ANT_BPWR_PAGE18();
|
||||
p_profile->page_80 = DEFAULT_ANT_COMMON_page80();
|
||||
p_profile->page_81 = DEFAULT_ANT_COMMON_page81();
|
||||
|
||||
NRF_LOG_INFO("ANT B-PWR channel %u init", p_profile->channel_number);
|
||||
return ant_channel_init(p_channel_config);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ant_bpwr_disp_init(ant_bpwr_profile_t * p_profile,
|
||||
ant_channel_config_t const * p_channel_config,
|
||||
ant_bpwr_disp_config_t const * p_disp_config)
|
||||
{
|
||||
ASSERT(p_profile != NULL);
|
||||
ASSERT(p_channel_config != NULL);
|
||||
ASSERT(p_disp_config != NULL);
|
||||
ASSERT(p_disp_config->evt_handler != NULL);
|
||||
ASSERT(p_disp_config->p_cb != NULL);
|
||||
|
||||
p_profile->evt_handler = p_disp_config->evt_handler;
|
||||
p_profile->_cb.p_disp_cb = p_disp_config->p_cb;
|
||||
|
||||
p_profile->_cb.p_disp_cb ->calib_timeout = 0;
|
||||
p_profile->_cb.p_disp_cb ->calib_stat = BPWR_DISP_CALIB_NONE;
|
||||
|
||||
return ant_bpwr_init(p_profile, p_channel_config);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ant_bpwr_sens_init(ant_bpwr_profile_t * p_profile,
|
||||
ant_channel_config_t const * p_channel_config,
|
||||
ant_bpwr_sens_config_t const * p_sens_config)
|
||||
{
|
||||
ASSERT(p_profile != NULL);
|
||||
ASSERT(p_channel_config != NULL);
|
||||
ASSERT(p_sens_config != NULL);
|
||||
ASSERT(p_sens_config->p_cb != NULL);
|
||||
ASSERT(p_sens_config->evt_handler != NULL);
|
||||
ASSERT(p_sens_config->calib_handler != NULL);
|
||||
|
||||
p_profile->evt_handler = p_sens_config->evt_handler;
|
||||
p_profile->_cb.p_sens_cb = p_sens_config->p_cb;
|
||||
|
||||
p_profile->_cb.p_sens_cb->torque_use = p_sens_config->torque_use;
|
||||
p_profile->_cb.p_sens_cb->calib_handler = p_sens_config->calib_handler;
|
||||
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_NONE;
|
||||
p_profile->_cb.p_sens_cb->message_counter = 0;
|
||||
|
||||
return ant_bpwr_init(p_profile, p_channel_config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**@brief Function for getting next page number to send.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
*
|
||||
* @return Next page number.
|
||||
*/
|
||||
static ant_bpwr_page_t next_page_number_get(ant_bpwr_profile_t * p_profile)
|
||||
{
|
||||
ant_bpwr_sens_cb_t * p_bpwr_cb = p_profile->_cb.p_sens_cb;
|
||||
ant_bpwr_page_t page_number;
|
||||
|
||||
if (p_bpwr_cb->calib_stat == BPWR_SENS_CALIB_READY)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_1;
|
||||
p_bpwr_cb->calib_stat = BPWR_SENS_CALIB_NONE; // mark event as processed
|
||||
}
|
||||
else if ((p_profile->BPWR_PROFILE_auto_zero_status != ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED)
|
||||
&& (p_bpwr_cb->message_counter == AUTO_ZERO_SUPPORT_INTERVAL))
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_1;
|
||||
p_profile->BPWR_PROFILE_calibration_id = ANT_BPWR_CALIB_ID_AUTO_SUPPORT;
|
||||
p_bpwr_cb->message_counter++;
|
||||
}
|
||||
else if (p_bpwr_cb->message_counter >= COMMON_PAGE_81_INTERVAL)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_81;
|
||||
p_bpwr_cb->message_counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p_bpwr_cb->message_counter == COMMON_PAGE_80_INTERVAL)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_80;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( p_bpwr_cb->torque_use == TORQUE_NONE)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_16;
|
||||
}
|
||||
else if ((p_bpwr_cb->message_counter % BPWR_PAGE_16_INTERVAL)
|
||||
== BPWR_PAGE_16_INTERVAL_OFS)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_16;
|
||||
}
|
||||
else if ( p_bpwr_cb->torque_use == TORQUE_WHEEL)
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_17;
|
||||
}
|
||||
else // assumed TORQUE_CRANK
|
||||
{
|
||||
page_number = ANT_BPWR_PAGE_18;
|
||||
}
|
||||
}
|
||||
p_bpwr_cb->message_counter++;
|
||||
}
|
||||
|
||||
return page_number;
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for encoding Bicycle Power Sensor message.
|
||||
*
|
||||
* @note Assume to be call each time when Tx window will occur.
|
||||
*/
|
||||
static void sens_message_encode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
|
||||
{
|
||||
ant_bpwr_message_layout_t * p_bpwr_message_payload =
|
||||
(ant_bpwr_message_layout_t *)p_message_payload;
|
||||
|
||||
p_bpwr_message_payload->page_number = next_page_number_get(p_profile);
|
||||
|
||||
NRF_LOG_INFO("B-PWR tx page: %u", p_bpwr_message_payload->page_number);
|
||||
|
||||
switch (p_bpwr_message_payload->page_number)
|
||||
{
|
||||
case ANT_BPWR_PAGE_1:
|
||||
ant_bpwr_page_1_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_1));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_16:
|
||||
ant_bpwr_page_16_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_16));
|
||||
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_17:
|
||||
ant_bpwr_page_17_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_17));
|
||||
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_18:
|
||||
ant_bpwr_page_18_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_18));
|
||||
ant_bpwr_cadence_encode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_COMMON_PAGE_80:
|
||||
ant_common_page_80_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_80));
|
||||
break;
|
||||
|
||||
case ANT_COMMON_PAGE_81:
|
||||
ant_common_page_81_encode(p_bpwr_message_payload->page_payload, &(p_profile->page_81));
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
p_profile->evt_handler(p_profile, (ant_bpwr_evt_t)p_bpwr_message_payload->page_number);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for decoding messages received by Bicycle Power sensor message.
|
||||
*
|
||||
* @note Assume to be call each time when Rx window will occur.
|
||||
*/
|
||||
static void sens_message_decode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
|
||||
{
|
||||
const ant_bpwr_message_layout_t * p_bpwr_message_payload =
|
||||
(ant_bpwr_message_layout_t *)p_message_payload;
|
||||
ant_bpwr_page1_data_t page1;
|
||||
|
||||
switch (p_bpwr_message_payload->page_number)
|
||||
{
|
||||
case ANT_BPWR_PAGE_1:
|
||||
ant_bpwr_page_1_decode(p_bpwr_message_payload->page_payload, &page1);
|
||||
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_REQUESTED;
|
||||
p_profile->_cb.p_sens_cb->calib_handler(p_profile, &page1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for decoding messages received by Bicycle Power display message.
|
||||
*
|
||||
* @note Assume to be call each time when Rx window will occur.
|
||||
*/
|
||||
static void disp_message_decode(ant_bpwr_profile_t * p_profile, uint8_t * p_message_payload)
|
||||
{
|
||||
const ant_bpwr_message_layout_t * p_bpwr_message_payload =
|
||||
(ant_bpwr_message_layout_t *)p_message_payload;
|
||||
|
||||
NRF_LOG_INFO("B-PWR rx page: %u", p_bpwr_message_payload->page_number);
|
||||
|
||||
switch (p_bpwr_message_payload->page_number)
|
||||
{
|
||||
case ANT_BPWR_PAGE_1:
|
||||
ant_bpwr_page_1_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_1));
|
||||
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_NONE;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_16:
|
||||
ant_bpwr_page_16_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_16));
|
||||
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_17:
|
||||
ant_bpwr_page_17_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_17));
|
||||
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_18:
|
||||
ant_bpwr_page_18_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_18));
|
||||
ant_bpwr_cadence_decode(p_bpwr_message_payload->page_payload, &(p_profile->common));
|
||||
break;
|
||||
|
||||
case ANT_COMMON_PAGE_80:
|
||||
ant_common_page_80_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_80));
|
||||
break;
|
||||
|
||||
case ANT_COMMON_PAGE_81:
|
||||
ant_common_page_81_decode(p_bpwr_message_payload->page_payload, &(p_profile->page_81));
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
p_profile->evt_handler(p_profile, (ant_bpwr_evt_t)p_bpwr_message_payload->page_number);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ant_bpwr_calib_request(ant_bpwr_profile_t * p_profile, ant_bpwr_page1_data_t * p_page_1)
|
||||
{
|
||||
ant_bpwr_message_layout_t bpwr_message_payload;
|
||||
|
||||
if (p_profile->_cb.p_disp_cb->calib_stat == BPWR_DISP_CALIB_REQUESTED)
|
||||
{
|
||||
return NRF_SUCCESS; // calibration in progress, so omit this request
|
||||
}
|
||||
|
||||
bpwr_message_payload.page_number = ANT_BPWR_PAGE_1;
|
||||
ant_bpwr_page_1_encode(bpwr_message_payload.page_payload, p_page_1);
|
||||
|
||||
uint32_t err_code = sd_ant_acknowledge_message_tx(p_profile->channel_number,
|
||||
sizeof (bpwr_message_payload),
|
||||
(uint8_t *) &bpwr_message_payload);
|
||||
|
||||
if (err_code == NRF_SUCCESS)
|
||||
{
|
||||
p_profile->_cb.p_disp_cb->calib_timeout = BPWR_CALIB_INT_TIMEOUT; // initialize watch on calibration's time-out
|
||||
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_REQUESTED;
|
||||
NRF_LOG_INFO("Start calibration process");
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_calib_response(ant_bpwr_profile_t * p_profile)
|
||||
{
|
||||
if (p_profile->_cb.p_sens_cb->calib_stat != BPWR_SENS_CALIB_READY) // abort if callback request is in progress
|
||||
{
|
||||
p_profile->_cb.p_sens_cb->calib_stat = BPWR_SENS_CALIB_READY; // calibration respond
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for hangling calibration events.
|
||||
*/
|
||||
static void service_calib(ant_bpwr_profile_t * p_profile, uint8_t event)
|
||||
{
|
||||
ant_bpwr_evt_t bpwr_event;
|
||||
|
||||
if (p_profile->_cb.p_disp_cb->calib_stat == BPWR_DISP_CALIB_REQUESTED)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case EVENT_RX:
|
||||
/* fall through */
|
||||
case EVENT_RX_FAIL:
|
||||
|
||||
if (p_profile->_cb.p_disp_cb->calib_timeout-- == 0)
|
||||
{
|
||||
bpwr_event = ANT_BPWR_CALIB_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
case EVENT_TRANSFER_TX_FAILED:
|
||||
bpwr_event = ANT_BPWR_CALIB_REQUEST_TX_FAILED;
|
||||
break;
|
||||
|
||||
case EVENT_RX_SEARCH_TIMEOUT:
|
||||
bpwr_event = ANT_BPWR_CALIB_TIMEOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("End calibration process");
|
||||
p_profile->_cb.p_disp_cb->calib_stat = BPWR_DISP_CALIB_NONE;
|
||||
|
||||
p_profile->evt_handler(p_profile, bpwr_event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ant_message_send(ant_bpwr_profile_t * p_profile)
|
||||
{
|
||||
uint32_t err_code;
|
||||
uint8_t p_message_payload[ANT_STANDARD_DATA_PAYLOAD_SIZE];
|
||||
|
||||
sens_message_encode(p_profile, p_message_payload);
|
||||
err_code =
|
||||
sd_ant_broadcast_message_tx(p_profile->channel_number,
|
||||
sizeof (p_message_payload),
|
||||
p_message_payload);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ant_bpwr_disp_open(ant_bpwr_profile_t * p_profile)
|
||||
{
|
||||
NRF_LOG_INFO("ANT B-PWR %u open", p_profile->channel_number);
|
||||
return sd_ant_channel_open(p_profile->channel_number);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ant_bpwr_sens_open(ant_bpwr_profile_t * p_profile)
|
||||
{
|
||||
// Fill tx buffer for the first frame
|
||||
ant_message_send(p_profile);
|
||||
|
||||
NRF_LOG_INFO("ANT B-PWR %u open", p_profile->channel_number);
|
||||
return sd_ant_channel_open(p_profile->channel_number);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_sens_evt_handler(ant_evt_t * p_ant_event, void * p_context)
|
||||
{
|
||||
ant_bpwr_profile_t * p_profile = ( ant_bpwr_profile_t *)p_context;
|
||||
|
||||
if (p_ant_event->channel == p_profile->channel_number)
|
||||
{
|
||||
switch (p_ant_event->event)
|
||||
{
|
||||
case EVENT_TX:
|
||||
ant_message_send(p_profile);
|
||||
break;
|
||||
|
||||
case EVENT_RX:
|
||||
if (p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID)
|
||||
{
|
||||
sens_message_decode(p_profile, p_ant_event->message.ANT_MESSAGE_aucPayload);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// No implementation needed
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_disp_evt_handler(ant_evt_t * p_ant_event, void * p_context)
|
||||
{
|
||||
ant_bpwr_profile_t * p_profile = ( ant_bpwr_profile_t *)p_context;
|
||||
|
||||
if (p_ant_event->channel == p_profile->channel_number)
|
||||
{
|
||||
switch (p_ant_event->event)
|
||||
{
|
||||
case EVENT_RX:
|
||||
|
||||
if (p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|
||||
|| p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|
||||
|| p_ant_event->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
|
||||
{
|
||||
disp_message_decode(p_profile, p_ant_event->message.ANT_MESSAGE_aucPayload);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
service_calib(p_profile, p_ant_event->event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
377
components/ant/ant_profiles/ant_bpwr/ant_bpwr.h
Normal file
377
components/ant/ant_profiles/ant_bpwr/ant_bpwr.h
Normal file
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @defgroup ant_bpwr Bicycle Power profile
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles
|
||||
* @brief This module implements the Bicycle Power profile.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ANT_BICYCLE_POWER_H__
|
||||
#define ANT_BICYCLE_POWER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "ant_parameters.h"
|
||||
#include "nrf_sdh_ant.h"
|
||||
#include "ant_channel_config.h"
|
||||
#include "ant_bpwr_pages.h"
|
||||
#include "sdk_errors.h"
|
||||
|
||||
#define BPWR_DEVICE_TYPE 0x0Bu ///< Device type reserved for ANT+ Bicycle Power.
|
||||
#define BPWR_ANTPLUS_RF_FREQ 0x39u ///< Frequency, decimal 57 (2457 MHz).
|
||||
#define BPWR_MSG_PERIOD 8182u ///< Message period, decimal 8182 (4.0049 Hz).
|
||||
|
||||
#define BPWR_EXT_ASSIGN 0x00 ///< ANT ext assign (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).
|
||||
#define BPWR_DISP_CHANNEL_TYPE CHANNEL_TYPE_SLAVE ///< Display Bicycle Power channel type.
|
||||
#define BPWR_SENS_CHANNEL_TYPE CHANNEL_TYPE_MASTER ///< Sensor Bicycle Power channel type.
|
||||
|
||||
#define BPWR_CALIBRATION_TIMOUT_S 5u ///< Time-out for responding to calibration callback (s).
|
||||
|
||||
|
||||
/**@brief Initialize an ANT channel configuration structure for the Bicycle Power profile (Display).
|
||||
*
|
||||
* @param[in] NAME Name of related instance.
|
||||
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
|
||||
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
|
||||
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
|
||||
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
|
||||
*/
|
||||
#define BPWR_DISP_CHANNEL_CONFIG_DEF(NAME, \
|
||||
CHANNEL_NUMBER, \
|
||||
TRANSMISSION_TYPE, \
|
||||
DEVICE_NUMBER, \
|
||||
NETWORK_NUMBER) \
|
||||
static const ant_channel_config_t CONCAT_2(NAME, _channel_bpwr_disp_config) = \
|
||||
{ \
|
||||
.channel_number = (CHANNEL_NUMBER), \
|
||||
.channel_type = BPWR_DISP_CHANNEL_TYPE, \
|
||||
.ext_assign = BPWR_EXT_ASSIGN, \
|
||||
.rf_freq = BPWR_ANTPLUS_RF_FREQ, \
|
||||
.transmission_type = (TRANSMISSION_TYPE), \
|
||||
.device_type = BPWR_DEVICE_TYPE, \
|
||||
.device_number = (DEVICE_NUMBER), \
|
||||
.channel_period = BPWR_MSG_PERIOD, \
|
||||
.network_number = (NETWORK_NUMBER), \
|
||||
}
|
||||
#define BPWR_DISP_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME, _channel_bpwr_disp_config)
|
||||
|
||||
/**@brief Initialize an ANT channel configuration structure for the Bicycle Power profile (Sensor).
|
||||
*
|
||||
* @param[in] NAME Name of related instance.
|
||||
* @param[in] CHANNEL_NUMBER Number of the channel assigned to the profile instance.
|
||||
* @param[in] TRANSMISSION_TYPE Type of transmission assigned to the profile instance.
|
||||
* @param[in] DEVICE_NUMBER Number of the device assigned to the profile instance.
|
||||
* @param[in] NETWORK_NUMBER Number of the network assigned to the profile instance.
|
||||
*/
|
||||
#define BPWR_SENS_CHANNEL_CONFIG_DEF(NAME, \
|
||||
CHANNEL_NUMBER, \
|
||||
TRANSMISSION_TYPE, \
|
||||
DEVICE_NUMBER, \
|
||||
NETWORK_NUMBER) \
|
||||
static const ant_channel_config_t CONCAT_2(NAME, _channel_bpwr_sens_config) = \
|
||||
{ \
|
||||
.channel_number = (CHANNEL_NUMBER), \
|
||||
.channel_type = BPWR_SENS_CHANNEL_TYPE, \
|
||||
.ext_assign = BPWR_EXT_ASSIGN, \
|
||||
.rf_freq = BPWR_ANTPLUS_RF_FREQ, \
|
||||
.transmission_type = (TRANSMISSION_TYPE), \
|
||||
.device_type = BPWR_DEVICE_TYPE, \
|
||||
.device_number = (DEVICE_NUMBER), \
|
||||
.channel_period = BPWR_MSG_PERIOD, \
|
||||
.network_number = (NETWORK_NUMBER), \
|
||||
}
|
||||
#define BPWR_SENS_CHANNEL_CONFIG(NAME) &CONCAT_2(NAME, _channel_bpwr_sens_config)
|
||||
|
||||
/**@brief Initialize an ANT profile configuration structure for the BPWR profile (Display).
|
||||
*
|
||||
* @param[in] NAME Name of related instance.
|
||||
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BPWR profile.
|
||||
*/
|
||||
#define BPWR_DISP_PROFILE_CONFIG_DEF(NAME, \
|
||||
EVT_HANDLER) \
|
||||
static ant_bpwr_disp_cb_t CONCAT_2(NAME, _bpwr_disp_cb); \
|
||||
static const ant_bpwr_disp_config_t CONCAT_2(NAME, _profile_bpwr_disp_config) = \
|
||||
{ \
|
||||
.p_cb = &CONCAT_2(NAME, _bpwr_disp_cb), \
|
||||
.evt_handler = (EVT_HANDLER), \
|
||||
}
|
||||
#define BPWR_DISP_PROFILE_CONFIG(NAME) &CONCAT_2(NAME, _profile_bpwr_disp_config)
|
||||
|
||||
|
||||
/**@brief Initialize an ANT profile configuration structure for the BPWR profile (Sensor).
|
||||
*
|
||||
* @param[in] NAME Name of related instance.
|
||||
* @param[in] TORQUE_USED Determines whether the torque page is included.
|
||||
* @param[in] CALIB_HANDLER Event handler to be called for handling calibration requests.
|
||||
* @param[in] EVT_HANDLER Event handler to be called for handling events in the BPWR profile.
|
||||
*/
|
||||
#define BPWR_SENS_PROFILE_CONFIG_DEF(NAME, \
|
||||
TORQUE_USED, \
|
||||
CALIB_HANDLER, \
|
||||
EVT_HANDLER) \
|
||||
static ant_bpwr_sens_cb_t CONCAT_2(NAME, _bpwr_sens_cb); \
|
||||
static const ant_bpwr_sens_config_t CONCAT_2(NAME, _profile_bpwr_sens_config) = \
|
||||
{ \
|
||||
.torque_use = (TORQUE_USED), \
|
||||
.calib_handler = (CALIB_HANDLER), \
|
||||
.p_cb = &CONCAT_2(NAME, _bpwr_sens_cb), \
|
||||
.evt_handler = (EVT_HANDLER), \
|
||||
}
|
||||
#define BPWR_SENS_PROFILE_CONFIG(NAME) &NAME##_profile_bpwr_sens_config
|
||||
|
||||
|
||||
/**@brief Configuration values for the Bicycle Power torque page. */
|
||||
typedef enum
|
||||
{
|
||||
TORQUE_NONE = 0,
|
||||
TORQUE_WHEEL = 1,
|
||||
TORQUE_CRANK = 2,
|
||||
} ant_bpwr_torque_t;
|
||||
|
||||
/**@brief Bicycle Power page number type. */
|
||||
typedef enum
|
||||
{
|
||||
ANT_BPWR_PAGE_1 = 1, ///< Calibration data page.
|
||||
ANT_BPWR_PAGE_16 = 16, ///< Standard power-only main data page.
|
||||
ANT_BPWR_PAGE_17 = 17, ///< Standard wheel torque main data page.
|
||||
ANT_BPWR_PAGE_18 = 18, ///< Standard crank torque main data page.
|
||||
ANT_BPWR_PAGE_80 = ANT_COMMON_PAGE_80,
|
||||
ANT_BPWR_PAGE_81 = ANT_COMMON_PAGE_81
|
||||
} ant_bpwr_page_t;
|
||||
|
||||
/**@brief BPWR profile event type. */
|
||||
typedef enum
|
||||
{
|
||||
ANT_BPWR_PAGE_1_UPDATED = ANT_BPWR_PAGE_1, ///< Data page 1 and speed have been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_PAGE_16_UPDATED = ANT_BPWR_PAGE_16, ///< Data page 16 and speed have been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_PAGE_17_UPDATED = ANT_BPWR_PAGE_17, ///< Data page 17 and speed have been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_PAGE_18_UPDATED = ANT_BPWR_PAGE_18, ///< Data page 18 has been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_PAGE_80_UPDATED = ANT_BPWR_PAGE_80, ///< Data page 80 has been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_PAGE_81_UPDATED = ANT_BPWR_PAGE_81, ///< Data page 81 has been updated (Display) or sent (Sensor).
|
||||
ANT_BPWR_CALIB_TIMEOUT, ///< Request of calibration time-out occurred (Display).
|
||||
ANT_BPWR_CALIB_REQUEST_TX_FAILED, ///< Calibration request did not reach the destination (Display).
|
||||
} ant_bpwr_evt_t;
|
||||
|
||||
// Forward declaration of the ant_bpwr_profile_t type.
|
||||
typedef struct ant_bpwr_profile_s ant_bpwr_profile_t;
|
||||
|
||||
/**@brief BPWR event handler type. */
|
||||
typedef void (* ant_bpwr_evt_handler_t) (ant_bpwr_profile_t *, ant_bpwr_evt_t);
|
||||
|
||||
/**@brief BPWR Sensor calibration request handler type. */
|
||||
typedef void (* ant_bpwr_calib_handler_t) (ant_bpwr_profile_t *, ant_bpwr_page1_data_t *);
|
||||
|
||||
#include "ant_bpwr_local.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Bicycle Power Sensor configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
ant_bpwr_torque_t torque_use; ///< Determines whether the torque page is included.
|
||||
ant_bpwr_sens_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
|
||||
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
|
||||
ant_bpwr_calib_handler_t calib_handler; ///< Event handler to be called for handling calibration requests.
|
||||
} ant_bpwr_sens_config_t;
|
||||
|
||||
/**@brief Bicycle Power Display configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
ant_bpwr_disp_cb_t * p_cb; ///< Pointer to the data buffer for internal use.
|
||||
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
|
||||
} ant_bpwr_disp_config_t;
|
||||
|
||||
/**@brief Bicycle Power profile structure. */
|
||||
struct ant_bpwr_profile_s
|
||||
{
|
||||
uint8_t channel_number; ///< Channel number assigned to the profile.
|
||||
union {
|
||||
ant_bpwr_disp_cb_t * p_disp_cb;
|
||||
ant_bpwr_sens_cb_t * p_sens_cb;
|
||||
} _cb; ///< Pointer to internal control block.
|
||||
ant_bpwr_evt_handler_t evt_handler; ///< Event handler to be called for handling events in the BPWR profile.
|
||||
ant_bpwr_page1_data_t page_1; ///< Page 1.
|
||||
ant_bpwr_page16_data_t page_16; ///< Page 16.
|
||||
ant_bpwr_page17_data_t page_17; ///< Page 17.
|
||||
ant_bpwr_page18_data_t page_18; ///< Page 18.
|
||||
ant_common_page80_data_t page_80; ///< Page 80.
|
||||
ant_common_page81_data_t page_81; ///< Page 81.
|
||||
ant_bpwr_common_data_t common; ///< BPWR common data.
|
||||
};
|
||||
|
||||
/** @name Defines for accessing ant_bpwr_profile_t member variables
|
||||
@{ */
|
||||
#define BPWR_PROFILE_calibration_id page_1.calibration_id
|
||||
#define BPWR_PROFILE_auto_zero_status page_1.auto_zero_status
|
||||
#define BPWR_PROFILE_general_calib_data page_1.data.general_calib
|
||||
#define BPWR_PROFILE_custom_calib_data page_1.data.custom_calib
|
||||
#define BPWR_PROFILE_instantaneous_cadence common.instantaneous_cadence
|
||||
#define BPWR_PROFILE_pedal_power page_16.pedal_power.items
|
||||
#define BPWR_PROFILE_power_update_event_count page_16.update_event_count
|
||||
#define BPWR_PROFILE_accumulated_power page_16.accumulated_power
|
||||
#define BPWR_PROFILE_instantaneous_power page_16.instantaneous_power
|
||||
#define BPWR_PROFILE_wheel_update_event_count page_17.update_event_count
|
||||
#define BPWR_PROFILE_wheel_tick page_17.tick
|
||||
#define BPWR_PROFILE_wheel_period page_17.period
|
||||
#define BPWR_PROFILE_wheel_accumulated_torque page_17.accumulated_torque
|
||||
#define BPWR_PROFILE_crank_update_event_count page_18.update_event_count
|
||||
#define BPWR_PROFILE_crank_tick page_18.tick
|
||||
#define BPWR_PROFILE_crank_period page_18.period
|
||||
#define BPWR_PROFILE_crank_accumulated_torque page_18.accumulated_torque
|
||||
#define BPWR_PROFILE_manuf_id page_80.manuf_id
|
||||
#define BPWR_PROFILE_hw_revision page_80.hw_revision
|
||||
#define BPWR_PROFILE_manufacturer_id page_80.manufacturer_id
|
||||
#define BPWR_PROFILE_model_number page_80.model_number
|
||||
#define BPWR_PROFILE_sw_revision_minor page_81.sw_revision_minor
|
||||
#define BPWR_PROFILE_sw_revision_major page_81.sw_revision_major
|
||||
#define BPWR_PROFILE_serial_number page_81.serial_number
|
||||
/** @} */
|
||||
|
||||
/**@brief Function for initializing the ANT Bicycle Power Display profile instance.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
|
||||
* @param[in] p_disp_config Pointer to the Bicycle Power Display configuration structure.
|
||||
*
|
||||
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
|
||||
*/
|
||||
ret_code_t ant_bpwr_disp_init(ant_bpwr_profile_t * p_profile,
|
||||
ant_channel_config_t const * p_channel_config,
|
||||
ant_bpwr_disp_config_t const * p_disp_config);
|
||||
|
||||
/**@brief Function for initializing the ANT Bicycle Power Sensor profile instance.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
* @param[in] p_channel_config Pointer to the ANT channel configuration structure.
|
||||
* @param[in] p_sens_config Pointer to the Bicycle Power Sensor configuration structure.
|
||||
*
|
||||
* @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
|
||||
*/
|
||||
ret_code_t ant_bpwr_sens_init(ant_bpwr_profile_t * p_profile,
|
||||
ant_channel_config_t const * p_channel_config,
|
||||
ant_bpwr_sens_config_t const * p_sens_config);
|
||||
|
||||
/**@brief Function for opening the profile instance channel for ANT BPWR Display.
|
||||
*
|
||||
* Before calling this function, pages should be configured.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
|
||||
*/
|
||||
ret_code_t ant_bpwr_disp_open(ant_bpwr_profile_t * p_profile);
|
||||
|
||||
/**@brief Function for opening the profile instance channel for ANT BPWR Sensor.
|
||||
*
|
||||
* Before calling this function, pages should be configured.
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the channel was successfully opened. Otherwise, an error code is returned.
|
||||
*/
|
||||
ret_code_t ant_bpwr_sens_open(ant_bpwr_profile_t * p_profile);
|
||||
|
||||
/** @name Functions: Sensor calibration API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief Function for initializing the response for a calibration request.
|
||||
*
|
||||
* This function should be used to signal the status of the calibration procedure to the ANT profile layer .
|
||||
*
|
||||
* @param[in] p_profile Pointer to the profile instance.
|
||||
*/
|
||||
void ant_bpwr_calib_response(ant_bpwr_profile_t * p_profile);
|
||||
/** @} */
|
||||
|
||||
|
||||
/**@brief Function for handling the Sensor ANT events.
|
||||
*
|
||||
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Power Display profile.
|
||||
*
|
||||
* @param[in] p_ant_evt Event received from the ANT stack.
|
||||
* @param[in] p_context Pointer to the profile instance.
|
||||
*/
|
||||
void ant_bpwr_sens_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
|
||||
|
||||
/**@brief Function for handling the Display ANT events.
|
||||
*
|
||||
* @details This function handles all events from the ANT stack that are of interest to the Bicycle Power Display profile.
|
||||
*
|
||||
* @param[in] p_ant_evt Event received from the ANT stack.
|
||||
* @param[in] p_context Pointer to the profile instance.
|
||||
*/
|
||||
void ant_bpwr_disp_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
|
||||
|
||||
/** @name Functions: Display calibration API
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**@brief Function for initializing the calibration request process from the Bicycle Power Display side.
|
||||
*
|
||||
* @details This function requests a transfer to the Sensor and starts watching for the calibration response.
|
||||
* If a calibration response has already been requested, the function ignores the new request and returns NRF_SUCCESS.
|
||||
*
|
||||
* @param [in] p_profile Pointer to the profile instance.
|
||||
* @param [in] p_page_1 Pointer to the prepared page 1.
|
||||
*
|
||||
* @return Values returned by the @ref sd_ant_acknowledge_message_tx SVC callback.
|
||||
*/
|
||||
uint32_t ant_bpwr_calib_request(ant_bpwr_profile_t * p_profile, ant_bpwr_page1_data_t * p_page_1);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BICYCLE_POWER_H__
|
||||
|
||||
89
components/ant/ant_profiles/ant_bpwr/ant_bpwr_local.h
Normal file
89
components/ant/ant_profiles/ant_bpwr/ant_bpwr_local.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_LOCAL_H__
|
||||
#define ANT_BPWR_LOCAL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "ant_bpwr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup ant_bpwr
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief Bicycle Power Sensor control block. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t message_counter;
|
||||
ant_bpwr_torque_t torque_use;
|
||||
enum
|
||||
{
|
||||
BPWR_SENS_CALIB_NONE, ///< Idle state.
|
||||
BPWR_SENS_CALIB_REQUESTED, ///< Received request for general calibration result message by the sensor.
|
||||
BPWR_SENS_CALIB_READY, ///< Calibration response message is ready to be transmitted.
|
||||
} calib_stat;
|
||||
ant_bpwr_calib_handler_t calib_handler;
|
||||
} ant_bpwr_sens_cb_t;
|
||||
|
||||
/**@brief Bicycle Power Sensor RX control block. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t calib_timeout;
|
||||
enum
|
||||
{
|
||||
BPWR_DISP_CALIB_NONE, ///< Idle state.
|
||||
BPWR_DISP_CALIB_REQUESTED, ///< Calibration requested.
|
||||
} calib_stat;
|
||||
} ant_bpwr_disp_cb_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_LOCAL_H__
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include "ant_bpwr_common_data.h"
|
||||
#include "ant_bpwr_utils.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_common
|
||||
#if ANT_BPWR_COMMON_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_COMMON_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_COMMON_INFO_COLOR
|
||||
#else // ANT_BPWR_COMMON_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_COMMON_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
/**@brief BPWR common page data layout structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t reserved0[2];
|
||||
uint8_t instantaneous_cadence;
|
||||
uint8_t reserved1[4];
|
||||
}ant_bpwr_cadence_data_layout_t;
|
||||
|
||||
/**@brief Function for tracing common data.
|
||||
*
|
||||
* @param[in] p_common_data Pointer to the common data.
|
||||
*/
|
||||
static void cadence_data_log(ant_bpwr_common_data_t const * p_common_data)
|
||||
{
|
||||
if (p_common_data->instantaneous_cadence == 0xFF)
|
||||
{
|
||||
NRF_LOG_INFO("instantaneous cadence: -- rpm\r\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_LOG_INFO("instantaneous cadence: %u rpm\r\n\n",
|
||||
p_common_data->instantaneous_cadence);
|
||||
}
|
||||
}
|
||||
|
||||
void ant_bpwr_cadence_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_common_data_t const * p_common_data)
|
||||
{
|
||||
ant_bpwr_cadence_data_layout_t * p_outcoming_data = (ant_bpwr_cadence_data_layout_t *)p_page_buffer;
|
||||
p_outcoming_data->instantaneous_cadence = p_common_data->instantaneous_cadence;
|
||||
|
||||
cadence_data_log(p_common_data);
|
||||
}
|
||||
|
||||
void ant_bpwr_cadence_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_common_data_t * p_common_data)
|
||||
{
|
||||
ant_bpwr_cadence_data_layout_t const * p_incoming_data = (ant_bpwr_cadence_data_layout_t *)p_page_buffer;
|
||||
p_common_data->instantaneous_cadence = p_incoming_data->instantaneous_cadence;
|
||||
|
||||
cadence_data_log(p_common_data);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_COMMON_DATA_H__
|
||||
#define ANT_BPWR_COMMON_DATA_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_common_data_page Stride Based Speed and Distance Monitor profile common data
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Data structure for BPWR common data.
|
||||
*
|
||||
* @details This structure stores data that is not associated with a particular page.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t instantaneous_cadence; ///< Crank cadence (rpm, 0 - 254, 255-> invalid).
|
||||
} ant_bpwr_common_data_t;
|
||||
|
||||
/**@brief Initialize common data.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_COMMON_DATA() \
|
||||
(ant_bpwr_common_data_t) \
|
||||
{ \
|
||||
.instantaneous_cadence = 0, \
|
||||
}
|
||||
|
||||
/**@brief Function for encoding speed.
|
||||
*
|
||||
* This function can be used for pages 16, 17, and 18.
|
||||
*
|
||||
* @param[in] p_common_data Pointer to the common data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_cadence_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_common_data_t const * p_common_data);
|
||||
|
||||
/**@brief Function for decoding speed.
|
||||
*
|
||||
* This function can be used for pages 16, 17, and 18.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_common_data Pointer to the common data.
|
||||
*/
|
||||
void ant_bpwr_cadence_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_common_data_t * p_common_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_COMMON_DATA_H__
|
||||
/** @} */
|
||||
286
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_1.c
Normal file
286
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_1.c
Normal file
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include <string.h>
|
||||
#include "ant_bpwr_page_1.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_page_1
|
||||
#if ANT_BPWR_PAGE_1_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_1_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_1_INFO_COLOR
|
||||
#else // ANT_BPWR_PAGE_1_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_PAGE_1_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
/**@brief bicycle power page 1 data layout structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t calibration_id; ///< Calibration request type
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t reserved[6]; ///< Unused, fill by 0xFF.
|
||||
} general_calib_request;
|
||||
struct
|
||||
{
|
||||
uint8_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
|
||||
uint8_t reserved[5]; ///< Unused, fill by 0xFF.
|
||||
} auto_zero_config;
|
||||
struct
|
||||
{
|
||||
uint8_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
|
||||
uint8_t reserved[3]; ///< Unused, fill by 0xFF.
|
||||
uint8_t data[2]; ///< Calibration Data.
|
||||
} general_calib_response;
|
||||
struct
|
||||
{
|
||||
uint8_t enable : 1;
|
||||
uint8_t status : 1;
|
||||
uint8_t reserved0 : 6; ///< Unused, fill by 0x00.
|
||||
uint8_t reserved1[5]; ///< Unused, fill by 0xFF.
|
||||
} auto_zero_support;
|
||||
struct
|
||||
{
|
||||
uint8_t manufac_spec[6]; ///< Manufacture Specyfic Data.
|
||||
} custom_calib;
|
||||
} data;
|
||||
} ant_bpwr_page1_data_layout_t;
|
||||
|
||||
|
||||
static void page1_data_log(ant_bpwr_page1_data_t const * p_page_data)
|
||||
{
|
||||
NRF_LOG_INFO("Calibration id: %u", p_page_data->calibration_id);
|
||||
|
||||
switch (p_page_data->calibration_id)
|
||||
{
|
||||
case ANT_BPWR_CALIB_ID_MANUAL:
|
||||
// No implementation needed
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_FAILED:
|
||||
NRF_LOG_INFO("General calibration data: %u",
|
||||
p_page_data->data.general_calib);
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_AUTO:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
|
||||
|
||||
switch (p_page_data->auto_zero_status)
|
||||
{
|
||||
case ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED:
|
||||
NRF_LOG_INFO("Auto zero not supported\r\n\n");
|
||||
break;
|
||||
|
||||
case ANT_BPWR_AUTO_ZERO_OFF:
|
||||
NRF_LOG_INFO("Auto zero off\r\n\n");
|
||||
break;
|
||||
|
||||
case ANT_BPWR_AUTO_ZERO_ON:
|
||||
NRF_LOG_INFO("Auto zero on\r\n\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CTF:
|
||||
NRF_LOG_INFO("Not supported\r\n\n");
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
|
||||
NRF_LOG_INFO("Manufacture specyfic: ");
|
||||
NRF_LOG_HEXDUMP_INFO((uint8_t*)p_page_data->data.custom_calib,
|
||||
sizeof (p_page_data->data.custom_calib));
|
||||
break;
|
||||
|
||||
default: // shouldn't occur
|
||||
NRF_LOG_INFO("Unsupported calibration ID\r\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_1_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page1_data_t const * p_page_data)
|
||||
{
|
||||
ant_bpwr_page1_data_layout_t * p_outcoming_data = (ant_bpwr_page1_data_layout_t *)p_page_buffer;
|
||||
|
||||
page1_data_log(p_page_data);
|
||||
|
||||
p_outcoming_data->calibration_id = p_page_data->calibration_id;
|
||||
|
||||
switch (p_page_data->calibration_id)
|
||||
{
|
||||
case ANT_BPWR_CALIB_ID_MANUAL:
|
||||
memset(p_outcoming_data->data.general_calib_request.reserved, 0xFF,
|
||||
sizeof (p_outcoming_data->data.general_calib_request.reserved));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_AUTO:
|
||||
memset(p_outcoming_data->data.auto_zero_config.reserved, 0xFF,
|
||||
sizeof (p_outcoming_data->data.auto_zero_config.reserved));
|
||||
p_outcoming_data->data.auto_zero_config.auto_zero_status =
|
||||
p_page_data->auto_zero_status;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_FAILED:
|
||||
memset(p_outcoming_data->data.general_calib_response.reserved, 0xFF,
|
||||
sizeof (p_outcoming_data->data.general_calib_response.reserved));
|
||||
p_outcoming_data->data.general_calib_response.auto_zero_status =
|
||||
p_page_data->auto_zero_status;
|
||||
UNUSED_PARAMETER(uint16_encode(p_page_data->data.general_calib,
|
||||
p_outcoming_data->data.general_calib_response.data));
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CTF:
|
||||
NRF_LOG_INFO("Not supported");
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
|
||||
memset(p_outcoming_data->data.auto_zero_support.reserved1, 0xFF,
|
||||
sizeof (p_outcoming_data->data.auto_zero_support.reserved1));
|
||||
p_outcoming_data->data.auto_zero_support.reserved0 = 0x00;
|
||||
p_outcoming_data->data.auto_zero_support.enable =
|
||||
(p_page_data->auto_zero_status == ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED) ? false : true;
|
||||
p_outcoming_data->data.auto_zero_support.status =
|
||||
(p_page_data->auto_zero_status == ANT_BPWR_AUTO_ZERO_ON) ? true : false;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
|
||||
memcpy(p_outcoming_data->data.custom_calib.manufac_spec,
|
||||
(void *)p_page_data->data.custom_calib,
|
||||
sizeof (p_page_data->data.custom_calib));
|
||||
break;
|
||||
|
||||
default: // shouldn't occur
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_1_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page1_data_t * p_page_data)
|
||||
{
|
||||
ant_bpwr_page1_data_layout_t const * p_incoming_data =
|
||||
(ant_bpwr_page1_data_layout_t *)p_page_buffer;
|
||||
|
||||
p_page_data->calibration_id = (ant_bpwr_calib_id_t)p_incoming_data->calibration_id;
|
||||
|
||||
switch (p_incoming_data->calibration_id)
|
||||
{
|
||||
case ANT_BPWR_CALIB_ID_MANUAL:
|
||||
// No implementation needed
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_AUTO:
|
||||
/* fall through */
|
||||
p_page_data->auto_zero_status =
|
||||
(ant_bpwr_auto_zero_status_t)p_incoming_data->data.auto_zero_config.auto_zero_status;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_MANUAL_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_FAILED:
|
||||
p_page_data->auto_zero_status =
|
||||
(ant_bpwr_auto_zero_status_t)p_incoming_data->data.general_calib_response.
|
||||
auto_zero_status;
|
||||
p_page_data->data.general_calib = uint16_decode(
|
||||
p_incoming_data->data.general_calib_response.data);
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CTF:
|
||||
NRF_LOG_INFO("Not supported");
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_AUTO_SUPPORT:
|
||||
|
||||
if (p_incoming_data->data.auto_zero_support.enable == false)
|
||||
{
|
||||
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED;
|
||||
}
|
||||
else if (p_incoming_data->data.auto_zero_support.status)
|
||||
{
|
||||
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_page_data->auto_zero_status = ANT_BPWR_AUTO_ZERO_OFF;
|
||||
}
|
||||
break;
|
||||
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE:
|
||||
/* fall through */
|
||||
case ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS:
|
||||
memcpy((void *)p_page_data->data.custom_calib,
|
||||
p_incoming_data->data.custom_calib.manufac_spec,
|
||||
sizeof (p_page_data->data.custom_calib));
|
||||
break;
|
||||
|
||||
default: // shouldn't occur
|
||||
break;
|
||||
}
|
||||
|
||||
page1_data_log(p_page_data);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
136
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_1.h
Normal file
136
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_1.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGE_1_H__
|
||||
#define ANT_BPWR_PAGE_1_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_page1 Bicycle Power profile page 1
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief BPWR Calibration ID.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ANT_BPWR_CALIB_ID_NONE = 0x00,
|
||||
ANT_BPWR_CALIB_ID_MANUAL = 0xAA, ///< Calibration Request: Manual Zero.
|
||||
ANT_BPWR_CALIB_ID_AUTO = 0xAB, ///< Calibration Request: Auto Zero Configuration.
|
||||
ANT_BPWR_CALIB_ID_MANUAL_SUCCESS = 0xAC, ///< Calibration Response: Manual Zero Successful.
|
||||
ANT_BPWR_CALIB_ID_FAILED = 0xAF, ///< Calibration Response: Failed.
|
||||
ANT_BPWR_CALIB_ID_CTF = 0x10, ///< Crank Torque Frequency (CTF) Power sensor Defined Message.
|
||||
ANT_BPWR_CALIB_ID_AUTO_SUPPORT = 0x12, ///< Auto Zero Support.
|
||||
ANT_BPWR_CALIB_ID_CUSTOM_REQ = 0xBA, ///< Custom Calibration Parameter Request.
|
||||
ANT_BPWR_CALIB_ID_CUSTOM_REQ_SUCCESS = 0xBB, ///< Custom Calibration Parameter Response.
|
||||
ANT_BPWR_CALIB_ID_CUSTOM_UPDATE = 0xBC, ///< Custom Calibration Parameter Update.
|
||||
ANT_BPWR_CALIB_ID_CUSTOM_UPDATE_SUCCESS = 0xBD, ///< Custom Calibration Parameter Update Response.
|
||||
} ant_bpwr_calib_id_t;
|
||||
|
||||
/**@brief BPWR Calibration Auto Zero Status.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED = 0xFF, ///< Auto Zero Not Supported.
|
||||
ANT_BPWR_AUTO_ZERO_OFF = 0x00, ///< Auto Zero OFF.
|
||||
ANT_BPWR_AUTO_ZERO_ON = 0x01, ///< Auto Zero ON.
|
||||
} ant_bpwr_auto_zero_status_t;
|
||||
|
||||
/**@brief Data structure for Bicycle Power data page 1.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ant_bpwr_calib_id_t calibration_id; ///< Calibration request type.
|
||||
ant_bpwr_auto_zero_status_t auto_zero_status; ///< Status of automatic zero feature of power sensor.
|
||||
union
|
||||
{
|
||||
int16_t general_calib;
|
||||
uint8_t custom_calib[6];
|
||||
} data;
|
||||
} ant_bpwr_page1_data_t;
|
||||
|
||||
/**@brief Initialize page 1.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_PAGE1() \
|
||||
(ant_bpwr_page1_data_t) \
|
||||
{ \
|
||||
.calibration_id = ANT_BPWR_CALIB_ID_NONE, \
|
||||
.auto_zero_status = ANT_BPWR_AUTO_ZERO_NOT_SUPPORTED, \
|
||||
.data.general_calib = 0x00, \
|
||||
}
|
||||
|
||||
/**@brief Initialize page 1 with the general request.
|
||||
*/
|
||||
#define ANT_BPWR_GENERAL_CALIB_REQUEST() \
|
||||
(ant_bpwr_page1_data_t) \
|
||||
{ \
|
||||
.calibration_id = ANT_BPWR_CALIB_ID_MANUAL, \
|
||||
}
|
||||
|
||||
/**@brief Function for encoding page 1.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_page_1_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page1_data_t const * p_page_data);
|
||||
|
||||
/**@brief Function for decoding page 1.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_1_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page1_data_t * p_page_data);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGE_1_H__
|
||||
/** @} */
|
||||
117
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_16.c
Normal file
117
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_16.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include "ant_bpwr_page_16.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_page_16
|
||||
#if ANT_BPWR_PAGE_16_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_16_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_16_INFO_COLOR
|
||||
#else // ANT_BPWR_PAGE_16_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_PAGE_16_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
/**@brief bicycle power page 16 data layout structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t update_event_count;
|
||||
uint8_t pedal_power;
|
||||
uint8_t reserved;
|
||||
uint8_t accumulated_power[2];
|
||||
uint8_t instantaneous_power[2];
|
||||
}ant_bpwr_page16_data_layout_t;
|
||||
|
||||
|
||||
static void page16_data_log(ant_bpwr_page16_data_t const * p_page_data)
|
||||
{
|
||||
NRF_LOG_INFO("event count: %u", p_page_data->update_event_count);
|
||||
|
||||
if (p_page_data->pedal_power.byte != 0xFF)
|
||||
{
|
||||
NRF_LOG_INFO("pedal power: %u %%",
|
||||
p_page_data->pedal_power.items.distribution);
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_LOG_INFO("pedal power: --");
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("accumulated power: %u W", p_page_data->accumulated_power);
|
||||
NRF_LOG_INFO("instantaneous power: %u W", p_page_data->instantaneous_power);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_16_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page16_data_t const * p_page_data)
|
||||
{
|
||||
ant_bpwr_page16_data_layout_t * p_outcoming_data =
|
||||
(ant_bpwr_page16_data_layout_t *)p_page_buffer;
|
||||
|
||||
p_outcoming_data->update_event_count = p_page_data->update_event_count;
|
||||
p_outcoming_data->pedal_power = p_page_data->pedal_power.byte;
|
||||
|
||||
UNUSED_PARAMETER(uint16_encode(p_page_data->accumulated_power,
|
||||
p_outcoming_data->accumulated_power));
|
||||
UNUSED_PARAMETER(uint16_encode(p_page_data->instantaneous_power,
|
||||
p_outcoming_data->instantaneous_power));
|
||||
|
||||
page16_data_log(p_page_data);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_16_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page16_data_t * p_page_data)
|
||||
{
|
||||
ant_bpwr_page16_data_layout_t const * p_incoming_data =
|
||||
(ant_bpwr_page16_data_layout_t *)p_page_buffer;
|
||||
|
||||
p_page_data->update_event_count = p_incoming_data->update_event_count;
|
||||
p_page_data->pedal_power.byte = p_incoming_data->pedal_power;
|
||||
p_page_data->accumulated_power = uint16_decode(p_incoming_data->accumulated_power);
|
||||
p_page_data->instantaneous_power = uint16_decode(p_incoming_data->instantaneous_power);
|
||||
|
||||
page16_data_log(p_page_data);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
111
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_16.h
Normal file
111
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_page_16.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGE_16_H__
|
||||
#define ANT_BPWR_PAGE_16_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_page16 Bicycle Power profile page 16
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Data structure for Bicycle Power data page 16.
|
||||
*
|
||||
* @note This structure implements only page 16 specific data.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t distribution : 7; ///< Pedal power distribution (%).
|
||||
uint8_t differentiation : 1; ///< Pedal differentiation: 1 -> right, 0 -> unknown.
|
||||
} items;
|
||||
uint8_t byte;
|
||||
} pedal_power;
|
||||
|
||||
uint8_t update_event_count; ///< Power event count.
|
||||
uint16_t accumulated_power; ///< Accumulated power (W).
|
||||
uint16_t instantaneous_power; ///< Instantaneous power (W).
|
||||
} ant_bpwr_page16_data_t;
|
||||
|
||||
/**@brief Initialize page 16.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_PAGE16() \
|
||||
(ant_bpwr_page16_data_t) \
|
||||
{ \
|
||||
.update_event_count = 0, \
|
||||
.pedal_power.items.distribution = 0, \
|
||||
.pedal_power.items.differentiation = 0, \
|
||||
.accumulated_power = 0, \
|
||||
.instantaneous_power = 0, \
|
||||
}
|
||||
|
||||
/**@brief Function for encoding page 16.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_page_16_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page16_data_t const * p_page_data);
|
||||
|
||||
/**@brief Function for decoding page 16.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_16_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page16_data_t * p_page_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGE_16_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include "ant_bpwr_page_17.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_page_17
|
||||
#if ANT_BPWR_PAGE_17_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_17_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_17_INFO_COLOR
|
||||
#else // ANT_BPWR_PAGE_17_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_PAGE_17_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
static void page17_data_log(ant_bpwr_page17_data_t const * p_page_data)
|
||||
{
|
||||
NRF_LOG_INFO("Wheel:");
|
||||
ant_bpwr_page_torque_log((ant_bpwr_page_torque_data_t *) p_page_data);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_17_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page17_data_t const * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_encode(p_page_buffer, (ant_bpwr_page_torque_data_t *)p_page_data);
|
||||
page17_data_log(p_page_data);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_17_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page17_data_t * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_decode(p_page_buffer, (ant_bpwr_page_torque_data_t *) p_page_data);
|
||||
page17_data_log(p_page_data);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGE_17_H__
|
||||
#define ANT_BPWR_PAGE_17_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_page17 Bicycle Power profile page 17
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ant_bpwr_page_torque.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Data structure for Bicycle Power data page 17.
|
||||
*
|
||||
* @note This structure implements only page 17 specific data.
|
||||
*/
|
||||
typedef ant_bpwr_page_torque_data_t ant_bpwr_page17_data_t;
|
||||
|
||||
/**@brief Initialize page 17.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_PAGE17() (ant_bpwr_page17_data_t) DEFAULT_ANT_BPWR_PAGE_TORQUE(0, 0, 0, 0)
|
||||
|
||||
/**@brief Function for encoding page 17.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_page_17_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page17_data_t const * p_page_data);
|
||||
|
||||
/**@brief Function for decoding page 17.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_17_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page17_data_t * p_page_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGE_17_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include "ant_bpwr_page_18.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_page_18
|
||||
#if ANT_BPWR_PAGE_18_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_18_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_18_INFO_COLOR
|
||||
#else // ANT_BPWR_PAGE_18_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_PAGE_18_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
static void page18_data_log(ant_bpwr_page18_data_t const * p_page_data)
|
||||
{
|
||||
NRF_LOG_INFO("Crank:");
|
||||
ant_bpwr_page_torque_log((ant_bpwr_page_torque_data_t *) p_page_data);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_18_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page18_data_t const * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_encode(p_page_buffer, (ant_bpwr_page_torque_data_t *)p_page_data);
|
||||
page18_data_log(p_page_data);
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_18_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page18_data_t * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_decode(p_page_buffer, (ant_bpwr_page_torque_data_t *) p_page_data);
|
||||
page18_data_log(p_page_data);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2011 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGE_18_H__
|
||||
#define ANT_BPWR_PAGE_18_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_page18 Bicycle Power profile page 18
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ant_bpwr_page_torque.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Data structure for Bicycle Power data page 18.
|
||||
*
|
||||
* @note This structure implements only page 18 specific data.
|
||||
*/
|
||||
typedef ant_bpwr_page_torque_data_t ant_bpwr_page18_data_t;
|
||||
|
||||
/**@brief Initialize page 18.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_PAGE18() (ant_bpwr_page18_data_t) DEFAULT_ANT_BPWR_PAGE_TORQUE(0, 0, 0, 0)
|
||||
|
||||
/**@brief Function for encoding page 18.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_page_18_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page18_data_t const * p_page_data);
|
||||
|
||||
/**@brief Function for decoding page 18.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_18_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page18_data_t * p_page_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGE_18_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ant_bpwr_page_torque.h"
|
||||
#include "ant_bpwr_utils.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME ant_bpwr_page_torque
|
||||
#if ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL ANT_BPWR_PAGE_TORQUE_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR ANT_BPWR_PAGE_TORQUE_INFO_COLOR
|
||||
#else // ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // ANT_BPWR_PAGE_TORQUE_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
/**@brief bicycle power page torque data layout structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t update_event_count;
|
||||
uint8_t tick;
|
||||
uint8_t reserved;
|
||||
uint8_t period[2];
|
||||
uint8_t accumulated_torque[2];
|
||||
}ant_bpwr_page_torque_data_layout_t;
|
||||
|
||||
STATIC_ASSERT(ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION == 1000); ///< Display format need to be updated
|
||||
STATIC_ASSERT(ANT_BPWR_ACC_TORQUE_DISP_PRECISION == 10); ///< Display format need to be updated
|
||||
|
||||
void ant_bpwr_page_torque_log(ant_bpwr_page_torque_data_t const * p_page_data)
|
||||
{
|
||||
uint16_t period = ANT_BPWR_TORQUE_PERIOD_RESCALE(p_page_data->period);
|
||||
uint32_t acc_torque = ANT_BPWR_ACC_TORQUE_RESCALE(p_page_data->accumulated_torque);
|
||||
|
||||
NRF_LOG_INFO("event count: %u", p_page_data->update_event_count);
|
||||
NRF_LOG_INFO("tick: %u", p_page_data->tick);
|
||||
NRF_LOG_INFO("period: %u.%03us",
|
||||
(unsigned int)(period / ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION),
|
||||
(unsigned int)(period % ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION));
|
||||
NRF_LOG_INFO("accumulated torque: %u.%01uNm",
|
||||
(unsigned int)(acc_torque / ANT_BPWR_ACC_TORQUE_DISP_PRECISION),
|
||||
(unsigned int)(acc_torque % ANT_BPWR_ACC_TORQUE_DISP_PRECISION));
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_torque_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page_torque_data_t const * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_data_layout_t * p_outcoming_data =
|
||||
(ant_bpwr_page_torque_data_layout_t *)p_page_buffer;
|
||||
|
||||
p_outcoming_data->update_event_count = p_page_data->update_event_count;
|
||||
p_outcoming_data->tick = p_page_data->tick;
|
||||
|
||||
UNUSED_PARAMETER(uint16_encode(p_page_data->period, p_outcoming_data->period));
|
||||
UNUSED_PARAMETER(uint16_encode(p_page_data->accumulated_torque,
|
||||
p_outcoming_data->accumulated_torque));
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_page_torque_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page_torque_data_t * p_page_data)
|
||||
{
|
||||
ant_bpwr_page_torque_data_layout_t const * p_incoming_data =
|
||||
(ant_bpwr_page_torque_data_layout_t *)p_page_buffer;
|
||||
|
||||
p_page_data->update_event_count = p_incoming_data->update_event_count;
|
||||
p_page_data->tick = p_incoming_data->tick;
|
||||
p_page_data->period = uint16_decode(p_incoming_data->period);
|
||||
p_page_data->accumulated_torque = uint16_decode(p_incoming_data->accumulated_torque);
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(ANT_BPWR)
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGE_TORQUE_COMMON_H__
|
||||
#define ANT_BPWR_PAGE_TORQUE_COMMON_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bicycle_p_page_torque Bicycle Power profile pages 17, 18 (commons)
|
||||
* @{
|
||||
* @ingroup ant_sdk_profiles_bpwr_pages
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Common data structure for Bicycle Power data pages 17, 18.
|
||||
*
|
||||
* @note This structure implements specific data that is common for pages 17, 18.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t update_event_count; ///< Power event count.
|
||||
uint8_t tick; ///< Wheel/crank revolutions counter.
|
||||
uint16_t period; ///< Accumulated wheel/crank period (1/2048 s).
|
||||
uint16_t accumulated_torque; ///< Accumulated wheel/torque (1/32 Nm).
|
||||
} ant_bpwr_page_torque_data_t;
|
||||
|
||||
/**@brief Initialize page torque.
|
||||
*/
|
||||
#define DEFAULT_ANT_BPWR_PAGE_TORQUE(up_evt_cnt, def_tick, def_period, acc_torque) \
|
||||
{ \
|
||||
.update_event_count = (up_evt_cnt), \
|
||||
.tick = (def_tick), \
|
||||
.period = (def_period), \
|
||||
.accumulated_torque = (acc_torque) \
|
||||
}
|
||||
|
||||
/**@brief Function for encoding pages 17, 18.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
* @param[out] p_page_buffer Pointer to the data buffer.
|
||||
*/
|
||||
void ant_bpwr_page_torque_encode(uint8_t * p_page_buffer,
|
||||
ant_bpwr_page_torque_data_t const * p_page_data);
|
||||
|
||||
/**@brief Function for decoding pages 17, 18.
|
||||
*
|
||||
* @param[in] p_page_buffer Pointer to the data buffer.
|
||||
* @param[out] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_torque_decode(uint8_t const * p_page_buffer,
|
||||
ant_bpwr_page_torque_data_t * p_page_data);
|
||||
|
||||
/**@brief Function for logging pages 17, 18.
|
||||
*
|
||||
* @param[in] p_page_data Pointer to the page data.
|
||||
*/
|
||||
void ant_bpwr_page_torque_log(ant_bpwr_page_torque_data_t const * p_page_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGE_TORQUE_COMMON_H__
|
||||
/** @} */
|
||||
69
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_pages.h
Normal file
69
components/ant/ant_profiles/ant_bpwr/pages/ant_bpwr_pages.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_PAGES_H__
|
||||
#define ANT_BPWR_PAGES_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_pages Bicycle Power profile pages
|
||||
* @{
|
||||
* @ingroup ant_bpwr
|
||||
* @brief This module implements functions for the BPWR data pages.
|
||||
*/
|
||||
|
||||
#include "ant_bpwr_page_1.h" // Calibration message main data page.
|
||||
#include "ant_bpwr_page_16.h" // Standard power-only page.
|
||||
#include "ant_bpwr_page_17.h" // Wheel Torque main data page.
|
||||
#include "ant_bpwr_page_18.h" // Crank Torque main data page.
|
||||
#include "ant_bpwr_common_data.h" // Instantaneous cadence data.
|
||||
#include "ant_common_page_80.h" // Manufacturer's information data page.
|
||||
#include "ant_common_page_81.h" // Product information data page.
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_PAGES_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "ant_bpwr_simulator.h"
|
||||
#include "app_util.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#define POWER_MIN 0
|
||||
#define POWER_MAX 2000
|
||||
#define POWER_INCR 10
|
||||
|
||||
#define CADENCE_MIN 0
|
||||
#define CADENCE_MAX (UINT8_MAX - 1)
|
||||
#define CADENCE_INCR 1
|
||||
|
||||
#define PEDAL_MIN 0
|
||||
#define PEDAL_MAX 100
|
||||
#define PEDAL_INCR 1
|
||||
|
||||
#define TORQUE_PERIOD 774
|
||||
#define SIMULATOR_TIME_INCREMENT BPWR_MSG_PERIOD
|
||||
|
||||
#define TORQUE_INCR 10
|
||||
|
||||
|
||||
void ant_bpwr_simulator_init(ant_bpwr_simulator_t * p_simulator,
|
||||
ant_bpwr_simulator_cfg_t const * p_config,
|
||||
bool auto_change)
|
||||
{
|
||||
p_simulator->p_profile = p_config->p_profile;
|
||||
p_simulator->_cb.auto_change = auto_change;
|
||||
p_simulator->_cb.tick_incr = 0;
|
||||
|
||||
p_simulator->_cb.power_sensorsim_cfg.min = POWER_MIN;
|
||||
p_simulator->_cb.power_sensorsim_cfg.max = POWER_MAX;
|
||||
p_simulator->_cb.power_sensorsim_cfg.incr = POWER_INCR;
|
||||
p_simulator->_cb.power_sensorsim_cfg.start_at_max = false;
|
||||
|
||||
p_simulator->_cb.cadence_sensorsim_cfg.min = CADENCE_MIN;
|
||||
p_simulator->_cb.cadence_sensorsim_cfg.max = CADENCE_MAX;
|
||||
p_simulator->_cb.cadence_sensorsim_cfg.incr = CADENCE_INCR;
|
||||
p_simulator->_cb.cadence_sensorsim_cfg.start_at_max = false;
|
||||
|
||||
p_simulator->_cb.pedal_sensorsim_cfg.min = PEDAL_MIN;
|
||||
p_simulator->_cb.pedal_sensorsim_cfg.max = PEDAL_MAX;
|
||||
p_simulator->_cb.pedal_sensorsim_cfg.incr = PEDAL_INCR;
|
||||
p_simulator->_cb.pedal_sensorsim_cfg.start_at_max = false;
|
||||
|
||||
p_simulator->p_profile->BPWR_PROFILE_pedal_power.differentiation = 0x01; // right
|
||||
|
||||
sensorsim_init(&(p_simulator->_cb.power_sensorsim_state),
|
||||
&(p_simulator->_cb.power_sensorsim_cfg));
|
||||
sensorsim_init(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg));
|
||||
sensorsim_init(&(p_simulator->_cb.pedal_sensorsim_state),
|
||||
&(p_simulator->_cb.pedal_sensorsim_cfg));
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_simulator_one_iteration(ant_bpwr_simulator_t * p_simulator, ant_bpwr_evt_t event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case ANT_BPWR_PAGE_16_UPDATED:
|
||||
|
||||
if (p_simulator->_cb.auto_change)
|
||||
{
|
||||
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.power_sensorsim_state),
|
||||
&(p_simulator->_cb.power_sensorsim_cfg)));
|
||||
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg)));
|
||||
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.pedal_sensorsim_state),
|
||||
&(p_simulator->_cb.pedal_sensorsim_cfg)));
|
||||
}
|
||||
|
||||
p_simulator->p_profile->BPWR_PROFILE_instantaneous_power =
|
||||
p_simulator->_cb.power_sensorsim_state.current_val;
|
||||
p_simulator->p_profile->BPWR_PROFILE_accumulated_power +=
|
||||
p_simulator->_cb.power_sensorsim_state.current_val;
|
||||
|
||||
if (p_simulator->p_profile->BPWR_PROFILE_accumulated_power == UINT16_MAX)
|
||||
{
|
||||
p_simulator->p_profile->BPWR_PROFILE_accumulated_power = 0;
|
||||
}
|
||||
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
|
||||
p_simulator->_cb.cadence_sensorsim_state.current_val;
|
||||
p_simulator->p_profile->BPWR_PROFILE_pedal_power.distribution =
|
||||
p_simulator->_cb.pedal_sensorsim_state.current_val;
|
||||
p_simulator->p_profile->BPWR_PROFILE_power_update_event_count++;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_17_UPDATED:
|
||||
|
||||
if (p_simulator->_cb.auto_change)
|
||||
{
|
||||
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg)));
|
||||
}
|
||||
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
|
||||
p_simulator->_cb.cadence_sensorsim_state.current_val;
|
||||
p_simulator->p_profile->BPWR_PROFILE_wheel_period += TORQUE_PERIOD;
|
||||
p_simulator->_cb.tick_incr +=
|
||||
SIMULATOR_TIME_INCREMENT;
|
||||
p_simulator->p_profile->BPWR_PROFILE_wheel_tick +=
|
||||
p_simulator->_cb.tick_incr / (TORQUE_PERIOD * 16);
|
||||
p_simulator->_cb.tick_incr =
|
||||
p_simulator->_cb.tick_incr % (TORQUE_PERIOD * 16);
|
||||
p_simulator->p_profile->BPWR_PROFILE_wheel_accumulated_torque += TORQUE_INCR;
|
||||
p_simulator->p_profile->BPWR_PROFILE_wheel_update_event_count++;
|
||||
break;
|
||||
|
||||
case ANT_BPWR_PAGE_18_UPDATED:
|
||||
|
||||
if (p_simulator->_cb.auto_change)
|
||||
{
|
||||
UNUSED_PARAMETER(sensorsim_measure(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg)));
|
||||
}
|
||||
p_simulator->p_profile->BPWR_PROFILE_instantaneous_cadence =
|
||||
p_simulator->_cb.cadence_sensorsim_state.current_val;
|
||||
p_simulator->p_profile->BPWR_PROFILE_crank_period = TORQUE_PERIOD;
|
||||
p_simulator->_cb.tick_incr +=
|
||||
SIMULATOR_TIME_INCREMENT;
|
||||
p_simulator->p_profile->BPWR_PROFILE_crank_tick +=
|
||||
p_simulator->_cb.tick_incr / (TORQUE_PERIOD * 16);
|
||||
p_simulator->_cb.tick_incr =
|
||||
p_simulator->_cb.tick_incr % (TORQUE_PERIOD * 16);
|
||||
p_simulator->p_profile->BPWR_PROFILE_crank_accumulated_torque += TORQUE_INCR;
|
||||
p_simulator->p_profile->BPWR_PROFILE_crank_update_event_count++;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_simulator_increment(ant_bpwr_simulator_t * p_simulator)
|
||||
{
|
||||
if (!p_simulator->_cb.auto_change)
|
||||
{
|
||||
sensorsim_increment(&(p_simulator->_cb.power_sensorsim_state),
|
||||
&(p_simulator->_cb.power_sensorsim_cfg));
|
||||
sensorsim_increment(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg));
|
||||
sensorsim_increment(&(p_simulator->_cb.pedal_sensorsim_state),
|
||||
&(p_simulator->_cb.pedal_sensorsim_cfg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ant_bpwr_simulator_decrement(ant_bpwr_simulator_t * p_simulator)
|
||||
{
|
||||
if (!p_simulator->_cb.auto_change)
|
||||
{
|
||||
sensorsim_decrement(&(p_simulator->_cb.power_sensorsim_state),
|
||||
&(p_simulator->_cb.power_sensorsim_cfg));
|
||||
sensorsim_decrement(&(p_simulator->_cb.cadence_sensorsim_state),
|
||||
&(p_simulator->_cb.cadence_sensorsim_cfg));
|
||||
sensorsim_decrement(&(p_simulator->_cb.pedal_sensorsim_state),
|
||||
&(p_simulator->_cb.pedal_sensorsim_cfg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_SIMULATOR_H__
|
||||
#define ANT_BPWR_SIMULATOR_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_simulators ANT simulators
|
||||
* @ingroup ant_sdk_utils
|
||||
* @brief Modules that simulate sensors.
|
||||
*
|
||||
* @defgroup ant_sdk_bpwr_simulator ANT BPWR simulator
|
||||
* @{
|
||||
* @ingroup ant_sdk_simulators
|
||||
* @brief ANT BPWR simulator module.
|
||||
*
|
||||
* @details This module simulates power for the ANT BPWR profile. The module calculates
|
||||
* abstract values, which are handled by the BPWR pages data model to ensure that they are
|
||||
* compatible. It provides a handler for changing the power value manually and functionality
|
||||
* for changing the power automatically.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bsp.h"
|
||||
#include "ant_bpwr.h"
|
||||
#include "sensorsim.h"
|
||||
#include "ant_bpwr_simulator_local.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief BPWR simulator configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
ant_bpwr_profile_t * p_profile; ///< Related profile.
|
||||
ant_bpwr_torque_t sensor_type; ///< Type of related sensor.
|
||||
} ant_bpwr_simulator_cfg_t;
|
||||
|
||||
/**@brief BPWR simulator structure. */
|
||||
typedef struct
|
||||
{
|
||||
ant_bpwr_profile_t * p_profile; ///< Related profile.
|
||||
ant_bpwr_simulator_cb_t _cb; ///< Internal control block.
|
||||
} ant_bpwr_simulator_t;
|
||||
|
||||
|
||||
/**@brief Function for initializing the ANT BPWR simulator instance.
|
||||
*
|
||||
* @param[in] p_simulator Pointer to the simulator instance.
|
||||
* @param[in] p_config Pointer to the simulator configuration structure.
|
||||
* @param[in] auto_change Enable or disable automatic changes of the power.
|
||||
*/
|
||||
void ant_bpwr_simulator_init(ant_bpwr_simulator_t * p_simulator,
|
||||
ant_bpwr_simulator_cfg_t const * p_config,
|
||||
bool auto_change);
|
||||
|
||||
/**@brief Function for simulating a device event.
|
||||
*
|
||||
* @details Based on this event, the transmitter data is simulated.
|
||||
*
|
||||
* This function should be called in the BPWR TX event handler.
|
||||
*/
|
||||
void ant_bpwr_simulator_one_iteration(ant_bpwr_simulator_t * p_simulator, ant_bpwr_evt_t event);
|
||||
|
||||
/**@brief Function for incrementing the power value.
|
||||
*
|
||||
* @param[in] p_simulator Pointer to the simulator instance.
|
||||
*/
|
||||
void ant_bpwr_simulator_increment(ant_bpwr_simulator_t * p_simulator);
|
||||
|
||||
/**@brief Function for decrementing the power value.
|
||||
*
|
||||
* @param[in] p_simulator Pointer to the simulator instance.
|
||||
*/
|
||||
void ant_bpwr_simulator_decrement(ant_bpwr_simulator_t * p_simulator);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_SIMULATOR_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_SIMULATOR_LOCAL_H__
|
||||
#define ANT_BPWR_SIMULATOR_LOCAL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bsp.h"
|
||||
#include "ant_bpwr.h"
|
||||
#include "sensorsim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup ant_sdk_bpwr_simulator
|
||||
* @brief BPWR simulator control block structure. */
|
||||
typedef struct
|
||||
{
|
||||
bool auto_change; ///< Power will change automatically (if auto_change is set) or manually.
|
||||
uint32_t tick_incr; ///< Fractional part of tick increment.
|
||||
sensorsim_state_t power_sensorsim_state; ///< Power state of the simulated sensor.
|
||||
sensorsim_cfg_t power_sensorsim_cfg; ///< Power configuration of the simulated sensor.
|
||||
sensorsim_state_t cadence_sensorsim_state; ///< Cadence stated of the simulated sensor.
|
||||
sensorsim_cfg_t cadence_sensorsim_cfg; ///< Cadence configuration of the simulated sensor.
|
||||
sensorsim_state_t pedal_sensorsim_state; ///< Pedal state of the simulated sensor.
|
||||
sensorsim_cfg_t pedal_sensorsim_cfg; ///< Pedal configuration of the simulated sensor.
|
||||
}ant_bpwr_simulator_cb_t;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_SIMULATOR_LOCAL_H__
|
||||
86
components/ant/ant_profiles/ant_bpwr/utils/ant_bpwr_utils.h
Normal file
86
components/ant/ant_profiles/ant_bpwr/utils/ant_bpwr_utils.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef ANT_BPWR_UTILS_H__
|
||||
#define ANT_BPWR_UTILS_H__
|
||||
|
||||
#include "app_util.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "nrf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ant_sdk_profiles_bpwr_utils Bicycle Power profile utilities
|
||||
* @{
|
||||
* @ingroup ant_bpwr
|
||||
* @brief This module implements utilities for the Bicycle Power profile.
|
||||
*
|
||||
*/
|
||||
|
||||
/*@brief A reversal of torque period unit.
|
||||
*
|
||||
* @details According to the ANT BPWR specification, the torque period unit is 1/2048 of a second.
|
||||
*/
|
||||
#define ANT_BPWR_TORQUE_PERIOD_UNIT_REVERSAL 2048
|
||||
#define ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION 1000
|
||||
#define ANT_BPWR_TORQUE_PERIOD_RESCALE(VALUE) value_rescale((VALUE), ANT_BPWR_TORQUE_PERIOD_UNIT_REVERSAL, \
|
||||
ANT_BPWR_TORQUE_PERIOD_DISP_PRECISION)
|
||||
|
||||
/*@brief A reversal of accumulated torque unit.
|
||||
*
|
||||
* @details According to the ANT BPWR specification, the accumulated torque unit is 1/32 of a Nm.
|
||||
*/
|
||||
#define ANT_BPWR_ACC_TORQUE_UNIT_REVERSAL 32
|
||||
#define ANT_BPWR_ACC_TORQUE_DISP_PRECISION 10
|
||||
#define ANT_BPWR_ACC_TORQUE_RESCALE(VALUE) value_rescale((VALUE), ANT_BPWR_ACC_TORQUE_UNIT_REVERSAL, \
|
||||
ANT_BPWR_ACC_TORQUE_DISP_PRECISION)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ANT_BPWR_UTILS_H__
|
||||
|
||||
Reference in New Issue
Block a user