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

LiSun

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

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

数据页32是从ANT+控制器发送到ANT+自行车灯的命令页,用于将其重置为未连接状态。此命令应作为来自ANT+控制器的确认消息发送。
所有ANT+自行车灯都应支持此页面。该消息中的所有字段均应按照表7-32中的说明进行设置。
在这里插入图片描述

7.16.1. 灯光索引
主灯应检查灯光索引,如果设置为0x01,则主灯应返回未连接状态。具体而言,应:
1、 关闭其共享主频道
2、 在数据页1中将其状态设置为“未连接”
3、 将其灯光索引设置为0
4、 停止传输数据第18页(主光通道ID)
如果灯索引设置为0x00,则主灯应在共享频道上将命令作为广播消息转发四次,然后返回到如上所述的未连接状态。

如果灯光索引设置为非0x00或0x01的值,则主灯光应将该命令作为已确认消息转发到共享通道。该命令最多应重试4次,直到收到EVENT_TX_SUCCESS。在这种情况下,主灯不得更改其自身的状态。

一旦命令在共享通道上转发,该命令将被一个或所有辅助灯接收,具体取决于灯索引值。如果灯光索引为零,则所有辅助灯光将接收该命令。如果主灯索引是任何其他值,则只有具有指定索引的主灯才会接收该命令。任何收到此命令的辅助ANT+自行车灯应:
1、关闭其共享从属通道
2、在数据页1中将其状态设置为“未连接”
3、将其灯光索引设置为0
4、停止传输数据第18页(主光通道ID)

7.16.2. 控制器ID
控制器ID字段应由ANT+控制器使用其序列号的LSB填充。没有序列号的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_32.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 断开命令(0x20) 第32页数据布局结构. 注意:该页由控制器发送至车灯。将车灯连接状态置为未连接 */
typedef struct
{
    uint8_t Light_Index;                             //灯光索引 0-63
    uint8_t Controller_ID;                           //控制器ID 保留以备将来使用。设置为0x00  范围:[0,255]
    uint8_t Reserved[5];                             //保留
} ant_BikeLight_page32_data_layout_t;


static void page32_data_log(ant_BikeLight_page32_data_t const *p_page_data)
{
//    SEGGER_RTT_printf(0, "Light_Index:             %d\r\n", (uint8_t)p_page_data->Light_Index);

}


void ant_BikeLight_page_32_encode(uint8_t                     *p_page_buffer,
                                  ant_BikeLight_page32_data_t const *p_page_data)
{

    ant_BikeLight_page32_data_layout_t *p_outcoming_data = (ant_BikeLight_page32_data_layout_t *)p_page_buffer;
    memset(p_page_buffer, 0, sizeof(ant_BikeLight_page32_data_layout_t));
    p_outcoming_data->Controller_ID                 = p_page_data->Controller_ID;

    page32_data_log(p_page_data);
    SEGGER_RTT_printf(0, "page_32 send:             %d\r\n", (uint8_t)p_page_data->Light_Index);
}


void ant_BikeLight_page_32_decode(uint8_t const              *p_page_buffer,
                                  ant_BikeLight_page32_data_t *p_page_data, uint8_t const Channel)
{
    ant_BikeLight_page32_data_layout_t const *p_incoming_data = (ant_BikeLight_page32_data_layout_t *)p_page_buffer;

    if (Channel == 0)
    {
        if (p_incoming_data->Light_Index == 0 || p_incoming_data->Light_Index == p_page_data->Light_Index)//判断灯光索引
        {
            /*处理事件*/
            m_ant_BikeLight.page_1.Last_Sequence_Number = p_incoming_data->Controller_ID;//填写最后一次命令
            /*如果是整体关机,则需要转发*/
            if (p_incoming_data->Light_Index == 0 && m_ant_BikeLight.page_1.Light_Index == 1) //作为主灯,接到全部断开命令,则需要转发到共享频道
            {
                /*如果灯索引设置为 0x00,则主灯应在共享频道上将命令作为广播消息转发四次*/
                memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page32_data_layout_t));//复制非自身内容至共享通道缓存区
                ANT_Relay_New_Share_Page = 32; //发送指定页
                ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
                SystemReg.Wait_Off_Own = 1;
            }
            else if (m_ant_BikeLight.page_1.Light_Index == 1) //仅仅关闭主灯自身
            {
                if (ANT_Relay_New_Share_Page == 32)
                {
                    /*如果灯索引设置为 0x00,则主灯应在共享频道上将命令作为广播消息转发四次*/
                    memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page32_data_layout_t));//复制非自身内容至共享通道缓存区
                    ANT_Relay_New_Share_Page = 32; //发送指定页
                    ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
                    ANT_message_payload_Shared_Wait[0] = 0;
                }
                else
                {
                    /*如果灯索引设置为 0x00,则主灯应在共享频道上将命令作为广播消息转发四次*/
                    memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page32_data_layout_t));//复制非自身内容至共享通道缓存区
                    ANT_Relay_New_Share_Page = 32; //发送指定页
                    ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
                }
            }
            else//非主灯
            {
                if ((SystemInit_Type.ANT_SHARED_CHANNEL != 0 || SystemReg.ANT_SHARED_CHANNEL != 0))
                {
                    ant_BikeLight_Shared_close(ant_channel_Shared.channel_number);//关闭共享通道
                    SystemInit_Type.ANT_SHARED_CHANNEL = 0;
                    SystemReg.ANT_SHARED_CHANNEL = 0;
                }
                Delete_BikeLight_Light_Index();
                SystemReg.ANT_Networking_Number = 2;
                /*关机*/
                System_ONOFF(1);//0--开机  1--关机
                Light_State_ModeNum_Update();
            }



//        page32_data_log(p_page_data);
        }
        else//不是自己的命令就发送到共享通道
        {
            if (m_ant_BikeLight.page_1.Light_Index != ANT_message_payload_Shared_Wait[0]) //作为主灯则转发到共享通道
            {
                memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page32_data_t));//复制非自身内容至共享通道缓存区
                ANT_Relay_New_Share_Page = 32; //发送指定页
                ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
            }

//        SEGGER_RTT_printf(0, "Forward [Page32] to shared channel.\r\n", (uint8_t)p_page_data->Light_Index);
        }
    }
    else if (Channel == 1)
    {
        if (p_incoming_data->Light_Index == 0 || p_incoming_data->Light_Index == p_page_data->Light_Index)//判断灯光索引
        {
            if (SystemInit_Type.ANT_SHARED_CHANNEL != 0 || SystemReg.ANT_SHARED_CHANNEL != 0)
            {
                ant_BikeLight_Shared_close(ant_channel_Shared.channel_number);//关闭共享通道
                SystemInit_Type.ANT_SHARED_CHANNEL = 0;
                SystemReg.ANT_SHARED_CHANNEL = 0;
            }
            Delete_BikeLight_Light_Index();
            SystemReg.ANT_Networking_Number = 2;
            /*关机*/
            System_ONOFF(1);//0--开机  1--关机
            Light_State_ModeNum_Update();
        }
        else
        {
            if (m_ant_BikeLight.page_1.Light_Index != 1)
            {
                memcpy(ANT_message_payload_Shared_Wait, p_incoming_data, sizeof(ant_BikeLight_page32_data_layout_t));//复制非自身内容至共享通道缓存区
                ANT_Relay_New_Share_Page = 32; //发送指定页
                ANT_Shared_Channel_sens_message_encode(ANT_message_payload_Shared_Wait, ANT_Relay_New_Share_Page);//对该命令进行重组
            }
        }
    }
}



/* 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_32_H__
#define ANT_BIKELIGHT_PAGE_32_H__

#include <stdint.h>

typedef struct
{
    uint8_t Light_Index;                             //灯光索引 0-63
    uint8_t Controller_ID;                           //控制器ID 保留以备将来使用。设置为0x00  范围:[0,255]
    uint8_t Reserved[5];                             //保留

} ant_BikeLight_page32_data_t;


#define DEFAULT_ANT_BikeLight_PAGE32()            \
    (ant_BikeLight_page32_data_t)                 \
    {                                             \
        .Light_Index                     = 0,     \
        .Controller_ID                   = 0,     \
    }


void ant_BikeLight_page_32_encode(uint8_t                          *p_page_buffer,
                                  ant_BikeLight_page32_data_t const *p_page_data);


void ant_BikeLight_page_32_decode(uint8_t const              *p_page_buffer,
                                  ant_BikeLight_page32_data_t *p_page_data,
                                  uint8_t const Channel);

#endif // ANT_BIKELIGHT_PAGE_32_H__
/** @} */

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