On Wed, 2006-07-05 at 14:53, Ben Kelley wrote:

> 
> I finally got it to work, I have no idea how.
> 
> I ended up going with
> 
> typedef struct MateRouteMsg {
>   uint16_t sourceaddr;
>   uint16_t originaddr;
>   int16_t seqno;
>   int16_t originseqno;
>   uint16_t hopcount;
>   uint8_t data[];
> } __attribute__ ((packed)) MateRouteMsg;
> 
> In $TOSDIR/lib/VM/types/mhop.h
> 
> I don't believe I changed anything else; however, just for the archives, it
> at least works. 

Right! Of course. My guess is that it will work fine without the packed
attribute.

There were two issues at play. The first was the size of the multihop
header. The one in lib/VM/types was from MintRoute and was too small. So
if you were using MultihopLQI, it would think that the Mate' data buffer
started somewhere in the MultihopLQI header, get confused, and tell you
that things weren't working right.

But if you loop at the MultihopLQI packet format, it's this:

typedef struct MultihopMsg {
  uint16_t sourceaddr;
  uint16_t originaddr;
  int16_t seqno;
  int16_t originseqno;
  uint16_t hopcount;
  uint8_t data[(TOSH_DATA_LENGTH - 10)];
} TOS_MHopMsg;

Note the major difference between your structure and this one: in yours,
you specify that data is an array of unknown size ([]), while
TOS_MHopMsg defines it as an array of size TOSH_DATA_LENGTH-10.

mig treats the two differently. With [], mig understands that the packet
will be variably sized and will accept payloads larger than or equal to
the minimum size. With [TOSH_DATA_LENGTH - 10], mig assumes the payload
is of a fixed size, and if it is shorter it says the packet is too
small.

Note that the original VM message buffer is this:

typedef struct MateRouteMsg {
  uint16_t sourceaddr;
  uint16_t originaddr;
  int16_t seqno;
  uint8_t hopcount;
  uint8_t data[];
} __attribute__ ((packed)) MateRouteMsg;

The Mate' implementation and java toolchain assume that you can send
variably sized packets. Basically, if your buffer has one item, it
doesn't send an entire buffer, just the one item. But if you use the
standard MultihopLQI format, mig thinks it is fixed size.

The trick of doing (TOSH_DATA_LENGTH - x) is old, before there were
interfaces that let you find out the payload length. It's also very
brittle, as it means you can't put MultihopLQI on top of another layer
that, say, adds other fields between the AM and multihop headers. All
network protocols in 2.x have stopped doing this for these reasons.

Phil

_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to