void CsmaAloha::stateRxPacketNotForMe(Packet* p) {
    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxPacketNotForMe() pkt for another address. Dropping pkt" << endl;
    if ( p != NULL ) Packet::free(p);

    refreshState( CSMA_STATE_WRONG_PKT_RX );

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE:
        stateIdle();
        break;

    case CSMA_STATE_RX_LISTEN:
        stateCheckListenExpired();
        break;

    case CSMA_STATE_RX_BACKOFF:
        stateCheckBackoffExpired();
        break;

    case CSMA_STATE_RX_WAIT_ACK:
        stateCheckAckExpired();
        break;

    default:
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateRxPacketNotForMe() logical error, current state = "
             << status_info[curr_state] << endl;
        stateIdle();

    }
}
void CsmaAloha::Phy2MacStartRx(const Packet* p) {
    if (debug_) cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacStartRx() rx Packet " << endl;


    refreshReason(CSMA_REASON_START_RX);

    switch(curr_state) {

    case(CSMA_STATE_IDLE):
        stateRxIdle();
        break;

    case(CSMA_STATE_LISTEN):
        stateRxListen();
        break;

    case(CSMA_STATE_BACKOFF):
        stateRxBackoff();
        break;

    case(CSMA_STATE_WAIT_ACK):
        stateRxWaitAck();
        break;

    default: {
        cerr << NOW << "  CsmaAloha("<< addr << ")::Phy2MacStartRx() logical warning, current state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }

    }


}
示例#3
0
    Player( XGame *g ) : Sprite(g) {
        frameTime = 3;
        color = alienColors[rand()%alienColors.size()];

        walkSpeed = 18;
        jumpStartSpeed = 60;
        alive = true;
        stretch = false;
        jumping = false;
        y = 400;
        x = 70*6;

        for( int i=0; i<0xFFFF; ++i ) keys[i]=false;

        texture = game->loadSpritesheet("aliens");
        stateIdle();

        XGameTexture *t = game->getTexture(texture);
        applyAnimation();
        h = t->cropHeight;
        w = t->cropWidth;

        g->onKeyDown = std::bind(&Player::onKeyDown, this, std::placeholders::_1);
        g->onKeyUp = std::bind(&Player::onKeyUp, this, std::placeholders::_1);
    }
void
UwCsmaAloha_Trigger_SINK::stateDisableRx()
{
	refreshState(UW_CS_ALOHA_TRIG_SINK_STATE_DISABLE_RX);
	if (debug_)
		cout << NOW << "UwCsmaAloha_Trigger_SINK(" << addr
			 << ")----> Timer fired ----> Disabling Receving Data" << endl;
	receiving_state_active = false;
	stateIdle();
}
void CsmaAloha::stateCheckBackoffExpired() {
    refreshState(CSMA_STATE_CHK_BACKOFF_TIMEOUT);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateCheckBackoffExpired()" << endl;
    if (print_transitions) printStateInfo();
    if ( backoff_timer.isActive() ) {
        refreshReason( CSMA_REASON_BACKOFF_PENDING );
        stateBackoff();
    }
    else if ( backoff_timer.isExpired() ) {
        refreshReason( CSMA_REASON_BACKOFF_TIMEOUT );
        exitBackoff();
        stateIdle();
    }
    else {
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateCheckBackoffExpired() backoff_timer logical error, current timer state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }
}
void CsmaAloha::stateRxData(Packet* data_pkt) {
    refreshState( CSMA_STATE_DATA_RX );

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxData() in state " << status_info[curr_state] << endl;
    refreshReason( CSMA_REASON_DATA_RX );

    hdr_mac* mach = HDR_MAC(data_pkt);
    int dst_addr = mach->macSA();

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateIdle();
    }
    break;

    case CSMA_STATE_RX_LISTEN: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckListenExpired();
    }
    break;

    case CSMA_STATE_RX_BACKOFF: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);
        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckBackoffExpired();
    }
    break;


    default:

        cerr << NOW << " CsmaAloha("<< addr << ")::stateRxData() logical error, prev state = " << status_info[prev_state]
             << endl;

    }
}
void CsmaAloha::stateRxAck(Packet* p) {
    ack_timer.stop();
    refreshState(CSMA_STATE_ACK_RX);
    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxAck() " << endl;

    Packet::free(p);

    refreshReason(CSMA_REASON_ACK_RX);

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE:
        stateIdle();
        break;

    case CSMA_STATE_RX_LISTEN:
        stateCheckListenExpired();
        break;

    case CSMA_STATE_RX_BACKOFF:
        stateCheckBackoffExpired();
        break;

    case CSMA_STATE_RX_WAIT_ACK:
        queuePop();
        updateAckTimeout(NOW - start_tx_time);
        incrAckPktsRx();
        stateIdle();
        break;

    default:

        cerr << NOW << " CsmaAloha("<< addr << ")::stateRxAck() logical error, prev state = " << status_info[prev_state]
             << endl;

    }
}
int
UwCsmaAloha_Trigger_SINK::command(int argc, const char *const *argv)
{
	Tcl &tcl = Tcl::instance();
	if (argc == 2) {
		if (strcasecmp(argv[1], "sinkRun") == 0) {
			stateIdle();
			return TCL_OK;
		} else if (strcasecmp(argv[1], "getNTriggerSent") == 0) {
			tcl.resultf("%d", getTriggerMsgSent());
			return TCL_OK;
		}
	}
	return MMac::command(argc, argv);
}
void CsmaAloha::stateCheckListenExpired() {
    refreshState(CSMA_STATE_CHK_LISTEN_TIMEOUT);

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateCheckListenExpired()" << endl;
    if (print_transitions) printStateInfo();
    if ( listen_timer.isActive() ) {
        refreshReason( CSMA_REASON_LISTEN_PENDING );
        refreshState( CSMA_STATE_LISTEN );
    }
    else if ( listen_timer.isExpired() ) {
        refreshReason( CSMA_REASON_LISTEN_TIMEOUT );
        if ( !( prev_state == CSMA_STATE_TX_ACK || prev_state == CSMA_STATE_WRONG_PKT_RX
                || prev_state == CSMA_STATE_ACK_RX || prev_state == CSMA_STATE_DATA_RX ) ) stateTxData();
        else stateListen();
    }
    else {
        cerr << NOW << "  CsmaAloha("<< addr << ")::stateCheckListenExpired() listen_timer logical error, current timer state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }
}
示例#10
0
 void applyInput() {
     if( keys[XK_Left] ) {
         velX = -walkSpeed;
         mirror = true;
         if( !jumping ) stateRun(true);
     } else if( keys[XK_Right] ) {
         velX = walkSpeed;
         mirror = false;
         if( !jumping ) stateRun(false);
     } else {
         velX *= 0.5;
     }
     if( !jumping ) {
         if(velX==0 && velY==0) {
             stateIdle();
         }
         if( keys[XK_space] ) {
             stateJump();
         }
     }
 }
void CsmaAloha::stateTxData()
{
    refreshState(CSMA_STATE_TX_DATA);


    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() " << endl;
    if (print_transitions) printStateInfo();

    curr_data_pkt = Q.front();


    if ( data_sn_queue.front() != last_sent_data_id) {
        resetCurrTxRounds();
        ack_timer.resetCounter();
        listen_timer.resetCounter();
        backoff_timer.resetCounter();
    }
    if ( curr_tx_rounds < max_tx_tries ) {
        hdr_mac* mach = HDR_MAC(curr_data_pkt);

        mach->macSA() = addr;
        start_tx_time = NOW;
        last_sent_data_id = data_sn_queue.front();
        txData();
    }
    else {
        queuePop(false);
        incrDroppedPktsTx();

        refreshReason(CSMA_REASON_MAX_TX_TRIES);

        if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() curr_tx_rounds " << curr_tx_rounds
                             << " > max_tx_tries = " << max_tx_tries << endl;

        stateIdle();
    }
}
void CsmaAloha::Phy2MacEndTx(const Packet* p) {




    if (debug_) cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() end tx packet" << endl;

    switch(curr_state) {

    case(CSMA_STATE_TX_DATA): {
        refreshReason(CSMA_REASON_DATA_TX);
        if (ack_mode == CSMA_ACK_MODE) {

            if (debug_) cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() DATA sent,from "
                                 << status_info[curr_state] << " to "
                                 << status_info[CSMA_STATE_WAIT_ACK] << endl;

            stateWaitAck();
        }
        else {

            if (debug_) cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() DATA sent, from "
                                 << status_info[curr_state] << " to " << status_info[CSMA_STATE_IDLE] << endl;

            stateIdle();
        }
    }
    break;

    case(CSMA_STATE_TX_ACK): {
        refreshReason(CSMA_REASON_ACK_TX);

        if ( prev_prev_state == CSMA_STATE_RX_BACKOFF ) {
            if (debug_) cout << NOW  << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() ack sent, from "
                                 << status_info[curr_state] << " to " << status_info[CSMA_STATE_CHK_BACKOFF_TIMEOUT] << endl;

            stateCheckBackoffExpired();
        }
        else if ( prev_prev_state == CSMA_STATE_RX_LISTEN ) {
            if (debug_) cout << NOW  << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() ack sent, from "
                                 << status_info[curr_state] << " to " << status_info[CSMA_STATE_CHK_LISTEN_TIMEOUT] << endl;

            stateCheckListenExpired();
        }
        else if ( prev_prev_state == CSMA_STATE_RX_IDLE ) {

            if (debug_) cout << NOW  << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() ack sent, from "
                                 << status_info[curr_state] << " to " << status_info[CSMA_STATE_IDLE] << endl;

            stateIdle();
        }
        else {

            cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() logical error in timers, current state = "
                 << status_info[curr_state] << endl;
            stateIdle();
        }
    }
    break;

    default: {
        cout << NOW << "  CsmaAloha("<< addr <<")::Phy2MacEndTx() logical error, current state = "
             << status_info[curr_state] << endl;
        stateIdle();
    }
    break;

    }

}