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

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

/* @file main.c
* @author TST
* @version 0.1
* @date 18/06/2012
* @brief This is an example about how to send a frame using the XBee ZigBee device.
*
* This example uses ZigBee protocol to send a frame to other XBee(Coordinator).
* This application configures an End-device, for this reason be sure that user XBee
* has a proper API firmware: End-device API firmware.
* TSmarT can work only in API mode and this is defined by XBee firmware.
*
* @note to run this application it's necessary to known your destination address
* of the user XBee receiver, and set the other XBee ZigBee (it must be a coordinator
* ZigBee device using API firmware) with the same configuration parameters:
* - kind of device: Coordinator (by firmware configures this parameter)
* - pan id: 0x3322
* The rest value can be default values.
*
* @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.
*
*/
/* Platform headers */
#include "tsmart.h"
/* @brief vXBeezb_sender task
*
* This task configures the XBee ZigBee and send a message to another XBee.
*
*
* @param pvParameters
*/
void vXBeezb_sender(void *pvParameters) {
/* Variables */
tsmart_xbee_zb_config_device_t xbee_zb_config_device;
uint8_t i;
/* Message to send */
uint8_t message[] = "Hello World!!\r\n";
/* Set default configuration */
TSMART_XBEE_ZB_InitStructEndDevice(&xbee_zb_config_device);
/* Specific configuration for XBee ZigBee application */
xbee_zb_config_device.low_pan_id = 0x000003322;
xbee_zb_config_device.high_pan_id = 0x00000000;
if (TSMART_XBEE_ZB_Config(&tsmart_xbee_zb, &xbee_zb_config_device) != TSMART_PASS){
for(;;);
}
/* Wait to start */
for(;;){
status = TSMART_XBEE_ZB_ReadSatus(&tsmart_xbee_zb, 15000/portTICK_RATE_MS);
/* Now it's possible to communicate with the coordinator */
break;
}
}
/* Broadcast message */
/* Set radius */
data_to_send.broadcast_radius = 0x00;
/* Id frame */
data_to_send.frame_id = 0x01;
data_to_send.network_addr_16bit = 0xFFFE;
/* Set options */
data_to_send.opt = 0x00;
/* Set your destination XBee ZigBee address: coordinator address */
data_to_send.high_addr_dest = 0x00000000;
data_to_send.low_addr_dest = 0x00000000;
/* Copy your message to buffer XBee ZigBee transmission */
memcpy(data_to_send.payload, &message, strlen(message));
data_to_send.payload_size = strlen(message);
for(;;){
/* Send API frame */
tx_status = TSMART_XBEE_ZB_SendApiFrame(&tsmart_xbee_zb, &data_to_send, 3500/portTICK_RATE_MS);
if(tx_status.delivery_status != 0){
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_zb_config_t xbee_zb_config;
portBASE_TYPE xReturn;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* The specific hardware for this application: XBee ZigBee.
* 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_zb_config.baud_rate = 9600;
xbee_zb_config.priority = 14;
if (TSMART_XBEE_ZB_Init(&tsmart_xbee_zb, &xbee_zb_config) != TSMART_PASS){
return TSMART_FAIL;
}
/* Exit XBee from sleep mode */
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* This examples will need one task:
*
* - XBeezb_sender task: This task configures the device and send a message: Hello world!.
*/
xReturn = xTaskCreate(vXBeezb_sender, "XBeezb_sender", 512, NULL, 7, NULL);
if (xReturn != pdPASS) {
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}