Home/Support/Support Forum/Struct envelope

Struct envelope

0 votes
Im running the DigiMesh chat between 2 programmable
XBee modules example. It is working well and It shows how to send packets to specific nodes and to handle
the received packages.

I went to the Help of CodeWarrior and I searched for the envelope that is massively used on the code.

Well, I found this explanation:

The "envelope" is used to gather all necessary information about a given frame on the network. Note that all members of the structure are in host byte order.

The low byte of the options field is a copy of the cluster flags for the cluster that received the data. Use #WPAN_ENVELOPE_CLUSTER_FLAGS to mask off the byte, and then compare to the various WPAN_CLUST_FLAG_* macros.

On a DigiMesh network, the 16-bit network address is always set to WPAN_NET_ADDR_UNDEFINED (0xFFFE).


Ok, I can understand what is the function of the envelope structure, but first, How can I use this to get my sensors data and send to another module?

Second, what is the why that this variable ( color=red]&xdev.wpan_dev[/color] ) to be create?





#include <xbee_config.h>
#include <types.h>
#include <debug.h>
#include <utils.h>
#include <xbee/byteorder.h>
#include <xbee/transparent_serial.h>
#include <xbee/atcmd.h>
#include <wpan/types.h>

#define MAX_LINE_LEN 100
char linebuf[MAX_LINE_LEN];

#ifdef ENABLE_XBEE_HANDLE_RX
int xbee_transparent_rx(const wpan_envelope_t FAR *envelope, void FAR *context)
{
char addrbuf[ADDR64_STRING_LENGTH];

addr64_format(addrbuf, &envelope->ieee_address);
sys_watchdog_reset();
printf("\n<%s> %s\n<input> ", addrbuf, envelope->payload);

return 0;
}
#endif

void main(void)
{
addr64 ieeeaddr;
wpan_envelope_t env;
char *plinebuf = linebuf, gotmac;

sys_hw_init();
sys_xbee_init();
sys_app_banner();

do {
printf("\nEnter the address to chat to (XX-XX-XX-XX-XX-XX-XX-XX)\n");
printf("<addr> ");

get_line(&plinebuf, MAX_LINE_LEN, 0);
gotmac = (char)addr64_parse(&ieeeaddr, linebuf);
} while (gotmac != 0);

wpan_envelope_create(&env, &xdev.wpan_dev, &ieeeaddr, WPAN_NET_ADDR_UNDEFINED);
env.payload = linebuf;

addr64_format(linebuf, (addr64 const *)&env.ieee_address);
printf("Talking to... %s\n", linebuf);
printf("\n<input> ");

for (;;) {
env.length = get_line(&plinebuf, MAX_LINE_LEN, O_NONBLOCK);
if (env.length) {
(void)xbee_transparent_serial(&env);
printf("<input> ");
}
sys_watchdog_reset();
sys_xbee_tick();
}
}
asked Feb 11, 2015 in XBee Programmable Development by tonofre New to the Community (6 points)

Please log in or register to answer this question.

...