Sean, I think if you move the condition for address after the "msg" declaration, you'll be fine. I don't think you need to use the preprocessor as Eric pointed out (I don't know the reason but it works, maybe Eric can explain better than me). check with the code below:

    event void Notify.notify(button_state_t val)
    {
        if(_radioBusy == FALSE)
        {           
            //Creating the packet
            MoteToMoteMsg_t* msg = call Packet.getPayload(& _packet , sizeof(MoteToMoteMsg_t));
           
            msg->NodeId = TOS_NODE_ID;
            msg->Data = "" !val;
           
            //Moved after msg declaration  <-------------
            if(_address == 2)
                _address = 3;
            else
                _address = 2;           
           
            //Sending the packet
            if(call AMSend.send(_address,& _packet ,  sizeof(MoteToMoteMsg_t)) == SUCCESS)
            {
                _radioBusy = TRUE;
            }
        }       
    }


On 24-3-2013 2:36 AM, Eric Decker wrote:

First fix your formatting.   The way you've presented your code is mostly unreadable.

So the first thing I did was to reformat the code and I got what is presented in Sean1.nc.txt.

It is very clear what is wrong.   You are declaring a new variable in the middle of a code block.   C doesn't like that.   That is also why when you remove the if (_radioBusy == FALSE) clause why things then work.


I've moved things around a little bit and made this as Sean2.nc.txt


This is basic C.



On Sat, Mar 23, 2013 at 3:00 PM, Sean Dekker <sean.dek...@gmx.com> wrote:
Hi all,
 
I want to create a packet and each time that the packet is being created I want to send it to a specific sensor board knowing the TOS_NODE_ID of the nodes.
 
I have 3 telosb boards. I assign node ids of 1,2 and 3 to them when uploading the program. But for giving the address (switching between 2 addresses in "AMSend.send()" method, the compiler gives some errors. Here is part of my code:
 
bool _radioBusy = FALSE;
message_t _packet;
uint16_t _address = 2;
 
event void Boot.booted()
{
call Notify.enable();
call AMControl.start();
}
 
event void Notify.notify(button_state_t val)
{
if(_radioBusy == FALSE)
{
if(_address == 2)
{
_address = 3;
}
else
{
_address = 2;
}
 
//Creating the packet
MoteToMoteMsg_t* msg = call Packet.getPayload(& _packet , sizeof(MoteToMoteMsg_t));
 
msg->NodeId = TOS_NODE_ID;
msg->Data = "" val; 
 
//Sending the packet
if(call AMSend.send(_address,& _packet ,  sizeof(MoteToMoteMsg_t)) == SUCCESS)
{
_radioBusy = TRUE;
}
}
}
 
And here is the error :
 
In file included from MoteToMoteAppC.nc:9:
In component `MoteToMoteC':
MoteToMoteC.nc: In function `Notify.notify':
MoteToMoteC.nc:56: syntax error before `*'
MoteToMoteC.nc:58: `msg' undeclared (first use in this function)
MoteToMoteC.nc:58: (Each undeclared identifier is reported only once
MoteToMoteC.nc:58: for each function it appears in.)
 
 
I found if I remove the if/else statement for checking for "_address" inside the Notify event, the progam compiles...but then I will only be able to send to node with ID of 2.
 
Can you please tell me how to solve this problem? I was following the guide here on youtube: http://youtu.be/CBhVPXpTz_Q
 
Thanks,
Sean.
 

_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help



--
Eric B. Decker
Senior (over 50 :-) Researcher



_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


--
Regards,
Saeid Yazdani
EE Tutorials

_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to