📄 propagation.pc
字号:
propData->fadingModel = RAYLEIGH; } else if (strcmp(buf, "RICIAN") == 0) { propData->fadingModel = RICIAN; wasFound = GLOMO_ReadDouble(-1, nodeInput, "RICIAN-K-FACTOR", &propData->ricianKFactor); if (!wasFound) { fprintf(stderr,"RICIAN-K-FACTOR not specified\n"); abort(); } propData->ricianStandardDeviation = CalculateRicianStandardDeviation(propData->ricianKFactor); } else { fprintf( stderr, "Error: unknown PROPAGATION-FADING-MODEL '%s'.\n", buf); abort(); }//if// }//if// // // Read BER-TABLE-FILE // wasFound = GLOMO_ReadCachedFile(nodeInput, "BER-TABLE-FILE", &berTableInput); if (wasFound == TRUE) { int i; double snr, ber; propData->numBerDataItems = berTableInput.numLines; propData->berTable = (GlomoPropBerTable *)calloc(propData->numBerDataItems, sizeof(GlomoPropBerTable)); for (i = 0; i < berTableInput.numLines; i++) { sscanf(berTableInput.inputStrings[i], "%lf %lf", &snr, &ber); propData->berTable[i].snr = snr; propData->berTable[i].ber = ber; } } else { propData->numBerDataItems = 0; propData->berTable = NULL; }}/* * FUNCTION GLOMO_PropagateInit * PURPOSE Initialization function for propagation functions * * Parameters: * node: node being initialized. * propagateData: shared structure for propagate data */void GLOMO_PropInit(GlomoNode *node, GlomoProp *propData) { node->propData = propData;}void GLOMO_PropBroadcast(GlomoPartition *partitionData, Message *msg){ PropInfo *propInfo = (PropInfo *)GLOMO_MsgReturnInfo(msg); GlomoProp *propData = &(partitionData->propData); GlomoNode *rxNode = partitionData->firstNode; while (rxNode != NULL) { int rxRadioNum = GLOMO_RadioGetRadioNumberForWavelength( rxNode, propInfo->wavelength); if ((rxNode->nodeAddr != propInfo->txAddr) && (rxRadioNum != INVALID_RADIO_NUMBER)) { double distance; double pathloss_dB; double fading_dB; double rxPower_dBm; float txAntennaGain_dB; float rxAntennaGain_dB; float rxAntennaHeight; distance = sqrt(SQUARE(rxNode->position.x - propInfo->txPosition.x) + SQUARE(rxNode->position.y - propInfo->txPosition.y) + SQUARE(rxNode->position.z - propInfo->txPosition.z)); txAntennaGain_dB = propInfo->txAntennaGain_dB; rxAntennaHeight = GLOMO_RadioAntennaHeight(rxNode, rxRadioNum); rxAntennaGain_dB = GLOMO_RadioAntennaGain_dB(rxNode, rxRadioNum); switch (propData->pathlossModel) { case FREE_SPACE: { pathloss_dB = PathlossFreeSpace(distance, propInfo->wavelength, txAntennaGain_dB, rxAntennaGain_dB); break; } case TWO_RAY: { pathloss_dB = PathlossTwoRay(distance, propInfo->wavelength, txAntennaGain_dB, propInfo->txAntennaHeight, rxAntennaGain_dB, rxAntennaHeight); break; } case PATHLOSS_MATRIX: { // // This is tricky, but this model sets distance here // pathloss_dB = PathlossMatrix(propInfo->txAddr, rxNode->nodeAddr, txAntennaGain_dB, rxAntennaGain_dB, propData->pathlossVar, &distance); break; } default: { assert(FALSE); abort(); } } switch (propData->fadingModel) { case NONE: fading_dB = 0.0; break; case RAYLEIGH: if (rxNode->nodeAddr == propInfo->correlatedFastFadingDestinationNode) { fading_dB = propInfo->correlatedFastFading_dB; } else { FadingRayleigh(rxNode->seed, &fading_dB); }//if// break; case RICIAN: if (rxNode->nodeAddr == propInfo->correlatedFastFadingDestinationNode) { fading_dB = propInfo->correlatedFastFading_dB; } else { FadingRician(propData->ricianKFactor, propData->ricianStandardDeviation, rxNode->seed, &fading_dB); }//if// break; default: assert(FALSE); abort(); break; }//switch// rxPower_dBm = propInfo->txPower_dBm - pathloss_dB + fading_dB; if (propData->propLimit_dBm > rxPower_dBm) { // signal not reachable to the receiver } else { // signal reachable to the receiver // further optimization (passing pointer) is necessary.. Message *newMsg = NULL; clocktype delay; PropInfo *newPropInfo; BOOL worthMsgCopying = GLOMO_RadioCanReceive(rxNode, rxRadioNum, rxPower_dBm); if (worthMsgCopying == TRUE) { newMsg = GLOMO_MsgCopy(rxNode, msg); assert(newMsg != NULL); GLOMO_MsgSetLayer(newMsg, GLOMO_RADIO_LAYER, 0); GLOMO_MsgSetEvent(newMsg, MSG_RADIO_FromChannelBegin); GLOMO_MsgSetInstanceId(newMsg, rxRadioNum); newPropInfo = (PropInfo *)GLOMO_MsgReturnInfo(newMsg); newMsg->error = FALSE; } else { // do not copy the message as it cannot be received newMsg = GLOMO_MsgAlloc(rxNode, GLOMO_RADIO_LAYER, 0, MSG_RADIO_FromChannelBegin); GLOMO_MsgSetInstanceId(newMsg, rxRadioNum); GLOMO_MsgInfoAlloc(rxNode, newMsg, sizeof(PropInfo)); newPropInfo = (PropInfo *)GLOMO_MsgReturnInfo(newMsg); memcpy(newPropInfo, propInfo, sizeof(PropInfo)); // // You should not set packetSize manually like this.. // newMsg->packetSize = msg->packetSize; newMsg->error = TRUE; } newPropInfo->rxPower_mW = NON_DB(rxPower_dBm); newPropInfo->correlatedFastFading_dB = fading_dB; // // This is from another partition so the delay until // airborne has already been factored during the // cross partition event (for lookahead). // GLOMO_MsgSend(rxNode, newMsg, ChannelPropagationDelay(distance)); } } rxNode = rxNode->nextNodeData; }}double GLOMO_PropBER(const GlomoNode *node, const double signalPower, const double noisePower){ GlomoProp *propData = node->propData; const GlomoPropBerTable *berTable = propData->berTable; const int numBerDataItems = propData->numBerDataItems; int i1, i2; double snrDiff; double snr = signalPower / noisePower; assert(numBerDataItems > 2); // // If the given snr is more than the biggest snr in the table, // simply return the ber of 0. // if (snr > berTable[numBerDataItems - 1].snr) { return 0.0; } i1 = numBerDataItems / 2; snrDiff = snr - berTable[i1].snr; // // Make berTable[i1].snr < snr < berTable[i2].snr // if (snrDiff < 0.0) { i2 = i1; i1 = 0; } else { i2 = numBerDataItems - 1; } while (i2 - i1 > 1) { int i3 = (i1 + i2) / 2; double snrDiff3 = snr - berTable[i3].snr; if (snrDiff3 < 0.0) { i2 = i3; } else { i1 = i3; } } return ((berTable[i1].ber - berTable[i2].ber) * (berTable[i2].snr - snr) / (berTable[i2].snr - berTable[i1].snr) + berTable[i2].ber);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -