记录开发过程中的问题和功能。毕se代做,小家电开发。 收徒带做企业级项目,帮助毕业生和转行人员顺利找到工作。

LiSun

记录开发过程中的问题和功能。毕se代做,小家电开发。 收徒带做企业级项目,帮助毕业生和转行人员顺利找到工作。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

数据页面33是从ANT+控制器发送到ANT+自行车灯的命令页面,以启动与新ANT+自行车灯的连接。该命令包括在连接状态下应使用的灯光索引和设置,以及要搜索的通道ID变量(即设备编号和传输类型)(如果适用)。该命令应作为确认消息从ANT+控制器发送。
该消息中的所有字段均应按表7-34中所述进行设置。
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

/*********************************************
函数名:ant_BikeLight_SHARED_MASTER_Init
功  能:共享通道初始化
形  参:ch--> 0--主灯共享通道(可发可接)  1--副灯共享通道(只接)
返回值:
备  注:
作  者:薛建强
时  间:2020/02/27
使  用:
**********************************************/
void ant_BikeLight_SHARED_MASTER_Init(void)
{
    uint32_t err_code = 0;
    /*共享通道*/
    if (SystemInit_Type.ANT_SHARED_MASTER == 0)
    {
        err_code = sd_ant_channel_unassign(BikeLight_Shared_CHANNEL_NUMBER);
        SEGGER_RTT_printf(0, "ANT BikeLight Shared channel_unassign %u close %d\n\r", 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!!! %d\r\n", m_ant_BikeLight.page_33.Light_Index_Set);
            return;
        }
//        m_ant_BikeLight_Shared.channel_number = BikeLight_Shared_CHANNEL_NUMBER; //通道号

        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:%d\r\n", err_code, ant_channel_Shared.device_number, ant_channel_Shared.transmission_type);
        APP_ERROR_CHECK(err_code);
    }
}

7.17.1 设置灯光索引
“灯光索引设置”字段应按以下方式解释为未连接的灯光(即当前灯光索引为0的灯光):
ANT+自行车灯应将其灯光索引设置为灯光索引设置字段中指定的值。

• 如果“灯光索引”设置为1,则ANT+自行车灯光被指定为网络的主灯光,并应按照第6.5节中的详细说明打开共享主频道。
• 或者,如果灯光索引设置为2 – 63,则ANT+自行车灯被分配为辅助灯,并且应打开共享的从属通道,如第6.4节中所述。

注意,ANT+控制器应按顺序分配灯光索引,从第一个辅助灯光的灯光索引设置为2开始。对于共享网络中的任何辅助灯光,灯光索引设置字段不得大于发送到主灯光的连接命令中的“辅助灯光”字段的一个以上。

仅当控制未连接的灯光时,才应使用灯光索引255(0xFF),例如设置灯光类型或灯光状态设置,而不更改灯光索引或影响灯光打开的频道。

光线指标设置字段应通过连接的光线(即当前光线指标> 0的光源)进行如下解释:
• ANT+自行车灯不得更改其灯光指数。
• 如果灯光索引设置为1,则连接命令仅适用于主灯光。
• 如果光指数设置为2 – 63,则连接命令将应用于具有指定光指数的辅助光。如果主灯接收到此命令,则应将其转发到指定的辅助灯。
请注意,连接的灯光应忽略灯光索引为255(0xFF)的连接命令。.

7.17.2 # 副灯
此字段指示将连接到共享通道的辅助灯光的数量,以便主灯光知道要轮询的灯光索引。例如,如果辅助灯光的数量为5,则主灯光应轮询灯光索引2-6。

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

7.17.4 子灯索引
子灯光索引字段指示应应用灯光状态和灯光类型设置的子灯光。如果子灯光索引设置为0,则命令的灯光设置应仅应用于主要的ANT+自行车灯光,而不是任何子灯光。
此字段不应设置为值5、6或7。
7.17.5 灯光状态设置
ANT+控制器可以使用灯光状态设置字段来命令ANT+自行车灯关闭,闪烁或打开光束(稳定)。ANT+自行车灯应立即响应命令.
在这里插入图片描述

请注意,灯状态设置字段为ANT+控制器提供了对ANT+自行车灯状态的有限控制。可以在网络配置期间使用此功能,从而实现ANT+自行车灯的基本控制,而无需ANT+控制器从自行车灯获取全模式信息。
接收到“闪烁”命令的ANT+自行车灯应将其自身设置为灯光闪烁的任何模式。
接收到“常亮”命令的ANT+自行车灯应将自身设置为具有常亮灯光亮度的任何模式。

7.17.6 灯光类型设置
ANT+控制器应使用此字段根据需要配置ANT+自行车灯。ANT+控制器不应尝试将ANT+自行车灯的灯光类型设置为不受支持的类型。ANT+自行车灯应根据要求配置其灯类型。ANT+自行车灯应忽略将其灯类型设置为不支持的任何请求。.

7.17.7 设备编号和传输类型字段
设备编号和传输类型字段包含主灯的通道ID参数。只要将灯光指标设置为2到63之间的值,这些值就应作为有效值包括在内。ANT+自行车灯应使用表7-37和表7-38指定的参数。
请注意,当灯光索引设置为0时,设备号和传输类型字段应设置为无效。
在这里插入图片描述

/* 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_33.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 连接命令(0x21) 第33页数据布局结构. */
typedef struct
{
    uint8_t Light_Index_Set;                 //灯光索引设置 [1-63]
    uint8_t Secondary_Lights;                //辅助灯       [1-62] 无效:255(0xFF)
    uint8_t Controller_ID;                   //控制器ID     [0-255]

    uint8_t SubLight_Index       : 3;        //子灯索引     [0-2]  5-7:保留,请勿使用
    uint8_t Light_State_Setting  : 2;        //灯光状态设置 [3-4] 0:无效  1:关灯  2:闪烁  3:常亮
    uint8_t Light_Type_Setting   : 3;        //灯光类型设置 [5-7] 0:前灯 2:尾灯 3:信号灯  4:信号灯-左  5:信号灯-右

    uint8_t DeviceNumber_LSB;                //主灯的设备号LSB
    uint8_t DeviceNumber_MSB;                //主灯的设备号MSB
    uint8_t Transmission_Type;               //主灯的传送类型 [1-255]
} ant_BikeLight_page33_data_layout_t;


static void page33_data_log(ant_BikeLight_page33_data_t const *p_page_data)
{
    SEGGER_RTT_printf(0, "page33:Light_Index_Set:             %d\r\n", (uint8_t)p_page_data->Light_Index_Set);
}


void ant_BikeLight_page_33_encode(uint8_t                     *p_page_buffer,
                                  ant_BikeLight_page33_data_t const *p_page_data)
{
//    ant_BikeLight_page33_data_layout_t *p_outcoming_data = (ant_BikeLight_page33_data_layout_t *)p_page_buffer;

//    p_outcoming_data->Light_Index_Set        = p_page_data->Light_Index_Set;
//    p_outcoming_data->Secondary_Lights       = p_page_data->Secondary_Lights;
//    p_outcoming_data->Controller_ID          = p_page_data->Controller_ID;
//    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->DeviceNumber_LSB       = p_page_data->DeviceNumber_LSB;
//    p_outcoming_data->DeviceNumber_MSB       = p_page_data->DeviceNumber_MSB;
//    p_outcoming_data->Transmission_Type      = p_page_data->Transmission_Type;
    ANT_PAGE_NEW = 100; //从零开始--》(++ANT_PAGE_NEW>81 ==> ANT_PAGE_NEW=0)

    page33_data_log(p_page_data);
}


void ant_BikeLight_page_33_decode(uint8_t const              *p_page_buffer,
                                  ant_BikeLight_page33_data_t *p_page_data,
                                  uint8_t const Channel)
{
    ant_BikeLight_page33_data_layout_t const *p_incoming_data = (ant_BikeLight_page33_data_layout_t *)p_page_buffer;
    if (Channel == 0)
    {
        if ((m_ant_BikeLight.page_1.Light_Index == 0 || p_incoming_data->Light_Index_Set == m_ant_BikeLight.page_1.Light_Index) && p_incoming_data->Light_Type_Setting == 0) //判断灯光索引且为前灯
        {
            memcpy(p_page_data, p_incoming_data, sizeof(uint8_t) * 7); //复制数组
            /*处理其他页*/
            if (p_incoming_data->Light_Index_Set != 0xFF)
            {
                m_ant_BikeLight.page_1.Light_Index           = p_incoming_data->Light_Index_Set;   //更改灯光索引
                m_ant_BikeLight.page_2.Light_Index           = p_incoming_data->Light_Index_Set;   //更改灯光索引
                m_ant_BikeLight.page_32.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
                m_ant_BikeLight.page_34.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
                m_ant_BikeLight.page_19.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
            }
            m_ant_BikeLight.page_1.Last_Sequence_Number  = p_incoming_data->Controller_ID;
            SystemReg.ANT_Networking_Number_Loop = 2;

            /*处理事件*/
            if (p_incoming_data->Light_State_Setting == 1)
            {
                /*关机机*/
                System_ONOFF(1);//0--开机  1--关机
            }
            else if (p_incoming_data->Light_State_Setting == 2)
            {
                /*开机*/
                System_ONOFF(0);//0--开机  1--关机
                SystemReg.Level = 3; //闪烁
            }
            else if (p_incoming_data->Light_State_Setting == 3)
            {
                /*开机*/
                System_ONOFF(0);//0--开机  1--关机
                SystemReg.Level = 0; //常亮
            }

            Light_State_ModeNum_Update();
            page33_data_log(p_page_data);
        }
    }
    else if (Channel == 1)
    {
        if (p_incoming_data->Light_Index_Set == m_ant_BikeLight.page_1.Light_Index && p_incoming_data->Light_Type_Setting == 0) //判断灯光索引且为前灯
        {
            memcpy(p_page_data, p_incoming_data, sizeof(uint8_t) * 7); //复制数组
            /*处理其他页*/
            m_ant_BikeLight.page_1.Light_Index           = p_incoming_data->Light_Index_Set;   //更改灯光索引
            m_ant_BikeLight.page_2.Light_Index           = p_incoming_data->Light_Index_Set;   //更改灯光索引
            m_ant_BikeLight.page_32.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
            m_ant_BikeLight.page_34.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
            m_ant_BikeLight.page_19.Light_Index          = p_incoming_data->Light_Index_Set;   //更改灯光索引
            m_ant_BikeLight.page_1.Last_Sequence_Number  = p_incoming_data->Controller_ID;
            SystemReg.ANT_Networking_Number_Loop = 2;

            /*处理事件*/

            /*开机*/
            System_ONOFF(0);//0--开机  1--关机
            Light_State_ModeNum_Update();
            page33_data_log(p_page_data);
        }
    }
    /*防止转播过程中,进入低功耗*/
    LowPower_Tmr = 0;
    System_shutdown_count = 0;
}



/* 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_33_H__
#define ANT_BIKELIGHT_PAGE_33_H__

#include <stdint.h>

typedef struct
{
    uint8_t Light_Index_Set;                 //灯光索引设置 [1-63]
    uint8_t Secondary_Lights;                //辅助灯       [1-62]  无效:255(0xFF)
    uint8_t Controller_ID;                   //灯光索引设置 [0-255]

    uint8_t SubLight_Index       : 3;        //子灯索引     [0-4]  5-7:保留,请勿使用
    uint8_t Light_State_Setting  : 2;        //灯光状态设置 [0-3] 0:无效  1:关灯  2:闪烁  3:常亮
    uint8_t Light_Type_Setting   : 3;        //灯光类型设置 [0-7] 0:前灯 2:尾灯 3:信号灯  4:信号灯-左  5:信号灯-右

    uint8_t DeviceNumber_LSB;                //主灯的设备号LSB
    uint8_t DeviceNumber_MSB;                //主灯的设备号MSB
    uint8_t Transmission_Type;               //主灯的传送类型 [1-255]
} ant_BikeLight_page33_data_t;


#define DEFAULT_ANT_BikeLight_PAGE33()            \
    (ant_BikeLight_page33_data_t)                 \
    {                                             \
        .Light_Index_Set                 = 0,     \
        .Secondary_Lights                = 1,     \
        .SubLight_Index                  = 0,     \
        .Light_State_Setting             = 3,     \
        .Light_Type_Setting              = 0,     \
        .DeviceNumber_LSB                = 0,     \
        .DeviceNumber_MSB                = 0,     \
        .Transmission_Type               = 0,     \
    }


void ant_BikeLight_page_33_encode(uint8_t                          *p_page_buffer,
                                  ant_BikeLight_page33_data_t const *p_page_data);


void ant_BikeLight_page_33_decode(uint8_t const              *p_page_buffer,
                                  ant_BikeLight_page33_data_t *p_page_data,
                                  uint8_t const Channel);

#endif // ANT_BIKELIGHT_PAGE_33_H__
/** @} */

posted on 2022-08-13 11:01  嵌入式单片机实验室  阅读(146)  评论(0)    收藏  举报
记录开发过程中的问题和功能。毕se代做,小家电开发。 收徒带做企业级项目,帮助毕业生和转行人员顺利找到工作。