⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrapperp.nc

📁 tinyos-2.x.rar
💻 NC
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 2008, Technische Universitaet Berlin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright 
 *   notice, this list of conditions and the following disclaimer in the 
 *   documentation and/or other materials provided with the distribution.
 * - Neither the name of the Technische Universitaet Berlin nor the names 
 *   of its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * - Revision -------------------------------------------------------------
 * $Date: 2009/09/18 16:41:20 $
 * @author Jan Hauer <hauer@tkn.tu-berlin.de>
 * @author: Ricardo Severino <rars@isep.ipp.pt>
 * ========================================================================
 */

module WrapperP
{
  uses {
    interface MLME_START;
    interface MLME_SET;
    interface MLME_GET;

    interface MLME_ASSOCIATE;
    interface MLME_DISASSOCIATE;

    interface MLME_BEACON_NOTIFY;
    interface MLME_GTS;

    interface MLME_ORPHAN;

    interface MLME_SYNC;
    interface MLME_SYNC_LOSS;

    interface MLME_RESET;

    interface MLME_SCAN;

    //MCPS
    interface MCPS_DATA;
    interface MCPS_PURGE;

    interface IEEE154Frame;
    interface IEEE154BeaconFrame;
    interface Pool<message_t> as MessagePool;
    interface Packet;
  }

  provides
  {
    interface OPENZB_MLME_RESET;
    interface OPENZB_MLME_START;

    interface OPENZB_MLME_GET;
    interface OPENZB_MLME_SET;

    interface OPENZB_MLME_BEACON_NOTIFY;
    interface OPENZB_MLME_GTS;

    interface OPENZB_MLME_ASSOCIATE;
    interface OPENZB_MLME_DISASSOCIATE;

    interface OPENZB_MLME_ORPHAN;
    interface OPENZB_MLME_SYNC;
    interface OPENZB_MLME_SYNC_LOSS;
    interface OPENZB_MLME_SCAN;

    interface OPENZB_MCPS_DATA;
  }

}
implementation
{

  /* ----------------------- MLME-RESET ----------------------- */

  command error_t OPENZB_MLME_RESET.request(uint8_t set_default_PIB)
  {
    return call MLME_RESET.request(set_default_PIB != 0);
  }

  event void MLME_RESET.confirm(ieee154_status_t status)
  {
    signal OPENZB_MLME_RESET.confirm(status);
  }

  /* ----------------------- MLME-ASSOCIATE ----------------------- */

  command error_t OPENZB_MLME_ASSOCIATE.request(uint8_t LogicalChannel,uint8_t CoordAddrMode,
      uint16_t CoordPANId,uint32_t CoordAddress[],uint8_t CapabilityInformation,bool securityenable)
  {
    ieee154_CapabilityInformation_t capabilityInformation;
    ieee154_address_t coordAddress;

    if (securityenable)
      return IEEE154_UNSUPPORTED_SECURITY;
    memcpy(&coordAddress, CoordAddress, 8);
    *((uint8_t*) &capabilityInformation) = CapabilityInformation; // TODO: check
    return call MLME_ASSOCIATE.request  (
                          LogicalChannel,
                          0, // ChannelPage
                          CoordAddrMode,
                          CoordPANId,
                          coordAddress,
                          capabilityInformation,
                          NULL //security
                        );
  }

  event void MLME_ASSOCIATE.confirm    (
      uint16_t AssocShortAddress,
      uint8_t status,
      ieee154_security_t *security
      )
  {
    signal OPENZB_MLME_ASSOCIATE.confirm(AssocShortAddress, status);
  }

  command error_t OPENZB_MLME_ASSOCIATE.response(uint32_t DeviceAddress[], 
      uint16_t AssocShortAddress, uint8_t status, bool securityenable)
  {
    uint64_t deviceAddress;

    if (securityenable)
      return IEEE154_UNSUPPORTED_SECURITY;
    memcpy(&deviceAddress, DeviceAddress, 8);
    return call MLME_ASSOCIATE.response  (
                          deviceAddress,
                          AssocShortAddress,
                          status,
                          NULL //security
                        );
  }

  event void MLME_ASSOCIATE.indication (
      uint64_t DeviceAddress,
      ieee154_CapabilityInformation_t CapabilityInformation,
      ieee154_security_t *security
      )
  {
    uint32_t deviceAddress[2];
    uint8_t capabilityInformation = *((uint8_t*) &CapabilityInformation);
    memcpy(&DeviceAddress, deviceAddress, 8);
    signal OPENZB_MLME_ASSOCIATE.indication(
                          deviceAddress,
                          capabilityInformation,
                          FALSE, // SecurityUse
                          0 //ACLEntry
        );
  }

  /* ----------------------- MLME-DISASSOCIATE ----------------------- */

  command error_t OPENZB_MLME_DISASSOCIATE.request(uint32_t DeviceAddress[], 
      uint8_t disassociate_reason, bool securityenable)
  {
    // DeviceAddress is an extended address, c.f. Tab. 37 in 802.15.4-2003 
    uint16_t panID = call MLME_GET.macPANId();
    ieee154_address_t deviceAddress;
    memcpy(&deviceAddress, DeviceAddress, 8);
    return call MLME_DISASSOCIATE.request(
                          ADDR_MODE_EXTENDED_ADDRESS, // DeviceAddrMode,
                          panID,
                          deviceAddress,
                          disassociate_reason,
                          FALSE, // TxIndirect,
                          NULL // security
                        );

  }

  event void MLME_DISASSOCIATE.indication (
      uint64_t DeviceAddress,
      ieee154_disassociation_reason_t DisassociateReason,
      ieee154_security_t *security
      )
  {
    uint32_t deviceAddress[2];
    memcpy(&DeviceAddress, deviceAddress, 8);
    signal OPENZB_MLME_DISASSOCIATE.indication(
        deviceAddress, DisassociateReason, 0, 0);
  }


  event void MLME_DISASSOCIATE.confirm    (
      ieee154_status_t status,
      uint8_t DeviceAddrMode,
      uint16_t DevicePANID,
      ieee154_address_t DeviceAddress
      )
  {
    signal OPENZB_MLME_DISASSOCIATE.confirm(status);
  }

  /* ----------------------- MLME-START ----------------------- */

  command error_t OPENZB_MLME_START.request(uint32_t PANId, uint8_t LogicalChannel, 
      uint8_t beacon_order, uint8_t superframe_order,bool pan_coodinator,
      bool BatteryLifeExtension,bool CoordRealignment,bool securityenable,
      uint32_t StartTime)
  {
    if (securityenable)
      return IEEE154_UNSUPPORTED_SECURITY;
    return call MLME_START.request (
                          PANId,
                          LogicalChannel,
                          0, // ChannelPage,
                          StartTime,
                          beacon_order,
                          superframe_order,
                          pan_coodinator,
                          BatteryLifeExtension,
                          CoordRealignment,
                          NULL, // coordRealignSecurity
                          NULL  // beaconSecurity
        );
  }

  event void MLME_START.confirm    (
      ieee154_status_t status)
  {
    signal OPENZB_MLME_START.confirm(status);
  }

  /* ----------------------- MLME-SYNC ----------------------- */

  command error_t OPENZB_MLME_SYNC.request(uint8_t logical_channel,uint8_t track_beacon)
  {
    return call MLME_SYNC.request(logical_channel, 0, // ChannelPage
                               track_beacon);
  }


  event void MLME_SYNC_LOSS.indication (
      ieee154_status_t lossReason,
      uint16_t PANId,
      uint8_t LogicalChannel,
      uint8_t ChannelPage,
      ieee154_security_t *security
      )
  {
    signal OPENZB_MLME_SYNC_LOSS.indication(lossReason);
  }

  /* ----------------------- MLME-SCAN ----------------------- */

  enum {
    NUM_ENERGY_DETECT_LIST_ENTRIES = 16,
    NUM_PANDESCRIPTOR_LIST_ENTRIES = 16,
  };

  bool isScanBusy = FALSE;
  int8_t m_EnergyDetectList[NUM_ENERGY_DETECT_LIST_ENTRIES];
  ieee154_PANDescriptor_t m_PANDescriptorList[NUM_PANDESCRIPTOR_LIST_ENTRIES];

  command error_t OPENZB_MLME_SCAN.request(uint8_t ScanType, uint32_t ScanChannels, uint8_t ScanDuration)
  {
    if (isScanBusy)
      return IEEE154_TRANSACTION_OVERFLOW;
    isScanBusy = TRUE;
    return call MLME_SCAN.request  (
                          ScanType,
                          ScanChannels,
                          ScanDuration,
                          0, // ChannelPage,
                          NUM_ENERGY_DETECT_LIST_ENTRIES, // EnergyDetectListNumEntries,
                          m_EnergyDetectList, // EnergyDetectList,
                          NUM_PANDESCRIPTOR_LIST_ENTRIES, // PANDescriptorListNumEntries,
                          m_PANDescriptorList, // PANDescriptorList,
                          NULL //security
                        );
  }

  event void MLME_SCAN.confirm    (
      ieee154_status_t status,
      uint8_t ScanType,
      uint8_t ChannelPage,
      uint32_t UnscannedChannels,
      uint8_t EnergyDetectNumResults,
      int8_t* EnergyDetectList,
      uint8_t PANDescriptorListNumResults,
      ieee154_PANDescriptor_t* PANDescriptorList
      )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -