实验四 节点与基站的通信

采用ActiveMessageC组件来实现发送和采用AMSenderC组件发送是不同的。一般地,实现发送信息有两种思路:

1)仅使用ActiveMessageC组件,利用该组件提供的AMSend接口和SplitControl接口

2)使用AMSenderC组件的AMSend接口,同时使用ActiveMessageC组件的SplitControl接口

SplitControl主要作用是开启无线电。

值得注意的是,两种方式中,AMSend的接口声明是不一样的。前者的AMSend是带有参数,如AMSend[am_id_t id],而后者AMSend是不带参数的。


【测试】

² 测试时,采用一个基站(程序采用/opt/tinyos-2.1.1/apps/BaseStation程序)和三个节点(烧录本程序,但发送数据不同)

上电运行后,在终端输入:

java net.tinyos.tools.Listen –commserial@/dev/ttyUSB0:telos

 

现象:按照一定先后顺序在终端显示接收到的数据:

00 FF FF 00 01 01 00 06 56

00 FF FF 00 01 01 00 06 12

00 FF FF 00 01 01 00 06 24

 

 

【测试程序】

/* by dickychen */


moduleRadioSenderC

 {

   uses interface Boot;

   uses interface SplitControl as RadioControl;

   uses interface Packet;

   uses interface AMSend as RadioSend[am_id_t id];

   uses interface Leds;

   uses interface  Timer asTimer0;

 }

 

 implementation

 {

     typedef nx_struct RealMsg

     {

          nx_uint8_t testmsg;

       }RealMsg;

         message_t MsgOnRadio; 

     event void Boot.booted()

     {

        call RadioControl.start( ) ;

     }

     event void RadioControl.startDone(error_t error )

     {

        if(error == SUCCESS)

           {

              call Timer0.startPeriodic(500);

           }

     }

     event void RadioControl.stopDone(error_t error){ }

     

     event void Timer0.fired()

     {

        RealMsg *btrpkt = (RealMsg *)(call Packet.getPayload(&MsgOnRadio,sizeof(RealMsg)));

        btrpkt -> testmsg = 0x56;

        callRadioSend.send[6](AM_BROADCAST_ADDR,&MsgOnRadio,sizeof(RealMsg));        

     }

         event void RadioSend.sendDone[am_id_t id](message_t *msg, error_terror)

         {

            if(error == SUCCESS)

                 call Leds.led0Toggle();

         }

 }

 


configuration RadioSenderAppC
{
}

implementation
{
    //components
       components RadioSenderC,MainC,LedsC;
        components ActiveMessageC as RadioC;
        components new TimerMilliC( ) as TimerC0;
        //wiring
        RadioSenderC .Boot -> MainC;
        RadioSenderC.RadioControl -> RadioC;
        RadioSenderC.Packet -> RadioC;
        RadioSenderC .RadioSend -> RadioC.AMSend;
        RadioSenderC.Leds -> LedsC;
        RadioSenderC.Timer0 -> TimerC0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值