I don't use MIG, but I think you are trying to defeat it's
only purpose by trying to have only one message type.

The underlying code on both sides of the TOS-Java fence allocates
message buffers of the maximum length, with a TOSH_DATA_SIZE payload
field. When receiving on the Java side some fairly low level code
that you don't usually see checks the number of bytes received
against the header length and whines about mismatches. But that
code doesn't know about specific AM types, so just matches buffer
and header lengths.

Perhaps MIG adds a second level check for valid length. Specifying
a zero length payload as in your GenericMsg would tell MIG not to
expect anything, and specifying a maximum length tells MIG to
always expect _everything_...

It looks to me like you are trying to reinvent the AM message
functions by having your own ID and length. The standard headers
already have those fields and the code knows how to handle them.
Can you just use that to get all your different messages instead?

The one issue I can think of is that MIG may not be able to deal
with variable length messages correctly. If that's what you're
up to, you may need to write your own message types, or hack
the MIG generated code to remove the length checks.

MS


Viktor Zsoldos wrote:
> Dear List,
> 
> In my application I have several types of messages, and to handle that, I 
> have one general struct:
> /typedef nx_struct GenericMsg {
>      nx_uint8_t msgID;
>      nx_uint8_t msgLen;
>      nx_uint8_t msgPayload[0];
> }GenericMsg;/
> Other messages are casted to the msgPayload variable, and sent over radio 
> with given length. Between motes, this works, when I send for example a 
> CounterMsg casted into msgPayload, motes can read all the values, leds are 
> shining. Now I want to receive this kind of message structure in Java, 
> using MIG.
> 
> Problem: with msgPayload[0], I receve only msgID and msgLen. After checking 
> the mig generated GenericMsg.java, I'm aware of the reason, the size of 
> message is hardcoded and every array indexes are set according to 
> DEFAULT_MESSAGE_SIZE.
> So I tried to set GenericMsg with msgPayload[TOSH_DATA_SIZE-2], and now I 
> have the error:
> /receive error for GenericMsg (AM type 1): invalid length message received 
> (too short)/
> 
> Again, checked the reason, net.tinyos.message.Receiver.java throws this, if 
> dataGet().length > msg.get_header_length();
> 
> Now I'm pretty much lost, and hoping that one of you already dealt with this 
> kind of problem, and can say me a few magic words about the solution.
> 
> Thanks for your assistance!
> Viktor
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to