通用数据页70允许ANT+设备向另一个ANT+设备请求特定的数据页。在此设备配置文件中:
• 第70页允许控制器从ANT+自行车灯请求特定的数据页。该请求数据页应采用公认的MES发送下垂由ANT+控制器e和如图必须被格式化表7-45。
• 如第7.3.3.2节所述,主指示灯使用页面70的共享格式来请求辅助指示灯的数据页。建议将该页面作为广播消息发送(以减少功耗),但是也允许确认消息。请求数据页的格式应如表7-46所示。
7.22.3.1 灯光索引
当请求包含灯光索引字段的数据页时,灯光索引字段应用于指定灯光索引,否则应设置为无效。
7.22.3.2 描述符字节 1 & 2
描述符字节字段用于描述请求的子页面。
描述符字节1应该用于指定:
• 请求包含次要灯光索引(1-4、6、16、17)的数据页时的次要灯光索引
• 模式编号,当请求数据时第5页–模式说明
否则设置为无效.
描述符字节2应该设置为无效.
7.22.3.3 请求的传输响应
ANT+自行车灯应该能够支持所有请求的传输响应类型,然而,但是,ANT+自行车灯设备配置文件进一步规定,ANT+控制器只能请求广播信息。
请注意,某些ANT+自行车灯不支持发送已确认的消息,而将以广播消息作为响应,而不管请求的响应类型如何。
ANT+自行车灯仅需要支持最多两个传输响应重复,以最小化共享网络上的轮询内存要求。
有关请求数据页面和可能的请求传输响应类型的更多详细信息,请参阅ANT+ 常用页文档。
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#include "ant_BikeLight_page_70.h"
#include "ant_BikeLight_utils.h"
#include "ant_BikeLight_page_logger.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#include "main.h"
/**@brief BikeLight 请求数据页面 (0x46) 第70页数据布局结构. */
typedef struct
{
uint8_t Light_Index; //灯光索引 0-63
uint8_t reserved; //保留
uint8_t descriptor[2]; //描述符:允许在请求的数据页内指定数据。有效值:0–254 无效:255(0xFF)
uint8_t req_trans_response_Repetitions: 6; //请求的数据页,需要发送的测试。
uint8_t req_trans_response_MSB: 1; //请求的数据页,是否等待发送成功
uint8_t req_page_number; //请求的页码
uint8_t command_type; /*请求数据页的值 =1(0x01)请求ANT-FS会话的值=2(0x02)
从机请求数据页的值=3(0x03)请求数据页集的值 =4(0x04)*/
} ant_BikeLight_page70_data_layout_t;
//static void page70_data_log(ant_BikeLight_page70_data_t const *p_page_data)
//{
//// SEGGER_RTT_printf(0, "command_type: %d\r\n", (uint8_t)p_page_data->command_type);
//// SEGGER_RTT_printf(0, "req_page_number: %d\r\n", (uint8_t)p_page_data->req_page_number);
//}
void ant_BikeLight_page_70_encode(uint8_t *p_page_buffer,
ant_BikeLight_page70_data_t const *p_page_data)
{
ant_BikeLight_page70_data_layout_t *p_outcoming_data = (ant_BikeLight_page70_data_layout_t *)p_page_buffer;
memcpy(p_outcoming_data, p_page_data, sizeof(ant_BikeLight_page70_data_layout_t));
// ANT_PAGE_NEW = 0;
// page70_data_log(p_page_data);
}
void ant_BikeLight_page_70_decode(uint8_t const *p_page_buffer,
ant_BikeLight_page70_data_t *p_page_data,
uint8_t const Channel)
{
ant_BikeLight_page70_data_layout_t const *p_incoming_data = (ant_BikeLight_page70_data_layout_t *)p_page_buffer;
if (Channel == 0)
{
if (p_incoming_data->Light_Index == 0 || p_incoming_data->Light_Index == m_ant_BikeLight.page_1.Light_Index)//判断灯光索引
{
p_page_data->descriptor[0] = p_incoming_data->descriptor[0];
p_page_data->descriptor[1] = p_incoming_data->descriptor[1];
p_page_data->req_page_number = p_incoming_data->req_page_number;
p_page_data->command_type = (ant_page70_command_t)p_incoming_data->command_type;
if (p_page_data->command_type == 1) //请求数据页
{
if (p_page_data->req_page_number == 1 || p_page_data->req_page_number == 2 || \
p_page_data->req_page_number == 80 || p_page_data->req_page_number == 81 || p_page_data->req_page_number == 19)
{
switch (p_page_data->req_page_number)
{
case 1:
ANT_PAGE_NEW = 100;
break;
case 2:
ANT_PAGE_NEW = 0;
break;
case 80:
ANT_PAGE_NEW = 1;
break;
case 81:
ANT_PAGE_NEW = 2;
break;
case 19:
ANT_PAGE_NEW = 3;
break;
default:
break;
}
}
else
{
ANT_PAGE_NEW = p_page_data->req_page_number; //发送指定页
}
}
m_ant_BikeLight.page_1.Last_Sequence_Number = 70;
/*防止转播过程中,进入低功耗*/
LowPower_Tmr = 0;
System_shutdown_count = 0;
}
else//不是自己的东西,转发出去
{
if (p_incoming_data->Light_Index == 0xff)
{
LowPower_Tmr = 0;
System_shutdown_count = 0;
}
if (p_incoming_data->Light_Index != 0xff && ANT_Relay_New_Share_Page != 32)
{
memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page70_data_layout_t));//复制非自身内容至共享通道缓存区
ANT_Relay_New_Share_Page = 70; //发送指定页
ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
}
}
}
else if (Channel == BikeLight_Shared_CHANNEL_NUMBER) //共享通道发送过来的请求,需要把指定内容转发到广播通道
{
// SEGGER_RTT_printf(0, "[channel1_MY]---ID:%d %d req_page_number:%d\n\r", \
// m_ant_BikeLight.page_1.Light_Index,p_incoming_data->Light_Index, p_page_data->req_page_number); //c测试
/*防止转播过程中,进入低功耗*/
LowPower_Tmr = 0;
System_shutdown_count = 0;
if (p_incoming_data->Light_Index == m_ant_BikeLight.page_1.Light_Index)//判断灯光索引
{
p_page_data->descriptor[0] = p_incoming_data->descriptor[0];
p_page_data->descriptor[1] = p_incoming_data->descriptor[1];
p_page_data->req_page_number = p_incoming_data->req_page_number;
p_page_data->command_type = (ant_page70_command_t)p_incoming_data->command_type;
if (p_page_data->command_type == 1) //请求数据页
{
if (p_page_data->req_page_number == 1 || p_page_data->req_page_number == 2 || p_page_data->req_page_number == 19) //
{
if (ANT_Relay_New_Share_Page == 2 || ANT_Relay_New_Share_Page == 19)
{
return;
}
switch (p_page_data->req_page_number)
{
case 1:
memcpy(ANT_message_payload_Shared_Wait, &(m_ant_BikeLight.page_1), sizeof(ant_BikeLight_page1_data_t));//复制非自身内容至共享通道缓存区
break;
case 2:
memcpy(ANT_message_payload_Shared_Wait, &(m_ant_BikeLight.page_2), sizeof(ant_BikeLight_page2_data_t));//复制非自身内容至共享通道缓存区
break;
case 19:
memcpy(ANT_message_payload_Shared_Wait, &(m_ant_BikeLight.page_19), sizeof(ant_BikeLight_page19_data_t));//复制非自身内容至共享通道缓存区
break;
default:
break;
}
ANT_Relay_New_Share_Page = p_page_data->req_page_number; //发送指定页
ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
//err_code = sd_ant_broadcast_message_tx(BikeLight_Shared_CHANNEL_NUMBER, 8, ANT_message_payload_Shared);//发送共享命令
// if (p_page_data->req_page_number == 2)
// {
// SEGGER_RTT_printf(0, "[channel1_MY]---TX page_%02d: %02X %02X %02X %02X %02X %02X %02X %02X\n\r", \
// ANT_Relay_New_Share_Page, Replace_Buff(ANT_message_payload_Shared_Wait)); //打印发送共享命令
// }
}
}
}
}
}
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#ifndef ANT_BIKELIGHT_PAGE_70_H__
#define ANT_BIKELIGHT_PAGE_70_H__
#include <stdint.h>
#define ANT_COMMON_PAGE_70 (70) ///< @brief ID value of common page 70.
#define ANT_PAGE70_INVALID_DESCRIPTOR UINT16_MAX ///< Invalid descriptor.
/**@brief Command type.
*/
typedef enum
{
ANT_PAGE70_COMMAND_PAGE_DATA_REQUEST = 0x01, ///< 页面请求。
ANT_PAGE70_COMMAND_ANT_FS_SESSION_REQUEST = 0x02, ///< ANT FS会话请求。
} ant_page70_command_t;
typedef struct
{
uint8_t Light_Index; //灯光索引 0-63
uint8_t reserved; //保留
uint8_t descriptor[2]; //描述符:允许在请求的数据页内指定数据。有效值:0–254 无效:255(0xFF)
uint8_t req_trans_response_Repetitions: 6; //请求的数据页,需要发送的测试。(请求次数)
uint8_t req_trans_response_MSB: 1; //请求的数据页,是否等待发送成功
uint8_t req_page_number; //请求的页码
uint8_t command_type; /*请求数据页的值 =1(0x01)请求ANT-FS会话的值=2(0x02)
从机请求数据页的值=3(0x03)请求数据页集的值 =4(0x04)*/
} ant_BikeLight_page70_data_t;
/**@brief 用默认值初始化第70页。
*/
#define DEFAULT_ANT_COMMON_PAGE70() \
(ant_BikeLight_page70_data_t) \
{ \
.Light_Index = 0x02, \
.reserved = 0xFF, \
.descriptor[0] = 0xFF, \
.descriptor[1] = 0xFF, \
.req_trans_response_Repetitions = 3, \
.req_trans_response_MSB = 0, \
.req_page_number = 1, \
.command_type = 1, \
}
void ant_BikeLight_page_70_encode(uint8_t *p_page_buffer,
ant_BikeLight_page70_data_t const *p_page_data);
void ant_BikeLight_page_70_decode(uint8_t const *p_page_buffer,
ant_BikeLight_page70_data_t *p_page_data,
uint8_t const Channel);
#endif // ANT_BIKELIGHT_PAGE_70_H__
/** @} */