zoukankan      html  css  js  c++  java
  • TinyOS节点间通信相关接口和组件介绍

    一.基本通信接口:
     
    Packet:提供了对message_t抽象数据类型的基本访问。这个接口的命令有:清空消息内容,获得消息的有效载荷区长度,获得消息有效载荷区的指针。

    //tos/interfaces/Packet.nc:

    #include

    interface Packet {

    command void clear(message_t* msg); //清空数据包,将msg的数据清空重新使用

    command uint8_t payloadLength(message_t* msg); //返回信息负载的长度

    command void setPayloadLength(message_t* msg, uint8_t len); //设置负载长度

    command uint8_t maxPayloadLength(); //返回最大负载

    command void* getPayload(message_t* msg, uint8_t len); //获取负载,len为需要的负载长度

    }

     

    Send:提供基本的自由地址的消息发送接口。这个接口提供的命令有:发送消息,取消未成功发出的消息。接口还提供了事件来指示一条消息是否成功发送。它也提供了一些便利的函数,来获得消息的最大有效载荷区长度以及消息有效载荷区的指针。

    //tos/interfaces/Send.nc:

    #include

    #include

    interface Send {

    command error_t send(message_t* msg, uint8_t len); //设置发送数据包的负载长度

    command error_t cancel(message_t* msg); //取消数据的传输

    event void sendDone(message_t* msg, error_t error); //发送数据完成

    command uint8_t maxPayloadLength(); //返回通讯层允许的最大负载长度

    command void* getPayload(message_t* msg, uint8_t len); //获取负载

    }

     

    Receive:提供最基本的消息接收接口。这个接口提供了接收消息后的事件。它也提供了些命令,可以方便地获得消息的有效载荷区长度以及消息有效载荷区的指针。

    //tos/interfaces/Receive.nc:

    #include

    #include

    interface Receive {

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

    }

     

    PacketAcknowledgements:提供了一种机制来要求对每个信息包的确认。

    //tos/interfaces/PacketAcknowledgements.nc:

    interface PacketAcknowledgements {

    async command error_t requestAck( message_t* msg ); //告诉协议,当要发送数据包时,使用同步的ACK

    async command error_t noAck( message_t* msg ); //告诉协议,当要发送数据包时,不使用同步的ACK

    async command bool wasAcked(message_t* msg); //判断传输的数据包是否为ACK

    }

     
    RadioTimeStamping:为无线电发射和接受提供时间标记信息。

    //tos/interfaces/RadioTimeStamping.nc:

    interface RadioTimeStamping

    {

    async event void transmittedSFD( uint16_t time, message_t* p_msg );

    async event void receivedSFD( uint16_t time ); //开始接收帧的时间

    }

     
     
    二.活动消息接口:活动消息(active message, AM)实现多渠道访问无线电。
     
    AMPacket:类似Packet,提供对message_t抽象数据类型的基本的AM访问。这个接口提供的命令有:获得节点的AM地址,AM信息包的目标地址以及AM信息包的类型。除此之外还有,设置AM信息包目标地址和类型,检查目标地址是否为本地节点。

    //tos/interfaces/AMPacket.nc:

    #include

    #include

    interface AMPacket {

    command am_addr_t address();//返回AM栈中节点的AM地址

    command am_addr_t destination(message_t* amsg);//返回AM数据包的目的地址的AM地址

    command am_addr_t source(message_t* amsg);//返回AM数据包的源地址的AM地址

    command void setDestination(message_t* amsg, am_addr_t addr);//设置AM数据包的目的地址的AM地址

    command void setSource(message_t* amsg, am_addr_t addr);//设置AM数据包的源地址的AM地址

    command bool isForMe(message_t* amsg);

    command am_id_t type(message_t* amsg);//返回AM数据包的AM类型,也就是说数据包的类型

    command void setType(message_t* amsg, am_id_t t);//设置包的类型

    command am_group_t group(message_t* amsg);//获得AM数据包的AM

    command void setGroup(message_t* amsg, am_group_t grp);//设置AM数据包的AM

    command am_group_t localGroup();//返回本节点的AM

    }

     
    AMSend:类似Send,提供了基本的活动消息发送接口。AMSendSend之间的关键区别是,AMSend在其发送命令里带有AM目标地址参数。

    //tos/interfaces/AMSend.nc:

    #include

    #include

    #include

    interface AMSend {

    command error_t send(am_addr_t addr, message_t* msg, uint8_t len);//发送负载长度为len的数据,addr为发送地址

    command error_t cancel(message_t* msg);//取消发送数据

    event void sendDone(message_t* msg, error_t error);

    command uint8_t maxPayloadLength();//返回通信层提供的最大负载长度

    command void* getPayload(message_t* msg, uint8_t len);//获取负载

    }

     
     
    三.支持AM接口的组件:
     

    AMReceiverC:提供支持以下的接口:ReceivePacketAMPacket

    AMSenderC:提供支持以下的接口:AMSendPacketAMPacketAcks(PacketAckowledgements)

    AMSnooperC:提供支持以下的接口:ReceivePacketAMPacket,进行嗅探的组件功能,和组件AMReceiverC功能相同,用于接收数据。

    AMSnoopingReceiverC:提供支持以下的接口:ReceivePacketAMPacket。与AMSnooperC组件比,多了一个ActiveMessageC.Receive[AMId]

    ActiveMessageAddressC:本模块提供了一些指令可以用来获取和设置节点的AM地址。这个模块不是为一般用户提供的,它容易破坏网络栈,所以如果不清楚操作的情况下要避免使用它

     
     
    所有的接口和组件使用了一个共同的消息缓冲抽象,称为message_t
     
     
     
  • 相关阅读:
    将excel中的数据导入到oracle数据库中
    C++学习–基础篇(书籍推荐及分享)
    Spring MVC No converter found for return value of type
    jQuery>学习
    动态建立事件
    sizeof:结构体对齐问题
    次窗体修改主窗体控件属性
    资源文件的读取和使用
    小端格式和大端格式(LittleEndian&BigEndian)
    新增控件数组
  • 原文地址:https://www.cnblogs.com/huanzxj/p/3489692.html
Copyright © 2011-2022 走看看