Hi, Guys!

I'd like to know the exactly moment that a mobile node reaches its
destination position. I've read and read so many time the method
MobileNode::set_destination (below) and I really don't figured it out.

I need this to send a packet exactly in that moment. Could anyone help me?

Thanks again!

Larissa

int
MobileNode::set_destination(double x, double y, double s)
{
    assert(initialized());

    if(x >= T_->upperX() || x <= T_->lowerX())
        return -1;
    if(y >= T_->upperY() || y <= T_->lowerY())
        return -1;

    update_position();    // figure out where we are now

    destX_ = x;
    destY_ = y;
    speed_ = s;

    dX_ = destX_ - X_;
    dY_ = destY_ - Y_;
    dZ_ = 0.0;        // this isn't used, since flying isn't allowed

    double len;

    if (destX_ != X_ || destY_ != Y_) {
        // normalize dx, dy to unit len
        len = sqrt( (dX_ * dX_) + (dY_ * dY_) );
        dX_ /= len;
        dY_ /= len;
    }

    position_update_time_ = Scheduler::instance().clock();

#ifdef DEBUG
    fprintf(stderr, "%d - %s: calling log_movement()\n",
        address_, __FUNCTION__);
#endif
    log_movement();

    /* update gridkeeper */
    if (GridKeeper::instance()){

        GridKeeper* gp =  GridKeeper::instance();
        gp-> new_moves(this);
    }

    if (namChan_ != 0) {

        double v = speed_ * sqrt( (dX_ * dX_) + (dY_ * dY_));

        sprintf(nwrk_,
            "n -t %f -s %d -x %f -y %f -U %f -V %f -T %f",
            Scheduler::instance().clock(),
            nodeid_,
            X_, Y_,
            speed_ * dX_, speed_ * dY_,
            ( v != 0) ? len / v : 0. );
        namdump();
    }
    return 0;
}

-- 
"O maior prazer do inteligente é bancar o  idiota
 diante de um  idiota que banca o inteligente".

Reply via email to