中级
20 分钟

使用WIRL-PRO2和STM32G071RB将Wirepas Mesh无线连接堆栈集成到您的应用中

Wirepas Click 立刻行动!

Wirepas Click with Nucleo 64 with STM32G071RB MCU

已发布 10月 08, 2024

点击板

Wirepas Click

开发板

Nucleo 64 with STM32G071RB MCU

编译器

NECTO Studio

微控制器单元

STM32G071RB

您的网关可以创建坚固的、自愈的和节能的网状网络,适用于智能照明、资产追踪等应用!

A

A

硬件概览

它是如何工作的?

Wirepas Click 基于 Würth Elektronik 的 WIRL-PRO2 Thetis-I,这是一款带有 Wirepas Mesh 协议的无线电模块。该模块旨在集成到基于 Wirepas 的路由网络中,用于设备或节点之间的无线通信。该模块在全球可用的免许可 2.4 GHz 频段内安全可靠地传输数据,具有认证和加密机制。WIRL-PRO2 Thetis-I 模块具有与 nano-SIM 卡相当的小尺寸(8 mm x 12 mm),包括板载 PCB 天线,使其非常适合小型设计。该模块工作在 2402 到 2480MHz 的频率范围内,数据速率高达 1Mbps。它基于 Nordic 

Semiconductor 的 32 位 ARM Cortex-M4 微控制器 nRF52840,配有 1MB 闪存和 256KB RAM。它具有印刷天线和智能天线配置(2 合 1 模块),允许高达 +6dBm 的发射功率和 -92dBm 的灵敏度。通过连接到板载 N.FL 连接器的外部天线,连接性能可以更好。由于其非常低的功耗,Wirepas Click 可以作为信标使用。为此,它配备了一个备用电池。此外,还有两个用户可配置的指示 LED,LED1 和 LED2(蓝色和绿色)。此外,Wirepas Click 还配备了一个未焊接的调试头,用于与 Wirepas 微控制器进行直接

通信。Wirepas Click 使用标准的 2 线 UART 接口与主 MCU 通信,支持 115200bps 的比特率。您可以通过 RST 引脚重置设备。DIN 引脚用于观察数据流,当处于低电平逻辑状态时,它是指向主 MCU 的数据指示。此 Click board™ 只能在 3.3V 逻辑电压水平下运行。使用具有不同逻辑电平的 MCU 之前,板必须进行适当的逻辑电压水平转换。此外,这款 Click board™ 配备了包含易于使用的功能和示例代码的库,可用于进一步开发。

Wirepas Click hardware overview image

功能概述

开发板

Nucleo-64 搭载 STM32G071RB MCU 提供了一种经济高效且灵活的平台,供开发者探索新想法并原型设计他们的项目。该板利用 STM32 微控制器的多功能性,使用户能够为他们的项目选择最佳的性能与功耗平衡。它配备了 LQFP64 封装的 STM32 微控制器,并包含了如用户 LED(同时作为 ARDUINO® 信号)、用户和复位按钮,以及 32.768kHz 晶体振荡器用于精确的计时操作等基本组件。Nucleo-64 板设计考虑到扩展性和灵活性,它特有的 ARDUINO® Uno

V3 扩展连接器和 ST morpho 扩展引脚头,提供了对 STM32 I/O 的完全访问,以实现全面的项目整合。电源供应选项灵活,支持 ST-LINK USB VBUS 或外部电源,确保在各种开发环境中的适应性。该板还配备了一个具有 USB 重枚举功能的板载 ST-LINK 调试器/编程器,简化了编程和调试过程。此外,该板设计旨在简化高级开发,它的外部 SMPS 为 Vcore 逻辑供电提供高效支持,支持 USB 设备全速或 USB SNK/UFP 全速,并内置加密功能,提升了项目的功效

和安全性。通过外部 SMPS 实验的专用连接器、 用于 ST-LINK 的 USB 连接器以及 MIPI® 调试连接器,提供了更多的硬件接口和实验可能性。开发者将通过 STM32Cube MCU Package 提供的全面免费软件库和示例得到广泛支持。这些,加上与多种集成开发环境(IDE)的兼容性,包括 IAR Embedded Workbench®、MDK-ARM 和 STM32CubeIDE,确保了流畅且高效的开发体验,使用户能够充分利用 Nucleo-64 板在他们的项目中的能力。

Nucleo 64 with STM32G071RB MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

128

硅供应商

STMicroelectronics

引脚数

64

RAM (字节)

36864

你完善了我!

配件

Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。

Click Shield for Nucleo-64 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PC12
RST
ID COMM
PB12
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Data Indication
PC14
INT
UART TX
PA2
TX
UART RX
PA3
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Wirepas Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-64 accessories 1 image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 64 with STM32G071RB MCU作为您的开发板开始。

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 Wirepas Click 驱动程序的 API。

关键功能:

  • wirepas_send_command - Wirepas 发送命令功能。

  • wirepas_write_csap_attribute - Wirepas 写入 CSAP 属性功能。

  • wirepas_send_data - Wirepas 发送数据功能。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Wirepas Click Example.
 *
 * # Description
 * This example demonstrates the use of Wirepas Click board by processing
 * the incoming data and displaying them on the USB UART in sink mode, and sending data to 
 * the sinks in router mode.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration, setting device mode, node,
 * net and channel addresses, and starting stack.
 *
 * ## Application Task
 * Router mode - Sending data to the sinks at the same network.
 * Sink mode - Reads and processes all incoming data and displays them on the USB UART.
 *
 * ## Additional Function
 * - err_t wirepas_wait_response ( wirepas_t *ctx, uint8_t primitive_id )
 * - err_t wirepas_parse_frame ( wirepas_t *ctx, uint8_t primitive_id )
 * - err_t wirepas_poll_indication ( wirepas_t *ctx )
 *
 * @note
 * For the best experience use two Clicks in sink mode and one in router.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "wirepas.h"

#define PROCESS_BUFFER_SIZE 300
#define TX_DATA             "Wirepas Click"

#define MULTI_SINK_MODE     // Comment out this macro to place device into single sink mode.

/**
* @brief Wirepas node addresses.
 * @details Specified setting for node addresses of Wirepas Click driver.
 */
#define ROUTER_NODE_ADDRESS         0x01
#define SINK_1_NODE_ADDRESS         0x02
#define SINK_2_NODE_ADDRESS         0x03
#define NET_ADDRESS                 0x01
#define CHANNEL_ADDRESS             0x01

#define NODE_ADDRESS                ROUTER_NODE_ADDRESS    /* Change the value of this macro to change 
                                                              node address, each node should have a unique address */

static wirepas_t wirepas;
static log_t logger;
uint8_t frame_id = 0;
uint8_t stack_auto_start = 1;
uint8_t pdu_capacity = 0x10;
wirepas_sink_data sink_1;
wirepas_sink_data sink_2;

/**
 * @brief Wirepas wait response function.
 * @details This function is used to get response from the device. 
 * @param[in] ctx : Click context object.
 * See #wirepas_t object definition for detailed explanation.
 * @param[in] primitive_id : Expected Primitive ID.
 * @return @li @c >=0 - Success,
 *         @li @c  <0 - Error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
err_t wirepas_wait_response ( wirepas_t *ctx, uint8_t primitive_id );

/**
 * @brief Wirepas parse frame function.
 * @details This function is used to parse frame response from the device. 
 * @param[in] ctx : Click context object.
 * See #wirepas_t object definition for detailed explanation.
 * @param[in] primitive_id : Expected Primitive ID.
 * @return @li @c >=0 - Success,
 *         @li @c  <0 - Error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
err_t wirepas_parse_frame ( wirepas_t *ctx, uint8_t primitive_id );

/**
 * @brief Wirepas send poll indication function function.
 * @details This function is used to send poll indication, 
 * and get response from the device. 
 * @param[in] ctx : Click context object.
 * See #wirepas_t object definition for detailed explanation.
 * @param[in] primitive_id : Expected Primitive ID.
 * @return @li @c >=0 - Success,
 *         @li @c  <0 - Error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
err_t wirepas_poll_indication ( wirepas_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    wirepas_cfg_t wirepas_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    wirepas_cfg_setup( &wirepas_cfg );
    WIREPAS_MAP_MIKROBUS( wirepas_cfg, MIKROBUS_1 );
    if ( UART_ERROR == wirepas_init( &wirepas, &wirepas_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    wirepas_default_cfg ( &wirepas );
   
    wirepas.tx_frame_id = 0;
    do
    {
        log_printf( &logger, " Wirepas stack stop request:" );
        wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_STOP_REQUEST, 0, NULL );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_MSAP_STACK_STOP_CONFIRM ) );
    Delay_ms ( 1000 );
    
    do
    {
        log_printf( &logger, " Wirepas factory reset request:" );
        wirepas_send_command( &wirepas, WIREPAS_CSAP_FACTORY_RESET_REQUEST,
                              strlen( WIREPAS_FACTORY_RESET_CODE ), WIREPAS_FACTORY_RESET_CODE );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_CSAP_FACTORY_RESET_CONFIRM ) );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    do
    {
        log_printf( &logger, " Set node address:" );
        wirepas_set_node_address( &wirepas, NODE_ADDRESS );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM ) );
    Delay_ms ( 1000 );
    
    do
    {
        log_printf( &logger, " Set net address:" );
        wirepas_set_net_address( &wirepas, NET_ADDRESS );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM ) );
    Delay_ms ( 1000 );
    
    uint8_t channel_net = CHANNEL_ADDRESS;
    do
    {
        log_printf( &logger, " Set channel address:" );
        wirepas_write_csap_attribute( &wirepas, WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL, 1, &channel_net );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM ) );
    Delay_ms ( 1000 );


    uint8_t role;
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )
    role = WIREPAS_ROUTER_NODE_MODE;
#else
    role = WIREPAS_SINK_NODE_MODE;
#endif
    do
    {
        log_printf( &logger, " Set role:" );
        wirepas_write_csap_attribute( &wirepas, WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE, 1, &role );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM ) );
    Delay_1sec( );
    
    do
    {
        log_printf( &logger, " Wirepas Stack start request:" ); 
        wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_START_REQUEST, 1, &stack_auto_start );
    }
    while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_MSAP_STACK_START_CONFIRM ) );
    Delay_1sec( );
        
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )

    sink_1.pduid = 0x00;
    sink_1.source_endpoint = 0x01;
    sink_1.destination_addr = SINK_1_NODE_ADDRESS;
    sink_1.destination_endpoint = 0x01;
    #if defined MULTI_SINK_MODE
        sink_2.pduid = 0x00;
        sink_2.source_endpoint = 0x01;
        sink_2.destination_addr = SINK_2_NODE_ADDRESS;
        sink_2.destination_endpoint = 0x01;
    #endif
#endif
    Delay_ms ( 100 );
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    wirepas_poll_indication ( &wirepas );
#if ( ROUTER_NODE_ADDRESS == NODE_ADDRESS )
    if ( wirepas_get_din_state ( &wirepas ) && ( pdu_capacity > 0 ) )
    {
        log_printf( &logger, " Sending data to the first Sink node: \n" );
        wirepas_send_data ( &wirepas,  sink_1, 0x01, strlen( TX_DATA ), TX_DATA );
        wirepas_wait_response ( &wirepas, WIREPAS_DSAP_DATA_TX_CONFIRM );
        Delay_ms ( 1000 );
        
        #if defined MULTI_SINK_MODE
            log_printf( &logger, " Sending data to the second Sink node: \n" );
            wirepas_send_data ( &wirepas,  sink_2, 0x01, strlen( TX_DATA ), TX_DATA );
            wirepas_wait_response ( &wirepas, WIREPAS_DSAP_DATA_TX_CONFIRM );
            Delay_ms ( 1000 );
        #endif
    }
#endif
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

err_t wirepas_wait_response ( wirepas_t *ctx, uint8_t primitive_id )
{
    for ( uint8_t cnt = 0; cnt < 5; cnt++ )
    {
        if ( WIREPAS_OK == wirepas_parse_frame ( ctx, primitive_id ) )
        {
            return WIREPAS_OK;
        }
    }
    return WIREPAS_ERROR;
}

err_t wirepas_parse_frame ( wirepas_t *ctx, uint8_t primitive_id )
{
    err_t error_flag = wirepas_read_frame ( ctx, &ctx->frame );
    if ( WIREPAS_OK == error_flag )
    {
        if ( ( primitive_id != ctx->frame.primitive_id ) && ( 0 != primitive_id ) )
        {
            error_flag |= WIREPAS_ERROR;
        }
        switch ( ctx->frame.primitive_id )
        {
            case WIREPAS_MSAP_STACK_STOP_CONFIRM:
            case WIREPAS_MSAP_STACK_START_CONFIRM:
            case WIREPAS_CSAP_FACTORY_RESET_CONFIRM:
            case WIREPAS_CSAP_ATTRIBUTE_WRITE_CONFIRM:
            {
                if ( 0 == ctx->frame.payload[ 0 ] )
                {
                    log_printf( &logger, " OK\r\n" );
                }
                else 
                {
                    log_printf( &logger, " ERROR[%u]\r\n", ( uint16_t ) ctx->frame.payload[ 0 ] );
                    error_flag |= WIREPAS_ERROR;
                }
                break;
            }
            case WIREPAS_DSAP_DATA_TX_CONFIRM:
            {
                pdu_capacity = ctx->frame.payload[ 3 ];
                if ( 0 == ctx->frame.payload[ 2 ] )
                {
                    log_printf( &logger, " TX request with PDU_ID[%u] is placed\r\n", 
                                ( ( ( uint16_t ) ctx->frame.payload[ 1 ] << 8 ) | ctx->frame.payload[ 0 ] ) );
                    sink_1.pduid += 1;
                    if ( sink_1.pduid >= 16 )
                    {
                        sink_1.pduid = 0;
                    }
                #if defined MULTI_SINK_MODE
                    sink_2.pduid += 1;
                    if ( sink_2.pduid >= 16 )
                    {
                        sink_2.pduid = 0;
                    }
                #endif
                }
                else 
                {
                    log_printf( &logger, " ERROR[%u] on TX request with PDU_ID[%u]\r\n", ( uint16_t ) ctx->frame.payload[ 2 ],
                                ( ( ( uint16_t ) ctx->frame.payload[ 1 ] << 8 ) | ctx->frame.payload[ 0 ] ) );
                    error_flag |= WIREPAS_ERROR;
                }
                break;
            }
            case WIREPAS_MSAP_INDICATION_POLL_CONFIRM:
            {
                if ( 1 == ctx->frame.payload[ 0 ] )
                {
                    log_printf( &logger, " There are pending indications\r\n" );
                }
                else
                {
                    log_printf( &logger, " No pending indications on poll request\r\n" );
                }
                break;
            }
            case WIREPAS_DSAP_DATA_TX_INDICATION:
            {
                wirepas_send_ack ( ctx, WIREPAS_DSAP_DATA_TX_RESPONSE, ctx->frame.frame_id, ctx->frame.payload[ 0 ] );
                log_printf( &logger, " TX data with PDU_ID[%u] is sent to dest address: %lu\r\n", 
                            ( ( ( uint16_t ) ctx->frame.payload[ 2 ] << 8 ) | ctx->frame.payload[ 1 ] ),
                            ( ( ( uint32_t ) ctx->frame.payload[ 7 ] << 24 ) | ( ( uint32_t ) ctx->frame.payload[ 6 ] << 16 ) |
                              ( ( uint16_t ) ctx->frame.payload[ 5 ] << 8 ) | ctx->frame.payload[ 4 ] ) );
                pdu_capacity++;
                break;
            }
            case WIREPAS_DSAP_DATA_RX_INDICATION:
            {
                wirepas_send_ack ( ctx, WIREPAS_DSAP_DATA_RX_RESPONSE, ctx->frame.frame_id, ctx->frame.payload[ 0 ] );
                log_printf( &logger, " RX data is received from src address: %lu\r\n", 
                            ( ( ( uint32_t ) ctx->frame.payload[ 4 ] << 24 ) | ( ( uint32_t ) ctx->frame.payload[ 3 ] << 16 ) |
                              ( ( uint16_t ) ctx->frame.payload[ 2 ] << 8 ) | ctx->frame.payload[ 1 ] ) );
                log_printf( &logger, " RX data: " );
                for ( uint8_t cnt = 0; cnt < ctx->frame.payload[ 16 ]; cnt++ )
                {
                    log_printf( &logger, "%c", ctx->frame.payload[ 17 + cnt ] );
                }
                log_printf( &logger, "\r\n---------------------------\r\n" );
                break;
            }
            case WIREPAS_MSAP_STACK_STATE_INDICATION:
            {
                wirepas_send_ack ( ctx, WIREPAS_MSAP_STACK_STATE_RESPONSE, ctx->frame.frame_id, ctx->frame.payload[ 0 ] );
                log_printf( &logger, " Stack state indication: 0x%.2X\r\n", ctx->frame.payload[ 1 ] );
                break;
            }
            case WIREPAS_MSAP_APP_CONFIG_DATA_RX_IND:
            {
                wirepas_send_ack ( ctx, WIREPAS_MSAP_APP_CONFIG_DATA_RX_RESP, ctx->frame.frame_id, ctx->frame.payload[ 0 ] );
                log_printf( &logger, " MSAP app config data rx indication\r\n" );
                break;
            }
            case WIREPAS_MSAP_SCAN_NBORS_INDICATION:
            {
                wirepas_send_ack ( ctx, WIREPAS_MSAP_SCAN_NBORS_RESPONSE, ctx->frame.frame_id, ctx->frame.payload[ 0 ] );
                if ( ctx->frame.payload[ 1 ] )
                {
                    log_printf( &logger, " Neighbors scan is done and ready\r\n" );
                }
                else
                {
                    log_printf( &logger, " Neighbors scan is NOT done and ready\r\n" );
                }
                break;
            }
            default:
            {
                log_printf( &logger, " Frame with unknown primitive ID [0x%.2X] is received\r\n", 
                            ( uint16_t ) ctx->frame.primitive_id );
                log_printf( &logger, " Frame ID: %u\r\n", ( uint16_t ) ctx->frame.primitive_id );
                log_printf( &logger, " Payload len: %u\r\n", ( uint16_t ) ctx->frame.payload_len );
                log_printf( &logger, " Payload: ", ( uint16_t ) ctx->frame.payload_len );
                for ( uint8_t cnt = 0; cnt < ctx->frame.payload_len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ctx->frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                error_flag |= WIREPAS_ERROR;
                break;
            }
        }
    }
    return error_flag;
}

err_t wirepas_poll_indication ( wirepas_t *ctx )
{
    err_t error_flag = WIREPAS_OK;
    uint32_t timeout_cnt = 0;
    while ( wirepas_get_din_state ( ctx ) )
    {
        if ( timeout_cnt++ > 2000 )
        {
            log_printf( &logger, " No pending indications on DIN pin\r\n" );
            break;
        }
        Delay_1ms ( );
    }
    timeout_cnt = 0;

    wirepas_send_command( ctx, WIREPAS_MSAP_INDICATION_POLL_REQUEST, 0, NULL );
    error_flag |= wirepas_wait_response ( ctx, WIREPAS_MSAP_INDICATION_POLL_CONFIRM );
    if ( WIREPAS_OK != error_flag )
    {
        return WIREPAS_ERROR;
    }
    while ( ( WIREPAS_OK == error_flag ) && ( ctx->frame.payload[ 0 ] == 0x01 ) )
    {
        error_flag |= wirepas_parse_frame ( ctx, 0 );
        if ( WIREPAS_OK == error_flag )
        {
            switch ( ctx->frame.primitive_id )
            {
                case WIREPAS_DSAP_DATA_TX_INDICATION:
                case WIREPAS_DSAP_DATA_RX_INDICATION:
                case WIREPAS_MSAP_STACK_STATE_INDICATION:
                case WIREPAS_MSAP_APP_CONFIG_DATA_RX_IND:
                case WIREPAS_MSAP_SCAN_NBORS_INDICATION:
                {
                    if ( ( ctx->frame.payload[ 0 ] == 0x00 ) )
                    {
                        while ( !wirepas_get_din_state ( ctx ) )
                        {
                            if ( timeout_cnt++ > 200 )
                            {
                                log_printf( &logger, " ERROR no IRQ clear\r\n" );
                                error_flag |= WIREPAS_ERROR;
                                break;
                            }
                            Delay_1ms ( );
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
        }
        else
        {
            log_printf( &logger, " ERROR on indication frame parse\r\n" );
        }
        if ( WIREPAS_OK != error_flag )
        {
            do
            {
                log_printf( &logger, " Wirepas stack stop request:" );
                wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_STOP_REQUEST, 0, NULL );
            }
            while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_MSAP_STACK_STOP_CONFIRM ) );
            Delay_1sec( );

            do
            {
                log_printf( &logger, " Wirepas Stack start request:" ); 
                wirepas_send_command( &wirepas, WIREPAS_MSAP_STACK_START_REQUEST, 1, &stack_auto_start );
            }
            while ( WIREPAS_OK != wirepas_wait_response ( &wirepas, WIREPAS_MSAP_STACK_START_CONFIRM ) );
            Delay_1sec( );
        }
    }
    return error_flag;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。