You probably need to read the lessons a bit closer
and learn a little more C. Look at wikibooks for a
good C primer.

In this particular case, presuming that the receive()
is actually getting an XDataMsg, the commented code
is trying to get a pointer to the whole message but
going about it a bit wrongly. The function is getting
a pointer not a full structure... TOS_MsgPtr has a
hidden "*" in it... Try this instead:

event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr msg)
{
        XDataMsg *payload;
        uint16_t constant;

        payload = (XDataMsg*)(msg->data);
        constant = payload->constant;
}

Once you can understand what each of those lines means
(which is just basic C and pointers) it should not be
too hard to do the rest.

MS

Xavi Colomer wrote:
> Hi people!
> 
> I'm in a project to implement a network with some mica2 motes (one of 
> them as a base station).I need to send a constant from base to sensors, 
> but I can't take the data from the message I receive. I pick and modify 
> the default lesson3 code that comes on PN2 and I add the following code:
> 
> event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr msg){
> //atomic constant= msg->XDataMsg;
> return msg;
> }
> I have tried the commented text but doesn't work. The struct of the 
> message received is:
> 
> typedef struct XDataMsg{
>   uint8_t  board_id;
>   uint8_t  packet_id;
>   uint8_t  node_id;
>   uint8_t  rsvd;
>   uint16_t vref;
>   uint16_t constant;
> }__attribute__ ((packed)) XDataMsg;
> 
> Thanks in advance.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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