[Tinyos-devel] Proposed patch to TinyOS C SDK
Eric Decker
cire831 at gmail.com
Tue Jun 24 00:54:46 PDT 2008
Along those lines. Namely keeping the message structure structure opaque.
I was wondering if we could add something like the following:
/**
* move the tmsg data pointer to an arbitrary place with arbitrary length.
* Useful for moving over encapsulations.
**/
void reset_tmsg(tmsg_t *msg, void *packet, size_t len);
An example of its use is:
if (len < 1 + SPACKET_SIZE ||
packet[0] != SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID) {
fprintf(stderr, "*** non-AM packet (type %d, len %d (%0x)): ",
packet[0], len, len);
hexprint(packet, len);
continue;
}
msg = new_tmsg(packet + 1, len - 1);
if (!msg) {
fprintf(stderr, "*** new_tmsg failed (null)\n");
exit(2);
}
dest = spacket_header_dest_get(msg);
src = spacket_header_src_get(msg);
len = spacket_header_length_get(msg);
group= spacket_header_group_get(msg);
stype= spacket_header_type_get(msg);
if (debug) {
fprintf(stderr, "*** dest %04x, src %04x, len %02x, group %02x, type
%02x\n",
dest, src, len, group, stype);
}
***
reset_tmsg(msg, ((uint8_t *)tmsg_data(msg)) + SPACKET_SIZE,
tmsg_length(msg) - spacket_data_offset(0));
***
switch(stype) {
case MM3_DATA_MSG_AM_TYPE:
process_mm3_data(msg);
break;
default:
break;
}
free_tmsg(msg);
free((void *)packet);
Would it be possible to get this interface added to the message library?
eric
diff attached below:
Index: support/sdk/c/sf/message.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/c/sf/message.c,v
retrieving revision 1.1
diff -u -r1.1 message.c
--- support/sdk/c/sf/message.c 5 Dec 2007 22:49:46 -0000 1.1
+++ support/sdk/c/sf/message.c 24 Jun 2008 07:30:00 -0000
@@ -18,6 +18,14 @@
size_t len;
};
+void reset_tmsg(tmsg_t *msg, void *packet, size_t len)
+{
+ if (!msg)
+ return;
+ msg->data = packet;
+ msg->len = len;
+}
+
tmsg_t *new_tmsg(void *packet, size_t len)
{
tmsg_t *x = malloc(sizeof(tmsg_t));
Index: support/sdk/c/sf/message.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/c/sf/message.h,v
retrieving revision 1.1
diff -u -r1.1 message.h
--- support/sdk/c/sf/message.h 5 Dec 2007 22:49:46 -0000 1.1
+++ support/sdk/c/sf/message.h 24 Jun 2008 07:30:00 -0000
@@ -33,6 +33,11 @@
*/
void (*tmsg_set_fail(void (*fn)(void)))(void);
+/** reset the data pointer and length of the tmsg struct
+ * usefull when moving over encapsulations.
+ */
+void reset_tmsg(tmsg_t *msg, void *packet, size_t len) ;
+
/**
* Create a message buffer from array 'packet' of 'len' bytes
*/
On Tue, Jun 17, 2008 at 8:54 AM, David Gay <dgay42 at gmail.com> wrote:
> On Wed, May 28, 2008 at 4:57 AM, Dima Kogan <dkogan at cds.caltech.edu>
> wrote:
> > I found an error in message.[ch] in the TinyOS C SDK.
> >
> > Currently the definition of the tmsg structure is in message.c:
> >
> > struct tmsg {
> > uint8_t *data;
> > size_t len;
> > };
> >
> > It really should be in message.h instead, in order to make this
> > structure available to external programs that want to use messages. In
> > particular, mig-generated C code needs to do this. Objections?
>
> Yes - it was placed in message.c as it's supposed to be an abstract
> data type. The methods in message.h should be giving you all the
> access you need.
>
> David, answering slowly.
> _______________________________________________
> Tinyos-devel mailing list
> Tinyos-devel at millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-devel
>
--
Eric B. Decker
Senior (over 50 :-) Researcher
Autonomous Systems Lab
Jack Baskin School of Engineering
UCSC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-devel/attachments/20080624/cac5e6e5/attachment.htm
More information about the Tinyos-devel
mailing list