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

📄 sscs_802_15_4.cpp

📁 802.15.4协议的sscs的c文件和header文件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// **/void Sscs802_15_4MLME_POLL_confirm(        Node* node,        int interfaceIndex,        M802_15_4_enum status){    if(status == M802_15_4_INVALID_PARAMETER)    {        if(DEBUG)        {            printf("%lld : Node %d: 802.15.4SSCS : Polling invalid param\n",                   getSimTime(node), node->nodeId);        }    }    else if(status == M802_15_4_NO_ACK)    {        Sscs802_15_4MLME_SYNC_LOSS_indication(                    node,                    interfaceIndex,                    status);    }}// /**// FUNCTION   :: Sscs802_15_4PrintStats// LAYER      :: SSCS// PURPOSE    :: Print out statistics// PARAMETERS ::// + node      : Node*         : Pointer to node// + interfaceIndex : int      : Interface index// RETURN     :: void : NULL// **/staticvoid Sscs802_15_4PrintStats(Node* node, int interfaceIndex){    SscsData802_15_4* sscs802_15_4;    MacData802_15_4* mac;    char buf[MAX_STRING_LENGTH];    mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar;    sscs802_15_4 = (SscsData802_15_4*) mac->sscs;    // print out # of Associations accepted    if (sscs802_15_4->t_isFFD)    {        sprintf(buf, "Number of Association requests accepted = %ld",                sscs802_15_4->stats.numAssociationAcptd);        IO_PrintStat(node,                    "SSCS",                    "802.15.4",                    ANY_DEST,                    interfaceIndex,                    buf);        sprintf(buf, "Number of Association requests rejected = %ld",                sscs802_15_4->stats.numAssociationRejctd);        IO_PrintStat(node,                     "SSCS",                     "802.15.4",                     ANY_DEST,                     interfaceIndex,                     buf);    }    sprintf(buf, "Number of SYNC loss reported = %ld",            sscs802_15_4->stats.numSyncLoss);    IO_PrintStat(node,                 "SSCS",                 "802.15.4",                 ANY_DEST,                 interfaceIndex,                 buf);}// /**// FUNCTION     Sscs802_15_4Init// PURPOSE      Initialization function for 802.15.4 protocol of SSCS layer// PARAMETERS   Node* node//                  Node being initialized.//              NodeInput* nodeInput//                  Structure containing contents of input file.// RETURN       None// NOTES        None// **/void Sscs802_15_4Init(        Node* node,        const NodeInput* nodeInput,        int interfaceIndex){    SscsData802_15_4* sscs802_15_4;    BOOL wasFound = FALSE;    char retString[MAX_STRING_LENGTH];    int retVal;    clocktype retTime;    Address address;    clocktype startDev;    clocktype stopDev;    //clocktype startBeacon;    //clocktype stopBeacon;    MacData802_15_4* mac;    mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar;    sscs802_15_4 = (SscsData802_15_4*)MEM_malloc(sizeof(SscsData802_15_4));    ERROR_Assert(sscs802_15_4 != NULL,                 "802.15.4: Unable to allocate memory for SSCS data struc.");    memset(sscs802_15_4, 0, sizeof(SscsData802_15_4));    mac->sscs = sscs802_15_4;    RANDOM_SetSeed(sscs802_15_4->seed,                   node->globalSeed,                   node->nodeId,                   MAC_PROTOCOL_802_15_4,                   interfaceIndex);    sscs802_15_4->neverAsso = TRUE;    sscs802_15_4->state = S802_15_4NULL;    NetworkGetInterfaceInfo(            node,            mac->myMacData->interfaceIndex,            &address);    IO_ReadString(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-DEVICE-TYPE",            &wasFound,            retString);    if (wasFound)    {        if ((strcmp(retString, "RFD") == 0))        {            sscs802_15_4->t_isFFD = FALSE;        }        else if ((strcmp(retString, "FFD") == 0))        {            sscs802_15_4->t_isFFD = TRUE;            IO_ReadString(                    node->nodeId,                    &address,                    nodeInput,                    "MAC-802.15.4-FFD-MODE",                    &wasFound,                    retString);            if (wasFound)            {                if(strcmp(retString, "PANCOORD") == 0)                {                    sscs802_15_4->ffdMode = 0;                }                else if (strcmp(retString, "COORD") == 0)                {                    sscs802_15_4->ffdMode = 1;                }                else if (strcmp(retString, "DEVICE") == 0)                {                    sscs802_15_4->ffdMode = 2;                }                else                {                    //default PAN Coordinator                    ERROR_ReportWarning("Unknown FFD MODE, Takes default "                        "Mode as PANCOORD");                    sscs802_15_4->ffdMode = 0;                }            }            else            {                sscs802_15_4->ffdMode = 0;            }        }        else        {            //default = RFD            ERROR_ReportWarning("Unknown Device type, Takes default type: "                "RFD");            sscs802_15_4->t_isFFD = FALSE;        }    }    else    {        //default = RFD        sscs802_15_4->t_isFFD = FALSE;    }    IO_ReadInt(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-COORD-BO",            &wasFound,            &retVal);    if (wasFound)    {        sscs802_15_4->t_BO = (UInt8) retVal;        ERROR_Assert(sscs802_15_4->t_BO <=15,                "SSCS802_15_4Init:"                " Invalid BO value. Should be between 0 and 15");    }    else    {        //default value = 3        sscs802_15_4->t_BO = S802_15_4DEF_BOVAL;    }    IO_ReadInt(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-COORD-SO",            &wasFound,            &retVal);    if (wasFound)    {        sscs802_15_4->t_SO = (UInt8) retVal;        ERROR_Assert(sscs802_15_4->t_SO <=15,                    "SSCS802_15_4Init:"                    " Invalid SO value. Should be between 0 and 15");    }    else    {        //default value = 3        sscs802_15_4->t_SO = S802_15_4DEF_SOVAL;    }    IO_ReadTime(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-START-DEVICE-AT",            &wasFound,            &retTime);    if (wasFound)    {        ERROR_Assert(retTime >= 0,"Invalid Device Start time");        startDev = retTime;    }    else    {        startDev = 0;    }    IO_ReadTime(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-STOP-DEVICE-AT",            &wasFound,            &retTime);    if (wasFound)    {        ERROR_Assert((retTime >= 0) && ((retTime == 0)||            (startDev < retTime)),"Invalid Device Stop time or Device stop "            "time is less than Device start time");        stopDev = retTime;    }    else    {        stopDev = 0;    }    //for future use/*    IO_ReadTime(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-START-BEACON-AT",            &wasFound,            &retTime);    if (wasFound)    {        ERROR_Assert(retTime >= 0,"Invalid Beacon Start time");        startBeacon = retTime;    }    else    {        startBeacon = 0;    }    IO_ReadTime(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-STOP-BEACON-AT",            &wasFound,            &retTime);    if (wasFound)    {        ERROR_Assert((retTime >= 0) && ((retTime == 0) ||            (startBeacon < retTime )),"Invalid Beacon Stop time or Beacon "            "Stop time less than Beacon start time");        stopBeacon = retTime;    }    else    {        stopBeacon = 0;    }*/    IO_ReadTime(            node->nodeId,            &address,            nodeInput,            "MAC-802.15.4-POLL-INTERVAL",            &wasFound,            &retTime);    if (wasFound)    {        ERROR_Assert(retTime > 0,"Invalid Poll Interval, Should be greater "            "than 0");        sscs802_15_4->pollInt = retTime;    }    else    {        sscs802_15_4->pollInt = 0;    }    //schedule timers - add a random delay    //Start device    Sscs802_15_4SetTimer (node,            interfaceIndex,            S802_15_4STARTDEVICE,            startDev + (RANDOM_nrand(sscs802_15_4->seed) % (1 * SECOND))            );    //for future use    /*if (sscs802_15_4->t_isFFD && sscs802_15_4->ffdMode == 1)    //Start Beacons    {        Sscs802_15_4SetTimer (node,            interfaceIndex,            S802_15_4STARTBEACON,            startBeacon + (RANDOM_nrand(sscs802_15_4->seed) % (1 * SECOND))            );        //Stop Beacons - stopBeacon = 0, end of Simulation        if (stopBeacon != 0)        {            Sscs802_15_4SetTimer (node,                interfaceIndex,                S802_15_4STOPBEACON,                stopBeacon + (RANDOM_nrand(sscs802_15_4->seed) % (1 *                    SECOND))                );        }    }*/    if (stopDev != 0)    {        Sscs802_15_4SetTimer (node,                              interfaceIndex,                              S802_15_4STOPDEVICE,                              stopDev);    }    if ( (sscs802_15_4->t_isFFD && sscs802_15_4->ffdMode != 0) ||          !sscs802_15_4->t_isFFD)    {        //poll timer for non-beacon enabled        if (sscs802_15_4->t_BO == 15 && sscs802_15_4->pollInt)        {            Sscs802_15_4SetTimer (node,                                  interfaceIndex,                                  S802_15_4POLLINT,                                  sscs802_15_4->pollInt +                                    (RANDOM_nrand(sscs802_15_4->seed) % (1 *                                    SECOND)));        }    }}// /**// FUNCTION     Sscs802_15_4Layer// PURPOSE      To handle timer events. This is called via Mac802_15_4Layer()// PARAMETERS   Node *node//                  Node which received the message.//              int interfaceInde//                  Interface index on which message is received//              Message* msg//                  Message received by the layer.// RETURN       None// NOTES        None// **/void Sscs802_15_4Layer(Node* node, int interfaceIndex, Message* msg){    MacData802_15_4* mac;    SscsData802_15_4* sscs802_15_4;    S802_15_4Timer* timerInfo;    mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar;    sscs802_15_4 = (SscsData802_15_4*)mac->sscs;    timerInfo = (S802_15_4Timer*) MESSAGE_ReturnInfo(msg);    switch(timerInfo->timerType)    {        case S802_15_4STARTDEVICE:        {            if (sscs802_15_4->t_isFFD && sscs802_15_4->ffdMode == 0)                 //PAN coordinator            {                Sscs802_15_4StartPANCoord(                        node,                        interfaceIndex,                        M802_15_4_SUCCESS); //dummy status            }            else            {                Sscs802_15_4StartDevice(                        node,                        interfaceIndex,                        TRUE,                        M802_15_4_SUCCESS); //dummy status            }            break;        }        case S802_15_4STOPDEVICE:        {            Sscs802_15_4StopDevice(                    node,                    interfaceIndex,                    M802_15_4_SUCCESS);            break;        }        case S802_15_4STARTBEACON:        {            break;        }        case S802_15_4STOPBEACON:        {            break;        }        case S802_15_4ASSORETRY:        {            Sscs802_15_4StartDevice(                    node,                    interfaceIndex,                    TRUE,                    M802_15_4_SUCCESS); //dummy status            break;        }        case S802_15_4POLLINT:        {            Sscs802_15_4PollRequest(                    node,                    interfaceIndex);            break;        }        default:        {            break;        }    }}// /**// FUNCTION     Sscs802_15_4Finalize// PURPOSE      Called at the end of simulation to collect the results of//              the simulation of 802.15.4 protocol of the SSCS Layer.// PARAMETERS   Node* node//                  Node which received the message.// RETURN       None// NOTES        None// **/void Sscs802_15_4Finalize(Node* node, int interfaceIndex){    Sscs802_15_4PrintStats(node, interfaceIndex);}

⌨️ 快捷键说明

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