wirepas 2.1.0.0
Main Page

Wirepas click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Ilic
  • Date : Jun 2023.
  • Type : UART type

Software Support

We provide a library for the Wirepas Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for Wirepas Click driver.

Standard key functions :

Example key functions :

  • wirepas_send_command Wirepas send command function.
    err_t wirepas_send_command ( wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id, uint8_t payload_length, uint8_t *payload );
    err_t wirepas_send_command(wirepas_t *ctx, uint8_t primitive_id, uint8_t frame_id, uint8_t payload_length, uint8_t *payload)
    Wirepas send command function.
    uint8_t frame_id
    Definition: main.c:53
  • wirepas_write_csap_attribute Wirepas write CSAP attribute function.
    err_t wirepas_write_csap_attribute ( wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id, uint8_t attribute_len, uint8_t *attribute_val );
    err_t wirepas_write_csap_attribute(wirepas_t *ctx, uint8_t frame_id, uint16_t attribute_id, uint8_t attribute_len, uint8_t *attribute_val)
    Wirepas write CSAP attribute function.
  • wirepas_send_data Wirepas send data function.
    err_t wirepas_send_data ( wirepas_t *ctx, uint8_t frame_id, wirepas_sink_data sink_data, uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu );
    err_t wirepas_send_data(wirepas_t *ctx, uint8_t frame_id, wirepas_sink_data sink_data, uint8_t tx_op, uint8_t apdu_length, uint8_t *apdu)
    Wirepas send data function.
    Wirepas Click sink data object.
    Definition: wirepas.h:214

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.

void application_init ( void )
{
log_cfg_t log_cfg;
wirepas_cfg_t wirepas_cfg;
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 );
uint8_t tmp_data[ 1 ] = { 0x00 };
Delay_ms( 1000 );
wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
Delay_ms( 1000 );
wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
Delay_ms( 1000 );
log_printf( &logger, " Wirepas stack stop request: \n" );
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
log_printf( &logger, " Wirepas factory reset request: \n" );
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
Delay_ms( 1000 );
wirepas_poll_indication( &wirepas, frame_id, NULL, NULL );
Delay_ms( 1000 );
log_printf( &logger, " Set node address: \n" );
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
log_printf( &logger, " Set net address: \n" );
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
log_printf( &logger, " Set channel address: \n" );
uint8_t channel_net = CHANNEL_ADDRESS;
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
log_printf( &logger, " Set role: \n" );
uint8_t role;
{
}
else
{
}
wirepas_get_resp( &wirepas );
Delay_ms( 1000 );
log_printf( &logger, " Wirepas Stack start request: \n" );
tmp_data[ 0 ] = 0x01;
wirepas_get_resp( &wirepas );
uint8_t data_buf[ WIREPAS_RX_DRV_BUFFER_SIZE ] = { 0 };
{
Delay_ms( 1000 );
wirepas_poll_indication( &wirepas, frame_id, data_buf, NULL );
sink_1.pduid = 0x00;
#if defined MULTI_SINK_MODE
sink_2.pduid = 0x00;
#endif
}
else
{
uint8_t data_rd = 0;
while ( 0 == data_rd )
{
wirepas_poll_indication( &wirepas, frame_id, data_buf, &data_rd );
Delay_ms( 1000 );
}
}
Delay_ms( 100 );
log_info( &logger, " Application Task " );
}
#define WIREPAS_MSAP_STACK_START_REQUEST
Definition: wirepas.h:79
#define WIREPAS_CSAP_ATTRIBUTE_NETWORK_CHANNEL
Definition: wirepas.h:103
#define WIREPAS_FACTORY_RESET_CODE
Wirepas factory reset code.
Definition: wirepas.h:110
#define WIREPAS_SINK_NODE_MODE
Definition: wirepas.h:123
#define WIREPAS_RX_DRV_BUFFER_SIZE
Definition: wirepas.h:138
#define WIREPAS_ROUTER_NODE_MODE
Wirepas node role mode settings.
Definition: wirepas.h:122
#define WIREPAS_CSAP_FACTORY_RESET_REQUEST
Definition: wirepas.h:94
#define WIREPAS_MSAP_STACK_STOP_REQUEST
Definition: wirepas.h:81
#define WIREPAS_CSAP_ATTRIBUTE_NODE_ROLE
Definition: wirepas.h:104
#define WIREPAS_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: wirepas.h:156
err_t wirepas_set_node_address(wirepas_t *ctx, uint8_t frame_id, uint32_t address)
Wirepas set node address function.
err_t wirepas_poll_indication(wirepas_t *ctx, uint8_t frame_id, uint8_t *rx_data, uint8_t *data_rdy)
Wirepas poll indication function.
err_t wirepas_set_net_address(wirepas_t *ctx, uint8_t frame_id, uint32_t net_address)
Wirepas set net address function.
void application_init(void)
Definition: main.c:69
err_t wirepas_get_resp(wirepas_t *ctx)
Wirepas get response function.
Definition: main.c:247
#define SINK_1_NODE_ADDRESS
Definition: main.c:44
#define CHANNEL_ADDRESS
Definition: main.c:47
#define ROUTER_NODE_ADDRESS
Wirepas node addresses.
Definition: main.c:43
wirepas_sink_data sink_1
Definition: main.c:54
wirepas_sink_data sink_2
Definition: main.c:55
#define SINK_2_NODE_ADDRESS
Definition: main.c:45
#define NET_ADDRESS
Definition: main.c:46
#define NODE_ADDRESS
Definition: main.c:49
uint32_t destination_addr
Definition: wirepas.h:217
uint8_t source_endpoint
Definition: wirepas.h:216
uint16_t pduid
Definition: wirepas.h:215
uint8_t destination_endpoint
Definition: wirepas.h:218

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.

void application_task ( void )
{
{
log_printf( &logger, " Sending data to the first Sink node: \n" );
wirepas_send_data ( &wirepas, frame_id, sink_1, 0x01, strlen( TX_DATA ), TX_DATA );
wirepas_get_resp( &wirepas );
Delay_ms( 5000 );
#if defined MULTI_SINK_MODE
log_printf( &logger, " Sending data to the second Sink node: \n" );
wirepas_send_data ( &wirepas, frame_id, sink_2, 0x01, strlen( TX_DATA ), TX_DATA );
wirepas_get_resp( &wirepas );
Delay_ms( 5000 );
#endif
}
else
{
uint8_t data_buf[ WIREPAS_RX_DRV_BUFFER_SIZE ] = { 0 };
uint8_t data_rdy = 0;
err_t error = wirepas_poll_indication( &wirepas, frame_id, data_buf, &data_rdy );
if ( 1 == data_rdy )
{
log_printf( &logger, "%s \r\n", data_buf );
}
Delay_ms( 2000 );
}
}
void application_task(void)
Definition: main.c:204
#define TX_DATA
Definition: main.c:35

Note

For the best experience use two clicks in sink mode and one in router.

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Wirepas

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.