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

This is an example about how to send API frame using the XBee 802.15.4 device.

/* @file main.c
* @author TST
* @version 0.1
* @date 14/06/2012
* @brief This is an example about how to send a frame using the XBee 802.15.4 device.
*
* This example uses 802.15.4 protocol to send a frame to other XBee.
*
* @note to run this application it's necessary to known your destination address
* of the user XBee receiver, and set the other XBee 802.15.4 with the same
* configuration parameters:
* - API: enable
* - kind of devices: end-device
* - channel: 13
* - pan id: 0x3322
* - MY: 0xFFFF
* The rest value can be default values.
* @note Set your destination address using the specific defines below.
*
* @note If the user uses a X-CTU terminal to receive the API frame, the user must know
* the structure of API frame for transmission using 64-bits.
*
*/
/* Destination XBee address.
* This defines set the destination address, please set them
* with your destination XBee address.
*/
#define HIGH_DEST_ADDR 0x00000000
#define LOW_DEST_ADDR 0x00000000
/* Platform headers */
#include "tsmart.h"
/* @brief vXBee802_sender task
*
* This task configures the XBee 802.15.4 and send a message to another XBee.
*
*
* @param pvParameters
*/
void vXBee802_sender(void *pvParameters) {
/* Variables */
tsmart_xbee_802_config_device_t xbee_802_config_device;
/* Message to send */
uint8_t message[] = "Hello World!!\r\n";
/* Set default configuration */
TSMART_XBEE_802_InitStruct(&xbee_802_config_device);
/* Specific configuration for this application, not all parameter are
* interesting for this applications
*/
xbee_802_config_device.api = TSMART_XBEE_802_ENABLE;
xbee_802_config_device.kind_dev = TSMART_XBEE_802_END_DEVICE;
xbee_802_config_device.channel = 13;
xbee_802_config_device.pan_id = 0x3322;
/* This application runs set address of 64-bit */
xbee_802_config_device.my = 0xFFFF;
if (TSMART_XBEE_802_Config(&tsmart_xbee_802, &xbee_802_config_device) != TSMART_PASS){
for(;;);
}
/* Select kind of address to use */
/* Set your destination XBee 802.15.4 address */
data_to_send.high_addr_dest = HIGH_DEST_ADDR;/* Set your high address in hexadecimal mode */
data_to_send.low_addr_dest = LOW_DEST_ADDR; /* Set your low address in hexadecimal mode */
/* Id frame */
data_to_send.frame_id = 0x01;
/* Copy your message to buffer XBee 802.15.4 transmission */
memcpy(data_to_send.payload, &message, strlen(message));
data_to_send.payload_size = strlen(message);
for(;;){
/* Send API frame */
if (TSMART_XBEE_802_SendApiFrame(&tsmart_xbee_802, &data_to_send, 5000/portTICK_RATE_MS)!= TSMART_PASS){
for(;;);
}
/* Wait one second to send again */
vTaskDelay(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_802_config_t xbee_802_config;
portBASE_TYPE xReturn;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: XBee 802
* 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_802_config.baud_rate = 9600;
xbee_802_config.priority = 14;
if (TSMART_XBEE_802_Init(&tsmart_xbee_802, &xbee_802_config) != TSMART_PASS){
return TSMART_FAIL;
}
/* Exit XBee from sleep mode */
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This examples will need one task:
*
* - XBee802_sender task: This task configures the device and send a message: Hello world!.
*/
xReturn = xTaskCreate(vXBee802_sender, "XBee802_sender", 512, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}