0

I'm studying THIS tutorial for tinyos and I wanted to try it out. I try to create the packet but it gives me the following error. I don't know what's wrong. It is probably something simple but I can't figure out what it is.

#include "TestMsg.h"
    ...
        event void AMControl.startDone(error_t error) {
            if (error == SUCCESS) {
                call Leds.led0On();

                //create packet
                TestMsg_t* msg = call Packet.getPayload(&packet, sizeof(TestMsg_t));
                msg->NodeID = TOS_NODE_ID;
    //          
    //          //TODO in the meantime this can change
    //          button_state_t val = call Get.get();
    //          msg->Data = ( val == BUTTON_PRESSED ? 1 : 0 );
    //          
    //          //send packet
    //          if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(TestMsg_t)) == SUCCESS) {
    //              radioBusy = TRUE;
    //          }
            } else {
                call AMControl.start();
            }
        }
    ...

Here is TestMsg.h

#ifndef TEST_MSG_H
#define TEST_MSG_H

typedef nx_struct _TestMsg {
    nx_uint16_t NodeID;
    nx_uint8_t Data;
} TestMsg_t;

enum {
    AM_RADIO = 6
};

#endif /* TEST_MSG_H */

Here is the part where it is declared in the video

The error I get it this:

In file included from /home/advanticsys/ws/TestRadio/src/TestRadioAppC.nc:5:
In component `TestRadioC':
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc: In function `AMControl.startDone':
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:43: syntax error before `*'
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: `msg' undeclared (first use in this function)
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: (Each undeclared identifier is reported only once
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: for each function it appears in.)

Update

Something is wrong with structs and headers.

#include "Szar.h"
#include "BarType.h"

module SzarP {
    uses interface Boot;
    uses interface Leds;
}

implementation {

    event void Boot.booted() {
        // TODO Auto-generated method stub
        call Leds.led0On();

        Szar_t foo;
        Szar_t *szar = &foo;

        BarType_t barVar;
        barVar.data = 0;
        BarType_t *pBarVar = &barVar;
        pBarVar->data = 1;

    }
}

Here are the 2 header files.

#ifndef SZAR_H
#define SZAR_H

typedef nx_struct _Szar {
    nx_uint8_t szar1;
    nx_uint16_t szar2;
} Szar_t;

#endif /* SZAR_H */


#ifndef BAR_TYPE_H
#define BAR_TYPE_H

typedef struct _BarType {
    uint8_t id;
    uint32_t data;
} BarType_t;

#endif /* BAR_TYPE_H */

And the errors:

In file included from /home/advanticsys/ws/Szar/src/SzarAppC.nc:6:
In component `SzarP':
/home/advanticsys/ws/Szar/src/SzarP.nc: In function `Boot.booted':
/home/advanticsys/ws/Szar/src/SzarP.nc:15: syntax error before `foo'
/home/advanticsys/ws/Szar/src/SzarP.nc:19: `barVar' undeclared (first use in this function)
/home/advanticsys/ws/Szar/src/SzarP.nc:19: (Each undeclared identifier is reported only once
/home/advanticsys/ws/Szar/src/SzarP.nc:19: for each function it appears in.)
/home/advanticsys/ws/Szar/src/SzarP.nc:20: syntax error before `*'
/home/advanticsys/ws/Szar/src/SzarP.nc:21: `pBarVar' undeclared (first use in this function)
gyozo kudor
  • 6,284
  • 10
  • 53
  • 80
  • Is this C? What is `event` as in `event void AMControl.startDone(error_t error)`? – Fiddling Bits Mar 05 '14 at 14:34
  • How are you compiling this? – Floris Mar 05 '14 at 14:34
  • It is similar to C but with some extra syntax – gyozo kudor Mar 05 '14 at 14:35
  • Where is `nx_uint16_t` defined or `typedef`ed? That's probably one of your problems. – Fiddling Bits Mar 05 '14 at 14:35
  • nx_uint16_t belongs to the tinyos sdk I think – gyozo kudor Mar 05 '14 at 14:36
  • to compile this I have to install tinyos sdk in ubuntu and do a `make telosb` – gyozo kudor Mar 05 '14 at 14:38
  • Try changing your `struct` definition to something really simple like `typedef nx_struct _TestMsg { int x; } TestMsg_t;` and see whether the error goes away (many others will appear... but we're looking for this error to go away). If it does, the problem is almost certainly that you are missing a type header file. – Floris Mar 05 '14 at 14:40
  • i think nx_*** types are recognized correctly if I hover over them with eclipse it shows `uint16_t - unsigned int`, and I copied the typedef from the video tutorial, so it should be ok – gyozo kudor Mar 05 '14 at 14:45
  • It gives me another error if I try to use a type that does not begin with nx_***, `/home/advanticsys/ws/TestRadio/src/TestMsg.h:5: field `x' must be a network type` , so I think the header file is ok – gyozo kudor Mar 05 '14 at 14:47

1 Answers1

0

For some strange reason I have to declare EVERY variable outside the function, and then it works. Example:

bool radioBusy = FALSE;
message_t packet;
TestMsg_t *messageToSend;
button_state_t buttonState;

event void AMControl.startDone(error_t error) {
    if (error == SUCCESS) {
        call Leds.led0On();

        messageToSend = call Packet.getPayload(&packet, sizeof(TestMsg_t));
        messageToSend->NodeID = TOS_NODE_ID;

        //TODO in the meantime this can change
        buttonState = call Get.get();
        messageToSend->Data = ( buttonState == BUTTON_PRESSED ? 1 : 0 );

        //send packet
        if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(TestMsg_t)) == SUCCESS) {
            radioBusy = TRUE;
        }
    } else {
        call AMControl.start();
    }
}

It also works if I declare my variables at the beginning of the functions/events/commands without any code before them.

gyozo kudor
  • 6,284
  • 10
  • 53
  • 80