Hello all,

I'm trying to send and receive a TOS_Msg using the telosB platform and I 
detect transmission, reception but unfortunatelly the reception data is 
different that one I transmit. I have created a componend known as TestC that 
is the responsible to send and receive tha frames, and a pseudoMAC layer that 
should decode the frame. I don't know where is the problem. Here is the code. 
Please any idea will be welcome,

Thanks in advance,

Manel

The code:

includes AM;

configuration TestC{
                            provides interface DataFrame;
                                provides interface StdControl;
                          }
implementation{
                           components TestM, RadioCRCPacket, LedsC, HPLUARTC;
                           
                           StdControl = TestM;
                           DataFrame = TestM;
                           TestM.SubControl -> RadioCRCPacket.Control;
                           TestM.Leds -> LedsC.Leds;
                           TestM.Send -> RadioCRCPacket.Send;
                           TestM.Receive -> RadioCRCPacket.Receive;
                           TestM.HPLUART ->HPLUARTC;
                          
}

includes AM;
includes IncludesFile;

module TestM{
           provides{
                                interface DataFrame;
                                interface StdControl;
                                }
       uses{
                                interface Leds;
                                interface StdControl as SubControl;
                                interface BareSendMsg as Send;
                                interface ReceiveMsg as Receive;
                                interface HPLUART;
                                }
}

implementation{

        TOS_MsgPtr buffer;              
        TOS_Msg dades;


        task void ReceiveTask(){
                uint8_t i;
                result_t success;
                
                atomic{
                for (i=0;i<sizeof(*buffer);i++){
                        if(call HPLUART.put(buffer->data[i]));
                }
                success = signal DataFrame.ReceiveData(buffer);
                }//close atomic
                if(success == SUCCESS)
                        call Leds.yellowToggle();
                else if(success == FAIL)
                        call Leds.redToggle();
        }                       
        
                           
        command result_t StdControl.init(){
                call Leds.init();
                if (call SubControl.init()== SUCCESS)
                        return SUCCESS;
        }
        command result_t StdControl.start(){
                call SubControl.start();
                return SUCCESS;
        }
        command result_t StdControl.stop(){
                call SubControl.stop();
                return SUCCESS;
        }
                                           

        command result_t DataFrame.SendData(TOS_Msg m){
                if(call Send.send(&m)==SUCCESS) 
                        return SUCCESS;   
                else return FAIL;       
        }
                                       
        event result_t Send.sendDone(TOS_MsgPtr msg, result_t success){
                //call Leds.redOff();
                if (success == SUCCESS)
                        call Leds.yellowToggle();
                                else if (success == FAIL)
                                        call Leds.greenOn(); 
                                return SUCCESS;
        }

        
        async event result_t HPLUART.get(uint8_t data){return SUCCESS;}
        async event result_t HPLUART.putDone(){ return SUCCESS;}
                                         
        event TOS_MsgPtr Receive.receive(TOS_MsgPtr m){
                TOS_MsgPtr tmp; 
                tmp = buffer;
                buffer = m;
                post ReceiveTask();

                return tmp;
        }
                                           
}//End of program       





includes includesFile;

configuration MacLayer{
}

implementation{
        components Main, MacLayerM, LedsC, TimerC, TestC, HPLUARTC;
        
        Main.StdControl -> MacLayerM.StdControl;
        Main.StdControl -> TestC.StdControl;
        Main.StdControl -> TimerC.StdControl;
        MacLayerM.Timer -> TimerC.Timer[unique("Timer")];
        MacLayerM.Leds -> LedsC;
        MacLayerM.DataFrame -> TestC.DataFrame;
        MacLayerM.HPLUART ->HPLUARTC;
}





includes IncludesFile;

module MacLayerM{
        provides{
                interface StdControl;
                }
        uses{
                interface Leds;
                interface DataFrame;
                interface Timer;
                interface HPLUART;
                }
        }
        
implementation{
        TOS_Msg dades;
        command result_t StdControl.init(){
                call Leds.init();
                return SUCCESS;
                }
        
        command result_t StdControl.start(){
                call HPLUART.init();
                call Timer.start(TIMER_REPEAT, 1000);
                return SUCCESS;
                }
        
        command result_t StdControl.stop(){
                call HPLUART.stop();
                call Timer.stop();
                return SUCCESS;
                }
        
        async event result_t HPLUART.get(uint8_t data){return SUCCESS;}
        async event result_t HPLUART.putDone(){ return SUCCESS;}
                
        event result_t Timer.fired(){
                uint8_t i=0;
                if (TOS_LOCAL_ADDRESS ==0){
                        BeaconFrame *BF = (BeaconFrame *)dades.data;
                        
                        uint16_t superFrameField = 0;
                        uint16_t gestor = 0;
                        uint16_t SuperframeOrder;
                        result_t success;
                        uint16_t coordinatorShortAddr;
                        BF->FrameControl = BEACONFRAMECONTROL;
                        BF->SequenceNumber = SEQUENCENUMBER;
                        BF->SrcPANId = 0x0000;//PCoD->PANId;
                        //BF->AddressingField =PCoD->coordinatorLongAddress;
                        gestor = (MASCARA1 + MASCARA2 + MASCARA3+ MASCARA4);
                        superFrameField = (BEACONORDER & gestor);
                        gestor = (MASCARA5 + MASCARA6 + MASCARA7 + MASCARA8);
                        SuperframeOrder = SUPERFRAMEORDER;
                        SuperframeOrder <<3;
                        SuperframeOrder &= gestor; 
                        superFrameField = SuperframeOrder + superFrameField;
                        /*
                        if (PCoD->BattLifeExt) 
                                superFrameField |= MASCARA13;
                        if (PCoD->PANCoordinator)
                                superFrameField |= MASCARA15;
                        */      
                        superFrameField |=MASCARA16;//permetrem l'associació 
sempre
                        BF->SuperFrameSpec = superFrameField;
                        //memcpy(dades.data, &(BF), sizeof(BF));
                        call DataFrame.SendData(dades);
                        /*for (i=0;i<sizeof(BF);i++){
                                if(call HPLUART.put(dades.data[i]));
                                }*/
                        }
                return SUCCESS;
                }
                
        event result_t DataFrame.ReceiveData(TOS_MsgPtr m){
                uint8_t i;
                BeaconFrameReceived *Beacon = (BeaconFrameReceived *)m->data;
                if(TOS_LOCAL_ADDRESS !=0){
                        for (i=0;i<sizeof(Beacon);i++){
                                if(call HPLUART.put(m->data[i]));
                                }
                        if (Beacon->FrameControl ==BEACONFRAMECONTROL)
                                return SUCCESS;
                        else return FAIL;
                }
                if (TOS_LOCAL_ADDRESS ==0)
                        return SUCCESS;
        }
}




-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/



_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to