• 首页
  • 中国
  • [ANT+][nrf51422][s210] 自行车车灯 如何让码表搜索到车灯设备?

[ANT+][nrf51422][s210] 自行车车灯 如何让码表搜索到车灯设备?

2023-11-01 128浏览
百检网是一家专业的第三方检测平台,汇聚众多拥有权威资质的第三方检测机构为你提供一站式的检测服务,做检测就上百检网。百检网让检测从此检测,一份报告全国通用,专业值得信赖。

本文将用前灯为例子。

**

1. 车灯通道

**

对于车灯,必须要创建两个通道,分别为主通道和共享通道。

小提示:通道开启数量是固定的,不是动态开启。修改位置如下:(全局搜索)

关键字:ANT_CONFIG_TOTAL_CHANNELS_ALLOCATED

检测是否已连接(Light_Index!=0),成功连接后,才允许开启共享通道。

/*********************************************

函数名:ant_BikeLight_SHARED_MASTER_Init

功 能:共享通道初始化

形 参:ch--> 0--主灯共享通道(可发可接) 1--副灯共享通道(只接)

返回值:

备 注:

作 者:薛建强

时 间:2020/02/27

使 用:

**********************************************/

void ant_BikeLight_SHARED_MASTER_Init(void)

{

uint32_t err_code = 0;

uint8_t pucStatus = 0;

/*共享通道*/

if (SystemInit_Type.ANT_SHARED_CHANNEL == 0)

{

pucStatus = ant_BikeLight_Shared_close(ant_channel_Shared.channel_number);//关闭共享通道

if (pucStatus == 100) //通道成功未关闭

{

return;

}

else if ((pucStatus == 17) || (pucStatus == STATUS_ASSIGNED_CHANNEL))

{

err_code = sd_ant_channel_unassign(BikeLight_Shared_CHANNEL_NUMBER);

SEGGER_RTT_printf(0, "ANT BikeLight Shared channel_unassign %u close %dnr", BikeLight_Shared_CHANNEL_NUMBER, err_code);

}

if (m_ant_BikeLight.page_33.Light_Index_Set == 1)//ID=1,主灯

{

ant_channel_Shared.channel_type = BikeLight_SENS_CHANNEL_TYPE_Shared;

//ant_channel_Shared.device_number = BikeLight_DEVICE_NUMBER; //将ANT设备号设置为MAC地址

ant_channel_Shared.device_number = NRF_FICR->DEVICEADDR[0]; //将ANT设备号设置为MAC地址

}

else if (m_ant_BikeLight.page_33.Light_Index_Set > 1)//ID>1,副灯

{

ant_channel_Shared.channel_type = BikeLight_DISP_CHANNEL_TYPE_Shared;

//ant_channel_Shared.device_number = BikeLight_DEVICE_NUMBER; //将ANT设备号设置为MAC地址

ant_channel_Shared.device_number = NRF_FICR->DEVICEADDR[0]; //将ANT设备号设置为MAC地址

}

else

{

SEGGER_RTT_printf(0, "Shared_open_fail,not Light_Index!!! %drn", m_ant_BikeLight.page_33.Light_Index_Set);

return;

}

ant_channel_Shared.channel_number = BikeLight_Shared_CHANNEL_NUMBER; //通道号

ant_channel_Shared.ext_assign = BikeLight_EXT_ASSIGN; //ANT 外部分配.

ant_channel_Shared.rf_freq = BikeLight_ANTPLUS_RF_FREQ; //频率

ant_channel_Shared.transmission_type = m_ant_BikeLight.page_33.Transmission_Type; //主灯的传送类型

ant_channel_Shared.device_type = BikeLight_DEVICE_TYPE_Shared; //设备类型

ant_channel_Shared.device_number = m_ant_BikeLight.page_33.DeviceNumber_MSB << 8 | m_ant_BikeLight.page_33.DeviceNumber_LSB;

ant_channel_Shared.channel_period = BikeLight_MSG_PERIOD_8Hz;//消息周期

ant_channel_Shared.network_number = 0;

err_code = ant_channel_init(&ant_channel_Shared);

APP_ERROR_CHECK(err_code);

err_code = ant_BikeLight_Shared_open(&ant_channel_Shared);

SEGGER_RTT_printf(0, "Shared_open,err_code=%02X device_number:%d transmission_type:%drn", err_code, ant_channel_Shared.device_number, ant_channel_Shared.transmission_type);

APP_ERROR_CHECK(err_code);

if (SystemInit_Type.ANT_SHARED_CHANNEL == 1 && SystemReg.ANT_SHARED_CHANNEL == 2)

{

err_code = ANT_Send_Message(BikeLight_Shared_CHANNEL_NUMBER, ANT_message_payload_Shared_Wait);

ANT_Relay_New_Share_Page = 0; //发送指定页

}

}

}

**

2. 通道类型

**

/**@brief ANT channel configuration structure. */

typedef struct

{

uint8_t channel_number; ///< 分配的频道号。

uint8_t channel_type; ///< 通道类型 (see Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).

uint8_t ext_assign; ///< 扩展分配 (see Ext. Assign Channel Parameters in ant_parameters.h: @ref ant_parameters).

uint8_t rf_freq; ///< 射频偏移 2400 MHz (for example, 2466 MHz, ucFreq = 66).

uint8_t transmission_type; ///< 传输类型.

uint8_t device_type; ///< 设备类型.

uint16_t device_number; ///< 设备编号.

uint16_t channel_period; ///< 32千赫的周期计数。

uint8_t network_number; ///< 表示网络密钥的网络号.

#if ANT_CONFIG_ENCRYPTED_CHANNELS > 0

ant_encrypt_channel_settings_t * p_crypto_settings; ///< 指向加密设置的指针,如果必须省略此配置,则为空。

#endif

} ant_channel_config_t;

主通道配置:

channel_number :0 //通道0

channel_type :0x10 ///< 主频道 (PARAMETER_TX_NOT_RX).

ext_assign :0x10 //通道快速启动模式。

rf_freq :57//频率,十进制 57 (2457 MHz).

transmission_type:5u //广播通道

device_type :0x23 //设备类型:车灯==35(广播通道类型)

device_number :NRF_FICR->DEVICEADDR[0]; //将ANT设备号设置为MAC地址

channel_period:4084///< 消息周期,十进制 4035 (8.12 Hz)

network_number:0

共享通道配置:

channel_number :1 //通道1

这里的通道类型需要根据实际控制:

当索引号为0时:

channel_type :0x10 ///< 主频道 (PARAMETER_TX_NOT_RX).

当索引号为>0时:

channel_type :0x00 ///< 从属信道 (PARAMETER_RX_NOT_TX).

ext_assign :0x10 //通道快速启动模式。

rf_freq :57//频率,十进制 57 (2457 MHz).

transmission_type:6u //共享通道

device_type :0x24 ///< 设备类型:车灯==36(共享通道类型)

device_number :m_ant_BikeLight.page_33.DeviceNumber_MSB << 8 | m_ant_BikeLight.page_33.DeviceNumber_LSB;//设备号有P33连接命令决定。

channel_period:4084///< 消息周期,十进制 4035 (8.12 Hz).

network_number:0

**

3. 数据轮询

**

由于前面设置了8HZ(125ms)的消息周期,所以20*9=180ms。这样消息冲撞概率会小。

/*********************************************

函数名:ant_message_send

功 能:用于设置ANT消息的有效负载并发送它的函数。(广播通道)

形 参:p_profile--指向配置文件实例的指针。

返回值:

备 注:

作 者:薛建强

时 间:2020/02/27

使 用:

**********************************************/

void ant_message_send(ant_BikeLight_profile_t *p_profile)

{

uint32_t err_code;

if (ANT_PAGE_NEW < 127) //广播通道的内容

{

sens_message_encode(p_profile, ANT_message_payload);//对广播命令进行编码

err_code = sd_ant_broadcast_message_tx(p_profile->channel_number, 8, ANT_message_payload);//发送广播命令

// if (ANT_message_payload[0] == 18)

// {

SEGGER_RTT_printf(0, "channel0---TX page_%02d: %02X %02X %02X %02X %02X %02X %02X %02X --err_code:%dnr",

ANT_message_payload[0], Replace_Buff(ANT_message_payload), err_code

);//打印发送共享命令

// }

}

else//共享通道的内容

{

if (ANT_PAGE_NEW == 127 + 1)

{

err_code = sd_ant_broadcast_message_tx(p_profile->channel_number, 8, ANT_message_payload_Wait_2);//共享通道的内容转发广播通道

SEGGER_RTT_printf(0, "[channel3---TX page_%02d: %02X %02X %02X %02X %02X %02X %02X %02X --err:%d]nr",

ANT_PAGE_NEW - 127, Replace_Buff(ANT_message_payload_Wait_2), err_code

);//打印发送共享命令

}

else if (ANT_PAGE_NEW == 127 + 2)

{

err_code = sd_ant_broadcast_message_tx(p_profile->channel_number, 8, ANT_message_payload_Wait_3);//共享通道的内容转发广播通道

SEGGER_RTT_printf(0, "[channel3---TX page_%02d: %02X %02X %02X %02X %02X %02X %02X %02X --err:%d]nr",

ANT_PAGE_NEW - 127, Replace_Buff(ANT_message_payload_Wait_3), err_code

);//打印发送共享命令

}

else if (ANT_PAGE_NEW == 127 + 3)

{

err_code = sd_ant_broadcast_message_tx(p_profile->channel_number, 8, ANT_message_payload_Wait_4);//共享通道的内容转发广播通道

SEGGER_RTT_printf(0, "[channel3---TX page_%02d: %02X %02X %02X %02X %02X %02X %02X %02X --err:%d]nr",

百检网秉承“客户至上,服务为先,精诚合作,以人为本”的经营理念,始终站在用户的角度解决问题,为客户提供“一站购物式”的新奇检测体验,打开网站,像挑选商品一样简单,方便。打破行业信息壁垒,建构消费和检测机构之间高效的沟通平台