inet-3.6.4/src/inet/linklayer/xmac/XMacLayer.cc
/**
 * Initialize method of XMacLayer. Init all parameters, schedule timers.
 */
Initialize method of XMacLayer. Init all parameters, schedule timers.
Initialize method of XMacLayer . Init all parameters schedule timers .
void XMacLayer::initialize(int stage)
{
	MACProtocolBase::initialize(stage);
	if (stage == INITSTAGE_LOCAL) {
		queueLength   = hasPar("queueLength")   ? par("queueLength")   : 10;
		animation     = hasPar("animation")     ? par("animation")     : true;
		slotDuration  = hasPar("slotDuration")  ? par("slotDuration")  : 1.;
		bitrate       = hasPar("bitrate")       ? par("bitrate")       : 15360.;
        headerLength = par("headerLength").longValue();
		checkInterval = hasPar("checkInterval") ? par("checkInterval") : 0.1;
		txPower       = hasPar("txPower")       ? par("txPower")       : 50.;
		useMacAcks    = hasPar("useMACAcks")    ? par("useMACAcks")    : false;
		maxTxAttempts = hasPar("maxTxAttempts") ? par("maxTxAttempts") : 2;
		EV_DEBUG << "headerLength: " << headerLength << ", bitrate: " << bitrate << endl;
		stats = par("stats");
		nbTxDataPackets = 0;
		nbTxPreambles = 0;
		nbRxDataPackets = 0;
		nbRxPreambles = 0;
		nbMissedAcks = 0;
		nbRecvdAcks=0;
		nbDroppedDataPackets=0;
		nbRxBrokenDataPackets = 0;
		nbTxAcks=0;
		txAttempts = 0;
		lastDataPktDestAddr = MACAddress::BROADCAST_ADDRESS;
		lastDataPktSrcAddr  = MACAddress::BROADCAST_ADDRESS;
		cModule *radioModule = getModuleFromPar<cModule>(par("radioModule"), this);
        radioModule->subscribe(IRadio::radioModeChangedSignal, this);
        radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
        radio = check_and_cast<IRadio *>(radioModule);
		macState = INIT;
		WATCH(macState);
	}
	else if(stage == INITSTAGE_LINK_LAYER) {
	    initializeMACAddress();
	    registerInterface();
		wakeup = new cMessage("wakeup");
		wakeup->setKind(XMAC_WAKE_UP);
		data_timeout = new cMessage("data_timeout");
		data_timeout->setKind(XMAC_DATA_TIMEOUT);
		data_timeout->setSchedulingPriority(100);
		data_tx_over = new cMessage("data_tx_over");
		data_tx_over->setKind(XMAC_DATA_TX_OVER);
		stop_preambles = new cMessage("stop_preambles");
		stop_preambles->setKind(XMAC_STOP_PREAMBLES);
		send_preamble = new cMessage("send_preamble");
		send_preamble->setKind(XMAC_SEND_PREAMBLE);
		ack_tx_over = new cMessage("ack_tx_over");
		ack_tx_over->setKind(XMAC_ACK_TX_OVER);
		cca_timeout = new cMessage("cca_timeout");
		cca_timeout->setKind(XMAC_CCA_TIMEOUT);
		cca_timeout->setSchedulingPriority(100);
		send_ack = new cMessage("send_ack");
		send_ack->setKind(XMAC_SEND_ACK);
		start_xmac = new cMessage("start_xmac");
		start_xmac->setKind(XMAC_START_XMAC);
		ack_timeout = new cMessage("ack_timeout");
		ack_timeout->setKind(XMAC_ACK_TIMEOUT);
		resend_data = new cMessage("resend_data");
		resend_data->setKind(XMAC_RESEND_DATA);
		resend_data->setSchedulingPriority(100);
		switch_preamble_phase = new cMessage("switch_preamble_phase");
		switch_preamble_phase->setKind(SWITCH_PREAMBLE_PHASE);
		delay_for_ack_within_remote_rx = new cMessage("delay_for_ack_within_remote_rx");
		delay_for_ack_within_remote_rx->setKind(DELAY_FOR_ACK_WITHIN_REMOTE_RX);
		switching_done = new cMessage("switching_done");
		switching_done->setKind(XMAC_SWITCHING_FINISHED);
		scheduleAt(0.0, start_xmac);
	}
}
void XMacLayer :: initialize ( int stage ) { MACProtocolBase :: initialize ( stage ) ; if ( stage == INITSTAGE_LOCAL ) { queueLength = hasPar ( " " ) ? par ( " " ) : 10 ; animation = hasPar ( " " ) ? par ( " " ) : true ; slotDuration = hasPar ( " " ) ? par ( " " ) : 1. ; bitrate = hasPar ( " " ) ? par ( " " ) : 15360. ; headerLength = par ( " " ) . longValue ( ) ; checkInterval = hasPar ( " " ) ? par ( " " ) : 0.1 ; txPower = hasPar ( " " ) ? par ( " " ) : 50. ; useMacAcks = hasPar ( " " ) ? par ( " " ) : false ; maxTxAttempts = hasPar ( " " ) ? par ( " " ) : 2 ; EV_DEBUG << " " << headerLength << " " << bitrate << endl ; stats = par ( " " ) ; nbTxDataPackets = 0 ; nbTxPreambles = 0 ; nbRxDataPackets = 0 ; nbRxPreambles = 0 ; nbMissedAcks = 0 ; nbRecvdAcks = 0 ; nbDroppedDataPackets = 0 ; nbRxBrokenDataPackets = 0 ; nbTxAcks = 0 ; txAttempts = 0 ; lastDataPktDestAddr = MACAddress :: BROADCAST_ADDRESS ; lastDataPktSrcAddr = MACAddress :: BROADCAST_ADDRESS ; cModule * radioModule = getModuleFromPar < cModule > ( par ( " " ) , this ) ; radioModule -> subscribe ( IRadio :: radioModeChangedSignal , this ) ; radioModule -> subscribe ( IRadio :: transmissionStateChangedSignal , this ) ; radio = check_and_cast < IRadio * > ( radioModule ) ; macState = INIT ; WATCH ( macState ) ; } else if ( stage == INITSTAGE_LINK_LAYER ) { initializeMACAddress ( ) ; registerInterface ( ) ; wakeup = new cMessage ( " " ) ; wakeup -> setKind ( XMAC_WAKE_UP ) ; data_timeout = new cMessage ( " " ) ; data_timeout -> setKind ( XMAC_DATA_TIMEOUT ) ; data_timeout -> setSchedulingPriority ( 100 ) ; data_tx_over = new cMessage ( " " ) ; data_tx_over -> setKind ( XMAC_DATA_TX_OVER ) ; stop_preambles = new cMessage ( " " ) ; stop_preambles -> setKind ( XMAC_STOP_PREAMBLES ) ; send_preamble = new cMessage ( " " ) ; send_preamble -> setKind ( XMAC_SEND_PREAMBLE ) ; ack_tx_over = new cMessage ( " " ) ; ack_tx_over -> setKind ( XMAC_ACK_TX_OVER ) ; cca_timeout = new cMessage ( " " ) ; cca_timeout -> setKind ( XMAC_CCA_TIMEOUT ) ; cca_timeout -> setSchedulingPriority ( 100 ) ; send_ack = new cMessage ( " " ) ; send_ack -> setKind ( XMAC_SEND_ACK ) ; start_xmac = new cMessage ( " " ) ; start_xmac -> setKind ( XMAC_START_XMAC ) ; ack_timeout = new cMessage ( " " ) ; ack_timeout -> setKind ( XMAC_ACK_TIMEOUT ) ; resend_data = new cMessage ( " " ) ; resend_data -> setKind ( XMAC_RESEND_DATA ) ; resend_data -> setSchedulingPriority ( 100 ) ; switch_preamble_phase = new cMessage ( " " ) ; switch_preamble_phase -> setKind ( SWITCH_PREAMBLE_PHASE ) ; delay_for_ack_within_remote_rx = new cMessage ( " " ) ; delay_for_ack_within_remote_rx -> setKind ( DELAY_FOR_ACK_WITHIN_REMOTE_RX ) ; switching_done = new cMessage ( " " ) ; switching_done -> setKind ( XMAC_SWITCHING_FINISHED ) ; scheduleAt ( 0.0 , start_xmac ) ; } }
Initialize method of XMacLayer.
Initialize method of XMacLayer .