• 实验六 CC2530平台上P2P通信的TinyOS编程


    实验 CC2530平台上P2P通信的TinyOS编程

    实验目的:

    1. 加深和巩固学生对于TinyOS编程方法的理解和掌握
    2. 让学生初步的掌握射频通信TinyOS编程方法
    3. 学生通过本实验应理解TinyOSActiveMessage组件的设计思想及编程方法
    4. 高学生的上机和编程过程中处理具体问题的能力

    实验要求:

    1. 实验要求自己独立的完成
    2. 编写和调试过程中出现的问题记录,并事后总结到报告中
    3. 实验程序调试完成后, 用给定的平台进行测试,由老师检查测试结果,并给予相应的成绩
    4. 实验完成后,要上交实验报告

    实验内容:

    1. 开发一个新的应用,发送节点能够通过两个不同类型的消息分别控制接收节点中LED灯的开和关,并且用串口输出两个消息到串口调试助手。以下述顺序完成这个新应用的开发。
      1. 首先实现周期性发送消息控制另一个节点上的LED灯;
      2. 然后在上述基础上编程在串口调试助手上输出接收到的消息
      3. 增加按键功能,即能够通过节点上的按键控制另个节点的LED
    2. 在实验报告中分别给出上述两个阶段的源码

    实验代码:

    (1)配置文件TestP2PC.nc

    configuration TestP2PC {}

    #define AM_DATA_TYPE  123

    implementation

    {

    components MainC,LedsC;

    components  TestP2PM as App;

    components ActiveMessageC as AM; //消息组件

      components new TimerMilliC () as Timer0;

    App.Boot ->MainC;

    App.Leds ->LedsC;

    App.Timer0 ->Timer0;

    App.Packet -> AM.Packet;

       App.AMPacket -> AM.AMPacket;

       App.AMSend -> AM.AMSend[AM_DATA_TYPE];

    App.Receive -> AM.Receive[AM_DATA_TYPE];  

      App.AMControl -> AM.SplitControl;

    }

    (2)模块文件TestP2P.nc

    module  TestP2PM

    {

    uses interface Boot;

    uses interface Leds;

    uses interface Timer<TMilli> as Timer0;

    uses interface SplitControl as AMControl;

    uses interface AMPacket;

    uses interface AMSend;

    uses interface Receive;

    uses interface Packet;

    }

    implementation

    {

    #define destAddress 5

    typedef nx_struct P2PMsg {nx_uint16_t nodeid; nx_uint16_t counter;}P2PMsg;

    uint16_t counter=0;

    bool busy =FALSE;

    message_t pkt;

    task void test() { }

    event void Boot.booted()

    {

    DbgOut(9,"BOOt");  

    call AMControl.start();

    }

    event void Timer0.fired()

    {

    counter++;

    if (!busy)

    {

         P2PMsg* btrpkt = (P2PMsg*)(call Packet.getPayload(&pkt, sizeof(P2PMsg)));

         btrpkt->nodeid = TOS_NODE_ID;

         btrpkt->counter = counter;

    call AMPacket.setGroup(&pkt,TOS_IEEE_GROUP);   

         if (call AMSend.send(destAddress, &pkt, sizeof(P2PMsg)) == SUCCESS)

         {

           busy = TRUE;

         }

         }

    }

    event void AMControl.startDone(error_t err)

    {

    if(err==SUCCESS)

    call Timer0.startPeriodic(1000);

    else

    call AMControl.start();

    }

       event void AMSend.sendDone(message_t* msg, error_t erro)

       {

    if (&pkt == msg)

           busy = FALSE;  

       }

    event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len)

    {

        if (len == sizeof(P2PMsg))

       {

         P2PMsg* btrpkt = (P2PMsg*)payload;

         DbgOut(9,"Receive Id is %d,Data is %d,Length is %d ",(uint16_t)btrpkt->nodeid,(uint16_t)btrpkt->counter,len);  

         call Leds.set(btrpkt->counter);

       }

       return msg;

    }

     event void AMControl.stopDone(error_t err)   { }

    }

    3makefile 编译文件

    COMPONENT= TestP2PC

    PFLAGS += -DUART_DEBUG

    PFLAGS += -DUART_BAUDRATE=9600

    include $(MAKERULES)

    实验环境:

    1. 上位机操作系统为WindowsXP,在Cygwin环境下编译
    2. 集成开发环境为Notepad++

    实验报告人:木舟 报告时间2018.11.16

  • 相关阅读:
    UILocalNotification实现本地的闹钟提醒的方法
    自定义UITableViewCell:Cell高度、分割线、间距等
    第三方苹果开发库之ASIHTTPRequest(翻译版)
    字符串NSString和数组NSArray操作
    MFMailComposeViewController发送邮件的实例
    IOS开发之手势—UIGestureRecognizer 共存
    ios 画图总结 [转]
    iOS-响应上下左右滑动手势
    MFMessageComposeViewController程序内发送短信息的实例
    FIELDSYMBOLS 学习—转载
  • 原文地址:https://www.cnblogs.com/LeonNchu/p/10695787.html
Copyright © 2020-2023  润新知