tinyos / nesc

Master nesc repository
GNU General Public License v2.0
100 stars 53 forks source link

Issue with event sendDone #50

Closed antonio13x closed 6 years ago

antonio13x commented 6 years ago

I have a problem with this code that describe a node sensor in a telos b.

Code

 #include <Timer.h>
 #include "printf.h"
 #include "Lumino.h"

 module LuminoC {
    uses {
        interface Boot;   
        interface Timer<TMilli> as Timer;
        interface Read<uint16_t>;
        interface Leds;
        interface SplitControl as RadioControl;
        interface StdControl as CollectionControl;
        interface Send as AlertRoot;
    }
 }

 implementation {
    #define SAMPLING_FREQUENCY 1000  
    uint16_t lum=0;
    uint16_t soglia=200;
    message_t alertMsg;
    void theft() {
        alert_t *payload = call AlertRoot.getPayload(&alertMsg, sizeof(alert_t));
        if (payload != NULL) {
            payload -> stolenId = TOS_NODE_ID;

*if(call AlertRoot.send(&alertMsg, sizeof payload)) { call Leds.led1On(); }

        }
    }

*event void AlertRoot.sendDone(message_t msg, error_t ok) { call Leds.led0On(); }

event void Boot.booted() {    
        call Timer.startPeriodic(SAMPLING_FREQUENCY);
        call RadioControl.start();
    }
    event void RadioControl.startDone(error_t ok){
        if (ok == SUCCESS) {        
            call CollectionControl.start();
        }
    }
    event void RadioControl.stopDone(error_t ok) {}
    event void Timer.fired() {    
        call Read.read();
    }
    event void Read.readDone(error_t result, uint16_t data) {       
        if (result == SUCCESS ) {   
            lum=data;
            if(lum<soglia){
                    call Leds.led0Off();
                call Leds.led1Off();            
            }           
            else{ 
                theft();
            }       
        }
    }   
 } 

In particulary the led1, switch on, but the led0, inside the event sendDone, no. I try to use if( ok == SUCCESS/FAIL/ECANCEL/ERETRY/TOSSIM) before the call led0, but it does not work. How can I sove it?

cire831 commented 6 years ago

first, technically not an issue for github. Also not a nesc issue. This would be more appropriate for tinyos-help@millennium.berkeley.edu mailing list.

you need to figure out why AlertRoot.sendDone isn't being signalled. The fact that led1 is turned on after AlertRoot.send is called implies that the send didn't work.

please spend some time learning how the basic interfaces work. In particular, if you looked at how AlertRoot.send() works you would see that a return of 0 (SUCCESS) won't turn on Led1. Led1 being on indicates that the send didn't work.

If the .send didn't work there is no way the event will get signalled. And no way for Led0 to get turned on.

before asking questions, please first learn the basics.

antonio13x commented 6 years ago

Thank you so much for the aswer. In the folder build i threw

enum __nesc_unnamed4248 {
SUCCESS = 0,
FAIL = 1,
ESIZE = 2,
ECANCEL = 3,
EOFF = 4,
EBUSY = 5,
EINVAL = 6,
ERETRY = 7,
ERESERVE = 8,
EALREADY = 9,
ENOMEN = 10,
ENOACK = 11,
ELAST = 11
};

but now I try to use

if(call AlertRoot.send(&alertMsg, sizeof payload) == SUCCESS) { call Leds.led1On(); }

And it works...contrary if I use

if(call AlertRoot.send(&alertMsg, sizeof payload) == FAIL) { call Leds.led1On(); }

it does not work, so i don't understand where is the problem...

cire831 commented 6 years ago

please take this off github. use the email address I referred to earlier.

repost this on tinyos-help and I will respond there.

On Tue, Oct 9, 2018 at 1:12 AM antonio13x notifications@github.com wrote:

Thank you so much for the aswer. In the folder build i threw

enum __nesc_unnamed4248 { SUCCESS = 0, FAIL = 1, ESIZE = 2, ECANCEL = 3, EOFF = 4, EBUSY = 5, EINVAL = 6, ERETRY = 7, ERESERVE = 8, EALREADY = 9, ENOMEN = 10, ENOACK = 11, ELAST = 11 };

but now I try to use

if(call AlertRoot.send(&alertMsg, sizeof payload) == SUCCESS) { call Leds.led1On(); }

And it works...contrary if I use

if(call AlertRoot.send(&alertMsg, sizeof payload) == FAIL) { call Leds.led1On(); }

it does not work, so i don't understand where is the problem...

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/tinyos/nesc/issues/50#issuecomment-428101404, or mute the thread https://github.com/notifications/unsubscribe-auth/AAY46ZZpJl2ubK7ns97NZmUmOLAjZwvHks5ujFqHgaJpZM4XMrsk .

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