Hi all
I was wondering if someone can help us regarding this code. What we need
to do is to program the base station to send three anchor packets after
the timer get fired (After 30 seconds). The base station should wait 30
sec and then sends three packets but what happens is the base station
sends packets to UART in the first 30 seconds without receiving any
packets from the network. Attached please have a look to the code:

module InitialBcastM
{
        provides
        {
                interface StdControl;
        }
        uses
        {
                interface Timer;
                interface TOS_MsgOutput;
        }
}

implementation
{
        AnchorXY AnchorPacket;
        int count;
        
        command result_t StdControl.init()
        {
                count = 0;
                AnchorPacket.X = GLOBAL_X;
                AnchorPacket.Y = GLOBAL_Y;
                AnchorPacket.hopCount = 1;
                atomic
                {
                        AnchorPacket.src = TOS_LOCAL_ADDRESS;
                }
                return SUCCESS;
        }
        
        command result_t StdControl.start()
        {
                return call Timer.start(TIMER_REPEAT,500);
        }
        
        command result_t StdControl.stop()
        {
                return call Timer.stop();
        }
        
        event result_t Timer.fired()
        {
                TOS_Msg msg;
                AnchorXY *ptr = (AnchorXY *)(msg.data);
                count++;
                if(count == 3)
                        call StdControl.stop();
                *ptr = AnchorPacket;
                call TOS_MsgOutput.output(TOS_BCAST_ADDR,
sizeof(AnchorXY), &msg);
        }
        
        event result_t TOS_MsgOutput.outputComplete(bool success)
        {
                return success;
        }
                
}

And then another part of the code which asks base station not to do
anything in the first 30 sec:


module DVHopStageIM
{
        provides
        {
                interface StdControl;
        }
        uses
        {
                interface StdControl as IBControl;
                interface StdControl as PRControl;
                interface StdControl as RPControl;
                interface StdControl as StageIIControl;
                interface Timer;
                interface Leds;
                interface TOS_MsgOutput;
        } 
}

implementation
{
        NodeInfo *ptr;
        TOS_Msg msg;
        AnchorXY *m;
        
        command result_t StdControl.init()
        {
                dbg(DBG_TEMP, "Stage I init()");
                atomic
                {
                        initialize(&headptr);
                }
                return rcombine4(call IBControl.init(), call
PRControl.init(), call RPControl.init(), call StageIIControl.init());
        }
        
        command result_t StdControl.start()
        {
                dbg(DBG_TEMP, "Stage I start()");
                return rcombine4(call IBControl.start(), call
PRControl.start(), call RPControl.start(), call
Timer.start(TIMER_ONE_SHOT,30000));
        }
        
        command result_t StdControl.stop()
        {
                dbg(DBG_TEMP, "StageI stop()");
                return rcombine4(call IBControl.stop(), call
PRControl.stop(), call RPControl.stop(), call StageIIControl.stop());
        }
        
        task void headToUART()
        {
                atomic
                {
                        ptr = headptr;
                }
                if(ptr)
                {
                        m = (AnchorXY*)(msg.data);
                        *m = ptr->packet;
                        call TOS_MsgOutput.output(TOS_UART_ADDR,
sizeof(AnchorXY), &msg);
                }
                
        }
        
        event result_t Timer.fired()
        {
                call Leds.greenToggle();
                
                post headToUART();
                dbg(DBG_TEMP, "This is the end of stage I");
                return call StageIIControl.start();;
        }
        
        event result_t TOS_MsgOutput.outputComplete(bool success)
        {
                if(success)
                        ptr = ptr->next;
                
                if(ptr)
                {
                        m = (AnchorXY*)(msg.data);
                        *m = ptr->packet;
                        call TOS_MsgOutput.output(TOS_UART_ADDR,
sizeof(AnchorXY), &msg);
                }
        }
}

Could someone please help us because this code is working fine with the
nodes of one of my friends who is using mica2 motes and I am using micaz
motes. We tried to figure out what is the problem but we were not
successful.
Thanks in advance

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to