I wonder if there should be more specific message types, that allow for
type-safeness through the C API.
I wrote an e-mail yesterday about issues with reading serialforwarder
data from the C API.
I started out with the Oscilloscope sample application, and
prettylistener.c. basically I added the following function to
prettylistener.c:
void oscilloscope_print(tmsg_t *msg) {
unsigned int version;
unsigned int interval;
unsigned int id;
unsigned int count;
version = oscilloscope_version_get(msg);
interval = oscilloscope_interval_get(msg);
id = oscilloscope_id_get(msg);
count = oscilloscope_count_get(msg);
printf("version: %u, interval: %u, id: %u, count: %u\n",
version, interval, id, count);
}
what I did, is that I called this function with the tmsg_t structure
that prettylistener works on:
tmsg_t *msg = new_tmsg(packet + 1, len - 1);
...
oscilloscope_print(msg);
this will result in corrupting data. I saw though that hexprint()
displays sensible data, though it works at some offset from the data
portion of message:
hexprint((uint8_t *)tmsg_data(msg) + spacket_data_offset(0),
tmsg_length(msg) - spacket_data_offset(0));
it seems that there's one tmsg_t structure encapsulated in another. when
creating a new tmsg_t structure using the above pattern, I get all the
readings correct:
tmsg_t *realMessage;
...
realMessage = new_tmsg((uint8_t *)tmsg_data(msg) +
spacket_data_offset(0),
tmsg_length(msg) - spacket_data_offset(0));
oscilloscope_print(realMessage);
my conclusion is that the tmsg_t is just too broad a type, and is
overused for any kind of 'message' around. in the above example, it is
used for the serial forwarder message (the container message), and the
message payload (the 'real' message) as well. and this is confusing.
I wonder if it would be better to have specificy types defined for these
different purposes. that way, API usage would be more straightforward,
as one would know right away what is contained in what type..
Akos
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help