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

📄 mac_802_15_4_transac.cpp

📁 csma协议
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Copyright (c) 2001-2008, Scalable Network Technologies, Inc.  All Rights Reserved.//                          6701 Center Drive West//                          Suite 520//                          Los Angeles, CA 90045//                          sales@scalable-networks.com//// This source code is licensed, not sold, and is subject to a written// license agreement.  Among other things, no portion of this source// code may be copied, transmitted, disclosed, displayed, distributed,// translated, used as the basis for a derivative work, or used, in// whole or in part, for any program or purpose other than its intended// use in compliance with the license agreement as part of the QualNet// software.  This source code and certain of the algorithms contained// within it are confidential trade secrets of Scalable Network// Technologies, Inc. and may not be used as the basis for any other// software, hardware, product or service.#include "mac_802_15_4_transac.h"// /**// FUNCTION   :: Mac802_15_4DevLinkInit// LAYER      :: Mac// PURPOSE    :: To initialize device link structure.// PARAMETERS ::// + devLink    : M802_15_4DEVLINK*     : Device Link structure// + addr       : MACADDR            : MAC address// + cap        : UInt8                 : Device capabilities// RETURN  :: None.// **/int Mac802_15_4AddDeviceLink(        M802_15_4DEVLINK** deviceLink1,        M802_15_4DEVLINK** deviceLink2,        MACADDR addr,        UInt8 cap){    M802_15_4DEVLINK* tmp;    if(*deviceLink2 == NULL)        //not exist yet    {        Mac802_15_4DevLinkInit(deviceLink2, addr,cap);        if (*deviceLink2 == NULL)        {            return 1;        }        *deviceLink1 = *deviceLink2;    }    else    {        Mac802_15_4DevLinkInit(&tmp, addr,cap);        if (tmp == NULL)        {            return 1;        }        tmp->last = *deviceLink2;        (*deviceLink2)->next = tmp;        *deviceLink2 = tmp;    }    return 0;}// /**// FUNCTION   :: Mac802_15_4UpdateDeviceLink// LAYER      :: Mac// PURPOSE    :: Deletes or update device link at the node// PARAMETERS ::// + oper       : int                   : Operation// + deviceLink1: M802_15_4DEVLINK*     : Device Link structure// + deviceLink2: M802_15_4DEVLINK*     : Device Link structure// + addr       : MACADDR            : MAC address// RETURN  :: int// **/int Mac802_15_4UpdateDeviceLink(        int oper,        M802_15_4DEVLINK** deviceLink1,        M802_15_4DEVLINK** deviceLink2,        MACADDR addr){    M802_15_4DEVLINK* tmp;    int rt;    rt = 1;    tmp = *deviceLink1;    while(tmp != NULL)    {        if(tmp->addr64 == addr)        {            if (oper == 1)    //delete an element            {                if(tmp->last != NULL)                {                    tmp->last->next = tmp->next;                    if(tmp->next != NULL)                        tmp->next->last = tmp->last;                    else                        *deviceLink2 = tmp->last;                }                else if (tmp->next != NULL)                {                    *deviceLink1 = tmp->next;                    tmp->next->last = NULL;                }                else                {                    *deviceLink1 = NULL;                    *deviceLink2 = NULL;                }                MEM_free((void *)tmp);            }            rt = 0;            break;        }        tmp = tmp->next;    }    return rt;}// /**// FUNCTION   :: Mac802_15_4NumberDeviceLink// LAYER      :: Mac// PURPOSE    :: Returns number of current device links at the node// PARAMETERS ::// + deviceLink1: M802_15_4DEVLINK*     : Device Link structure// RETURN  :: int// **/int Mac802_15_4NumberDeviceLink(M802_15_4DEVLINK** deviceLink1){    M802_15_4DEVLINK* tmp;    int num;    num = 0;    tmp = *deviceLink1;    while(tmp != NULL)    {        num++;        tmp = tmp->next;    }    return num;}// /**// FUNCTION   :: Mac802_15_4ChkAddDeviceLink// LAYER      :: Mac// PURPOSE    :: Adds device link to the node// PARAMETERS ::// + deviceLink1: M802_15_4DEVLINK*     : Device Link structure// + deviceLink2: M802_15_4DEVLINK*     : Device Link structure// + addr       : MACADDR            : MAC address// + cap        : UInt8                 : Device capabilities// RETURN  :: int// **/int Mac802_15_4ChkAddDeviceLink(        M802_15_4DEVLINK** deviceLink1,        M802_15_4DEVLINK** deviceLink2,        MACADDR addr,        UInt8 cap){    int i;    i = Mac802_15_4UpdateDeviceLink(2, deviceLink1, deviceLink2, addr);    if (i == 0)    {        return 1;    }    i = Mac802_15_4AddDeviceLink(deviceLink1, deviceLink2, addr, cap);    if (i == 0)    {        return 0;    }    else    {        return 2;    }}// /**// FUNCTION   :: Mac802_15_4EmptyDeviceLink// LAYER      :: Mac// PURPOSE    :: Deletes all device links// PARAMETERS ::// + deviceLink1: M802_15_4DEVLINK*     : Device Link structure// + deviceLink2: M802_15_4DEVLINK*     : Device Link structure// RETURN  :: None// **/void Mac802_15_4EmptyDeviceLink(        M802_15_4DEVLINK** deviceLink1,        M802_15_4DEVLINK** deviceLink2){    M802_15_4DEVLINK* tmp;    M802_15_4DEVLINK* tmp2;    if(*deviceLink1 != NULL)    {        tmp = *deviceLink1;        while(tmp != NULL)        {            tmp2 = tmp;            tmp = tmp->next;            MEM_free((void*)tmp2);        }        *deviceLink1 = NULL;    }    *deviceLink2 = *deviceLink1;}// /**// FUNCTION   :: Mac802_15_4PurgeTransacLink// LAYER      :: Mac// PURPOSE    :: To initialize transaction link structure.// PARAMETERS ::// + node           : Node*                  : Node pointer// + transacLink1   : M802_15_4TRANSLINK**   : Transaction Link structure// + transacLink2   : M802_15_4TRANSLINK**   : Transaction Link structure// RETURN  :: None.// **/void Mac802_15_4PurgeTransacLink(        Node* node,        M802_15_4TRANSLINK** transacLink1,        M802_15_4TRANSLINK** transacLink2){    //purge expired transactions    M802_15_4TRANSLINK* tmp;    M802_15_4TRANSLINK* tmp2;    tmp = *transacLink1;    while(tmp != NULL)    {        if (getSimTime(node) > tmp->expTime)        {            tmp2 = tmp;            if (tmp->next != NULL)            {                tmp = tmp->next->next;            }            else            {                tmp = NULL;            }            //--- delete the transaction ---            //don't try to call updateTransacLink() -- to avoid re-entries of            //functions            if(tmp2->last != NULL)            {                tmp2->last->next = tmp2->next;                if(tmp2->next != NULL)                {                    tmp2->next->last = tmp2->last;                }                else                {                    *transacLink2 = tmp2->last;                }            }            else if (tmp2->next != NULL)            {                *transacLink1 = tmp2->next;                tmp2->next->last = NULL;            }            else            {                *transacLink1 = NULL;                *transacLink2 = NULL;            }            //free the packet first            MESSAGE_Free(node, tmp2->pkt);            MEM_free((void*)tmp2);            //--------------------------------        }        else            tmp = tmp->next;    }}// /**// FUNCTION   :: Mac802_15_4AddTransacLink// LAYER      :: Mac// PURPOSE    :: Adds transaction link// PARAMETERS ::// + transacLink1   : M802_15_4TRANSLINK**   : Transaction Link structure// + transacLink2   : M802_15_4TRANSLINK**   : Transaction Link structure// + pendAM         : UInt8                  :// + pendAddr       : MACADDR             : MAC address// + p              : Message*               : Message// + msduH          : UInt8                  :// + kpTime         : clocktype              :// RETURN  :: int// **/int Mac802_15_4AddTransacLink(        Node* node,        M802_15_4TRANSLINK** transacLink1,        M802_15_4TRANSLINK** transacLink2,        UInt8 pendAM,        MACADDR pendAddr,        Message* p,        UInt8 msduH,        clocktype kpTime){    M802_15_4TRANSLINK* tmp;    if(*transacLink2 == NULL)       //not exist yet    {        Mac802_15_4TransLink(node,                             transacLink2,                              pendAM,                              pendAddr,                              p,                              msduH,                              kpTime);        if (*transacLink2 == NULL)        {            return 1;        }        *transacLink1 = *transacLink2;    }    else    {        Mac802_15_4TransLink(node,                             &tmp,                              pendAM,                              pendAddr,                              p,                              msduH,                              kpTime);        if (tmp == NULL)        {            return 1;        }        tmp->last = *transacLink2;        (*transacLink2)->next = tmp;        *transacLink2 = tmp;    }

⌨️ 快捷键说明

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