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 <[email protected]> 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 = (uint8_t) 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
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>



-- 
Eric B. Decker
Senior (over 50 :-) Researcher
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 = (uint8_t) val; 

    //Sending the packet
    if(call AMSend.send(_address,& _packet ,  sizeof(MoteToMoteMsg_t)) == 
SUCCESS) {
      _radioBusy = TRUE;
    }
  }
}
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) {
  MoteToMoteMsg_t* msg;

  if (_radioBusy == FALSE) {
#ifdef notdef
    if (_address == 2) _address = 3;
    else _address = 2;
#endif

    _address = (_address == 2) ? 3 : 2;
 
    //Creating the packet
    // not really.   doesn't create anything.   Uses the static storage defined
    // above as _packet.
    msg = call Packet.getPayload(& _packet , sizeof(MoteToMoteMsg_t));
 
    msg->NodeId = TOS_NODE_ID;
    msg->Data = (uint8_t) val; 

    //Sending the packet
    if (call AMSend.send(_address,& _packet ,  sizeof(MoteToMoteMsg_t)) == 
SUCCESS)
      _radioBusy = TRUE;
  }
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to