[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)

时间:2022-10-31 20:56:03


数据页34是发送到ANT+自行车灯以控制该灯的命令页。所有ANT+自行车灯均应响应此页面,所有ANT+控制器均应支持发送此页面。该命令应作为确认消息从ANT+控制器发送。当灯光索引字段设置为0x00时,主灯光应使用广播消息在共享信道上发送此命令。当光指标为2–63时,可以使用已确认的消息,在这种情况下,允许重试。该消息中的所有字段均应按照表7-39中的说明进行设置。

Table 7-39. 数据页34格式–灯光设置

[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)


[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)

7.18.1 灯光索引
灯光索引字段用于指示哪个ANT+自行车灯应应用命令的灯光设置。如果此字段设置为0x00,则所有灯都应响应(请注意,子灯索引字段仍然适用)。如果将灯光指数设置为任何其他值,则只有具有匹配灯光指数的ANT+自行车灯才应响应。
7.18.2 子灯索引
子光源索引字段指示应对其应用命令的灯光设置的子光源。如果子灯索引设置为0,则命令的灯设置应仅应用于主要ANT+自行车灯,而不应用于任何子灯。
要寻址主光源和所有子光源,应将子光源索引字段设置为0,并将子光源地址标志设置为1。

7.18.3 子灯地址标志
子灯地址标志指示是否应将灯设置应用于子灯索引字段所指示的特定主/子灯,还是应用于ANT+自行车灯上的所有主/子灯。如果子灯地址标志设置为0,则应用子灯索引字段。
如果子灯地址标志设置为1,则副灯索引字段将被忽略.

7.18.4 灯光类型
请注意,只有在将灯光索引字段设置为0并将子灯光索引字段设置为0,并且将子灯光地址标志设置为1的情况下,才应解释灯光类型字段。
灯光类型字段指示应响应该命令的ANT+自行车灯的类型。如果指示“信号灯–全部”,则该命令适用于所有信号灯,包括可配置的,左侧和右侧。如果光源类型字段设置为无效,则命令的光源设置应应用于所有光源类型。
有关处理“灯光设置”命令的详细决策树,请参阅第7.18.10节。

[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)

7.18.5 控制器ID

控制器ID字段应由ANT+控制器使用其序列号的LSB填充。没有序列号的ANT+控制器应为该字段分配一个固定值。

7.18.6 设置自动灯光亮度模式

自动亮度模式设置允许ANT+控制器在ANT+自行车灯上启用或禁用自动亮度模式,以指示对该功能的支持(请参阅第7.5.1节)。如果遥控器不打算修改当前的自动强度模式设置,则遥控器应将该字段设置为0x03(无效)。

[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)

7.18.7 Brake Override Setting

7.18.8 灯光档位调整
调整光束的焦点或强度。如果此字段设置为0xFF,则自行车灯不应改变其光束焦点。

7.18.9 设置灯光状态
“设置指示灯状态”字段中指示的设置应按下表所示进行解释。

[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)

请注意,ANT+控制器不应尝试将ANT+自行车灯设置为它不支持的模式。如果ANT+自行车灯收到命令要求其切换到不受支持的模式,则该命令将被忽略。

7.18.10 用于处理灯光设置命令的决策树

灯光索引,子灯光索引和灯光类型字段将用于 [确定应用接收到的命令]、[指定的设置的主灯光和子灯光]。

[ANT+][nrf51422][s210] 自行车车灯 数据页34 –灯光设置(0x22)


Figure 7-9. 应用灯光设置命令

/* 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_34.h"
#include "ant_BikeLight_utils.h"
#include "ant_BikeLight_page_logger.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#include "main.h"
/*************Light_State_ModeNum***当前模式号************************
0 灯光关闭
1 常亮:81 - 100%亮度
2 常亮:61 - 80%亮度
3 常亮:41 - 60%亮度
4 常亮:21 - 40%亮度
5 常亮: 0 - 20%亮度
6 慢闪烁
7 快速闪烁
8 随机闪烁
9 自动
10 左转信号灯(自动取消)
11 左转信号灯(持续)
12 右转信号灯(自动取消)
13 右转信号灯(持续)
14 危险指示灯(左右指示灯连续闪烁)
15:47 保留以备将来使用。不要使用。
48 自定义模式48
X 自定义模式“X”
63 自定义模式63
**********************************/
/*************Beam_Adjustment***灯光调整说明符************************
0xFF: 不调整灯光聚焦或亮度
无调整: 设置为0xFF
灯光焦点调整:0-100%,增量为1%
灯光亮度调整:0-100%,增量为1%
同时进行灯光聚焦和亮度调整:
位0-3:灯光聚焦(单位6.67%)
位4-7:灯光亮度(单位6.67%)
最大光束焦点的百分比。
无效:0xFF
**********************************/

/**@brief BikeLight 灯光设置 (0x22) 第34页数据布局结构. */
typedef struct
{
uint8_t Light_Index; //灯光索引 0-63

uint8_t SubLight_Index : 3; //子灯索引 [0-4] 5-7:保留,请勿使用
uint8_t Light_State_Setting : 1; //灯光状态设置 [0-1] 0:地址特定的子灯 1:处理主光和所有子光
uint8_t Light_Type_Setting : 4; //灯光类型设置 [0-15] 0:前灯 2:尾灯 3:信号灯 4:信号灯-左 5:信号灯-右

uint8_t Sequence_Number; //顺序号:每个新命令递增 [0,255]
uint8_t Controller_ID; //控制器ID [0-255]

uint8_t Auto_Intensity_Mode_Setting : 2; //自动灯光亮度模式 0:无效 1:禁用 2:启动 3:保留
uint8_t Brake_Override_Setting : 2; //刹车控制设置 0:无效 1:强制刹车事件 2:取消刹车事件 3:保留
uint8_t Beam_Adjustment_Specifier_focus : 1; //灯光聚焦 0--可以调整 1--不可以调整
uint8_t Beam_Adjustment_Specifier_intensity : 1; //灯光亮度 0--不可以调整 1--可以调整
uint8_t Reserved : 2; //

uint8_t Set_Light_State_Beam : 2; //灯光类型 0--无效 1--关闭 2--近光灯(默认) 3:远光灯
uint8_t Set_Light_State_ModeNum : 6; //当前模式号 0--无效 [1-63]--模式n
uint8_t Beam_Adjustment; //灯光调整:见上方注解
} ant_BikeLight_page34_data_layout_t;


static void page34_data_log(ant_BikeLight_page34_data_t const *p_page_data)
{
SEGGER_RTT_printf(0, "page34:Last_Sequence_Number: %d\r\n", (uint8_t)p_page_data->Sequence_Number);
SEGGER_RTT_printf(0, "page34:Set_Light_State_Beam: %d\r\n", (uint8_t)p_page_data->Set_Light_State_Beam);
SEGGER_RTT_printf(0, "page34:Set_Light_State_ModeNum: %d\r\n", (uint8_t)p_page_data->Set_Light_State_ModeNum);
}

uint8_t Cmd_off = 0;

void ant_BikeLight_page_34_encode(uint8_t *p_page_buffer,
ant_BikeLight_page34_data_t const *p_page_data)
{
ant_BikeLight_page34_data_layout_t *p_outcoming_data = (ant_BikeLight_page34_data_layout_t *)p_page_buffer;

p_outcoming_data->Light_Index = p_page_data->Light_Index;
p_outcoming_data->SubLight_Index = p_page_data->SubLight_Index;
p_outcoming_data->Light_State_Setting = p_page_data->Light_State_Setting;
p_outcoming_data->Light_Type_Setting = p_page_data->Light_Type_Setting;
p_outcoming_data->Sequence_Number = p_page_data->Sequence_Number;
p_outcoming_data->Controller_ID = p_page_data->Controller_ID;
p_outcoming_data->Auto_Intensity_Mode_Setting = p_page_data->Auto_Intensity_Mode_Setting;
p_outcoming_data->Brake_Override_Setting = p_page_data->Brake_Override_Setting;
p_outcoming_data->Beam_Adjustment_Specifier_focus = p_page_data->Beam_Adjustment_Specifier_focus;
p_outcoming_data->Beam_Adjustment_Specifier_intensity = p_page_data->Beam_Adjustment_Specifier_intensity;
p_outcoming_data->Set_Light_State_Beam = p_page_data->Set_Light_State_Beam;
p_outcoming_data->Set_Light_State_ModeNum = m_ant_BikeLight.page_1.Light_State_ModeNum;
p_outcoming_data->Beam_Adjustment = p_page_data->Beam_Adjustment;


page34_data_log(p_page_data);
}


void ant_BikeLight_page_34_decode(uint8_t const *p_page_buffer,
ant_BikeLight_page34_data_t *p_page_data,
uint8_t const Channel)
{
ant_BikeLight_page34_data_layout_t const *p_incoming_data =
(ant_BikeLight_page34_data_layout_t *)p_page_buffer;

if (p_incoming_data->Light_Index == 0 || p_incoming_data->Light_Index == m_ant_BikeLight.page_1.Light_Index)//判断灯光索引
{
p_page_data->Light_Index = p_incoming_data->Light_Index;
p_page_data->Sequence_Number = p_incoming_data->Sequence_Number;
p_page_data->Controller_ID = p_incoming_data->Controller_ID;
if (m_ant_BikeLight.page_1.Last_Sequence_Number != p_incoming_data->Sequence_Number)
{
SystemReg.Burst_update_channel_1 = 1;//突发消息发送Page1
m_ant_BikeLight.page_1.Last_Sequence_Number = p_incoming_data->Sequence_Number;
}
m_ant_BikeLight.page_1.Last_Sequence_Number = p_incoming_data->Sequence_Number;
if (p_incoming_data->Set_Light_State_ModeNum == 0 && p_incoming_data->Set_Light_State_Beam == 0)
{
return;
}
if (p_incoming_data->Set_Light_State_ModeNum == 2)//没有的模式号不更新
{

}
else//p_incoming_data->Set_Light_State_Beam!=0
{
if (p_incoming_data->Set_Light_State_ModeNum != 0)
{
p_page_data->Set_Light_State_ModeNum = p_incoming_data->Set_Light_State_ModeNum;//更新当前灯光模式
m_ant_BikeLight.page_1.Light_State_ModeNum = p_incoming_data->Set_Light_State_ModeNum;//更新数据1的当前灯光模式
}
else if (p_incoming_data->Set_Light_State_Beam == 1)
{
m_ant_BikeLight.page_1.Light_State_ModeNum = 0;//更新数据1的当前灯光模式
}
}



if (m_ant_BikeLight.page_1.Light_State_ModeNum == 0) //灯光关闭
{
System_shutdown_count = 0;
SystemReg.LED_ONOFF = 1;
LowPower_Tmr = 0;
}
else if (m_ant_BikeLight.page_1.Light_State_ModeNum != 0) //调整灯光
{
System_shutdown_count = 0;

LowPower_Tmr = 0;
/*开机*/
SystemReg.RunningState = 0;//开机
SystemReg.LED_ONOFF = 0; //开灯
switch (m_ant_BikeLight.page_1.Light_State_ModeNum)
{
case 1://常亮:81 - 100%亮度
SystemReg.Level = 2;
break;
case 3://常亮:41 - 60%亮度
SystemReg.Level = 1;
break;
case 4://常亮:21 - 40%亮度
SystemReg.Level = 0;
break;
case 6://慢闪烁
SystemReg.Level = 3;
break;
case 7://快速闪烁
SystemReg.Level = 4;
break;
default:
break;
}
SEGGER_RTT_printf(0, "Light_State_ModeNum:[%d]:\r\n", m_ant_BikeLight.page_1.Light_State_ModeNum);
}
System_shutdown_count = 0;
/*记录车灯组网数量,用于共享通道70页的轮询*/
if (SystemReg.ANT_Networking_Number < p_incoming_data->Light_Index)
{
SystemReg.ANT_Networking_Number = p_incoming_data->Light_Index;
}

if (p_incoming_data->Light_Index == 0 && Channel == 0 && m_ant_BikeLight.page_1.Light_Index == 1 && ANT_Relay_New_Share_Page != 32 && p_incoming_data->Light_Index != ANT_message_payload_Shared_Wait[0] && p_incoming_data->Sequence_Number != ANT_message_payload_Shared_Wait[3]) //当灯光索引字段设置为 0x00 时,主灯光应使用广播消息在共享信道上发送此命令。
{
memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page34_data_layout_t));//复制非自身内容至共享通道缓存区
ANT_Relay_New_Share_Page = 34; //发送指定页
ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
SEGGER_RTT_printf(0, "Forward [Page34] to shared channel\r\n");
}
// page34_data_log(p_page_data);
}
else //不是自己的内容就转发
{
/*记录车灯组网数量,用于共享通道70页的轮询*/
if (SystemReg.ANT_Networking_Number < p_incoming_data->Light_Index)
{
SystemReg.ANT_Networking_Number = p_incoming_data->Light_Index;
}
if (ANT_Relay_New_Share_Page != 32 && p_incoming_data->Sequence_Number != ANT_message_payload_Shared_Wait[3])
{
/*防止转播过程中,进入低功耗*/
LowPower_Tmr = 0;
System_shutdown_count = 0;
/*当自己是主灯时,手动对副灯写入[最后命令字节]*/
if (m_ant_BikeLight.page_1.Light_Index == 1)
{
switch (p_incoming_data->Light_Index)
{
case 2:
ANT_message_payload_Wait_2[5] = p_incoming_data->Sequence_Number;
SEGGER_RTT_printf(0, "[See2---Page_1: %02X %02X %02X %02X %02X %02X %02X %02X]\n\r", \
1, Replace_Buff(ANT_message_payload_Wait_2));

break;
case 3:
ANT_message_payload_Wait_3[5] = p_incoming_data->Sequence_Number;
SEGGER_RTT_printf(0, "[See3---Page_1: %02X %02X %02X %02X %02X %02X %02X %02X]\n\r", \
1, Replace_Buff(ANT_message_payload_Wait_3));
break;
case 4:
ANT_message_payload_Wait_4[5] = p_incoming_data->Sequence_Number;
break;
case 5:
ANT_message_payload_Wait_5[5] = p_incoming_data->Sequence_Number;
break;
case 6:
ANT_message_payload_Wait_6[5] = p_incoming_data->Sequence_Number;
break;
case 7:
ANT_message_payload_Wait_7[5] = p_incoming_data->Sequence_Number;
break;
case 8:
ANT_message_payload_Wait_8[5] = p_incoming_data->Sequence_Number;
break;
case 9:
ANT_message_payload_Wait_9[5] = p_incoming_data->Sequence_Number;
break;
case 10:
ANT_message_payload_Wait_10[5] = p_incoming_data->Sequence_Number;
break;
default:
break;
}
}
memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page34_data_layout_t));//复制非自身内容至共享通道缓存区
ANT_Relay_New_Share_Page = 34; //发送指定页
ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
SEGGER_RTT_printf(0, "Forward [Page34] to shared channel\r\n");
}
else if (ANT_Relay_New_Share_Page != 32 && (p_incoming_data->Light_Index == ANT_message_payload_Shared_Wait[0] || p_incoming_data->Sequence_Number == ANT_message_payload_Shared_Wait[3]))
{
SEGGER_RTT_printf(0, "Not Forward [Page34] to shared channel. Because repetition!\r\n");
}
// if (Channel == 1 && m_ant_BikeLight.page_1.Light_Index != 1)
// {
// if (ANT_Relay_New_Share_Page != 32 && ANT_Relay_New_Share_Page!=34)
// {
// memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page34_data_layout_t));//复制非自身内容至共享通道缓存区
// ANT_Relay_New_Share_Page = 34; //发送指定页
// ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
SEGGER_RTT_printf(0, "Forward [Page34] to shared channel.\r\n", (uint8_t)p_page_data->Light_Index);
// }
// }
}
}
/* 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_34_H__
#define ANT_BIKELIGHT_PAGE_34_H__

/*************Beam_Adjustment***灯光调整说明符************************
0xFF:不调整灯光聚焦或亮度
无调整:设置为0xFF
灯光焦点调整:0-100%,增量为1%
灯光亮度调整:0-100%,增量为1%
同时进行灯光聚焦和亮度调整:
位0-3:灯光聚焦(单位6.67%)
位4-7:灯光亮度(单位6.67%)
最大光束焦点的百分比。
无效:0xFF
**********************************/

#include <stdint.h>

typedef struct
{
uint8_t Light_Index; //灯光索引 0-63

uint8_t SubLight_Index : 3; //子灯索引 [0-4] 5-7:保留,请勿使用
uint8_t Light_State_Setting : 1; //灯光状态设置 [0-1] 0:地址特定的子灯 1:处理主光和所有子光
uint8_t Light_Type_Setting : 4; //灯光类型设置 [0-15] 0:前灯 2:尾灯 3:信号灯 4:信号灯-左 5:信号灯-右

uint8_t Sequence_Number; //顺序号:每个新命令递增 [0,255]
uint8_t Controller_ID; //控制器ID [0-255]

uint8_t Auto_Intensity_Mode_Setting : 2; //自动灯光亮度模式 0:无效 1:禁用 2:启动 3:保留
uint8_t Brake_Override_Setting : 2; //刹车控制设置 0:无效 1:强制刹车事件 2:取消刹车事件 3:保留
uint8_t Beam_Adjustment_Specifier_focus : 1; //灯光聚焦 0--可以调整 1--不可以调整
uint8_t Beam_Adjustment_Specifier_intensity : 1; //灯光亮度 0--不可以调整 1--可以调整
uint8_t Reserved : 2; //

uint8_t Set_Light_State_Beam : 2; //灯光类型 0--无效 1--关闭 2--近光灯(默认) 3:远光灯
uint8_t Set_Light_State_ModeNum : 6; //当前模式号 0--无效 [1-63]--模式n
uint8_t Beam_Adjustment; //灯光调整:见上方注解

} ant_BikeLight_page34_data_t;


#define DEFAULT_ANT_BikeLight_PAGE34() \
(ant_BikeLight_page34_data_t) \
{ \
.Light_Index = 0, \
.SubLight_Index = 0, \
.Light_State_Setting = 0, \
.Light_Type_Setting = 0, \
.Sequence_Number = 0, \
.Controller_ID = 0, \
.Auto_Intensity_Mode_Setting = 0, \
.Brake_Override_Setting = 0, \
.Beam_Adjustment_Specifier_focus = 0, \
.Beam_Adjustment_Specifier_intensity = 1, \
.Set_Light_State_Beam = 2, \
.Set_Light_State_ModeNum = 0, \
.Beam_Adjustment = 0xFF, \
}


void ant_BikeLight_page_34_encode(uint8_t *p_page_buffer,
ant_BikeLight_page34_data_t const *p_page_data);


void ant_BikeLight_page_34_decode(uint8_t const *p_page_buffer,
ant_BikeLight_page34_data_t *p_page_data,
uint8_t const Channel);

#endif // ANT_BIKELIGHT_PAGE_34_H__
/** @} */