Struct envelope

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?


#define MAX_LINE_LEN 100
char linebuf[MAX_LINE_LEN];

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

addr64_format(addrbuf, &envelope->ieee_address);

<%s> %s
", addrbuf, envelope->payload);

return 0;


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


do {

Enter the address to chat to (XX-XX-XX-XX-XX-XX-XX-XX)
printf(” ");

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

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

addr64_format(linebuf, (addr64 const *)&amp;env.ieee_address);
printf("Talking to... %s

“, linebuf);

for (;;) {
	env.length = get_line(&amp;plinebuf, MAX_LINE_LEN, O_NONBLOCK);
	if (env.length) {
		printf(" ");