void
broadcast_an_integer(struct broadcast_conn *bc_conn, int x)
{
packetbuf_copyfrom(&x, sizeof(x));
broadcast_send(bc_conn);
}
The receiver can then access it like this:
static void
broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from)
{
if(packetbuf_datalen() >= sizeof(int)) {
printf("broadcast message received from %d.%d: %d\n",
from->u8[0], from->u8[1], *(int *)packetbuf_dataptr());
} else {
printf("invalid broadcast size: %d\n", packetbuf_datalen());
}
}
Nicolas
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Contiki-developers mailing list
Contiki-d...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/contiki-developers
struct datastruct *msg;
packetbuf_clear();
msg = (struct datastruct *) packetbuf_dataptr();
packetbuf_set_datalen(sizeof(msg));
msg->temp = sht11_temp();
besides what is the difference between rimebuf and packetbuf? They are the same functions and seem to be doing the same stuff.
I’m not sure what the problem could be, since you do not give a lot of details about the problem except for the code of your application. However, the statement packetbuf_set_datalen(sizeof(msg)); probably doesn’t result in what you want to happen. “msg” is a pointer to datastruct, so “sizeof(msg)” will give you the size of the pointer (which is generally 2 on 16-bit platforms) instead of the size of the data structure. In the example below it seems to look like this might still work since your data structure only contains one 16-bit value, so there’s probably other issues as well.
Did you try the method that I wrote about earlier in the thread, i.e.,
copying from and to a local variable rather than accessing the value
through a casted pointer to packetbuf_dataptr()? There is no guarantee
that the first byte pointed to by packetbuf_dataptr() is aligned.