API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
digimesh_receiver.c

This is an example about how to receive an API frame using the XBee Digimesh device.

/* @file main.c
* @author TST
* @version 0.1
* @date 14/06/2012
* @brief This is an example about how to receive a frame using the XBee Digimesh device.
*
* This example uses Digimesh protocol to receive a frame from other XBee.
*
* @note to run this application it's necessary to set the other XBee Digimesh with the same
* configuration parameters:
* - API: enable
* - kind of devices: end-router
* - channel: 0x0D
* - pan id: 0x3322
* - Mac retires: 3 (it's advisable).
* The rest value can be default values.
*
* @note to use the debug UART, user must set the next configuration in the serial communication program:
* - Baud rate: 19200
* - Word length: 8 bits
* - Parity: none
* - Stop bit: 1
* - Flow control: none
*
*
*/
/* Platform headers */
#include "tsmart.h"
/* @brief vXBeedm_receiver task
*
* This task configures the XBee Digimesh and wait for new API frame from other XBee.
*
* @param pvParameters
*/
void vXBeedm_receiver(void *pvParameters) {
/* Variables */
tsmart_xbee_dm_config_device_t xbee_dm_config_device;
/* Debug buffer */
uint8_t debug_buffer[50];
/* bytes received */
uint8_t bytes_rcv = 0;
/* Set default configuration */
TSMART_XBEE_DM_InitStruct(&xbee_dm_config_device);
/* Specific configuration for this application, not all parameter are
* interesting for this applications
*/
xbee_dm_config_device.api = TSMART_XBEE_DM_ENABLE;
xbee_dm_config_device.kind_dev = TSMART_XBEE_DM_ROUTER;
xbee_dm_config_device.channel = 0x0D;
xbee_dm_config_device.pan_id = 0x3322;
if (TSMART_XBEE_DM_Config(&tsmart_xbee_dm, &xbee_dm_config_device) != TSMART_PASS){
for(;;);
}
for(;;){
/* Reset buffer */
memset(data_received.data, 0x00, sizeof(data_received.data));
/* Wait for new API frame */
bytes_rcv = TSMART_XBEE_DM_ReceiveApiFrame(&tsmart_xbee_dm, &data_received, portMAX_DELAY);
if(bytes_rcv != 0 ){
/* Debug UART */
sprintf(debug_buffer, "from %x%x - %s", data_received.high_addr_source, data_received.low_addr_source, data_received.data);
TSMART_UART_Send(&tsmart_uart1, debug_buffer, strlen(debug_buffer), 1000/portTICK_RATE_MS);
}
}
}
/* @brief "Init()" function.
*
* This is the first thing that the user must do for using TSmarT.
* It initializes specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_xbee_dm_config_t xbee_dm_config;
tsmart_uart_config_t tsmart_uart_config;
static uint8_t uart_buf[50];
portBASE_TYPE xReturn;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: XBee Digimesh and UART.
* The baud rate and flow control for the XBee UART will be set. The priority
* for the reception task will be set to 14, avoiding lose packet.
*/
xbee_dm_config.baud_rate = 9600;
xbee_dm_config.priority = 14;
if (TSMART_XBEE_DM_Init(&tsmart_xbee_dm, &xbee_dm_config) != TSMART_PASS){
return TSMART_FAIL;
}
/* Exit XBee from sleep mode */
/* UART configuration. */
/* Baud rate */
tsmart_uart_config.baud_rate = 19200;
/* Flow control */
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
/* Parity bit */
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
/* Word length */
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
/* Stop bit */
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
/* Buffer size for our UART */
tsmart_uart_config.rx_buf_sz = 50;
/* Buffer for our UART */
tsmart_uart_config.rx_buf = uart_buf;
/* UART DMA */
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
/* UART time out */
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
/* UART initialization. UART 1 is selected */
TSMART_UART_Init(&tsmart_uart1, &tsmart_uart_config);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This examples will need one task:
*
* - XBeedm_receiver task: This task configures the device and wait for new
* message: Hello world!, this message will be showed
* using a debug UART.
*/
xReturn = xTaskCreate(vXBeedm_receiver, "XBeedm_receiver", 512, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}