INET Framework for OMNeT++/OMNEST
BonnMotionMobility.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2005 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include "BonnMotionMobility.h"
00019 #include "BonnMotionFileCache.h"
00020 #include "FWMath.h"
00021 
00022 
00023 Define_Module(BonnMotionMobility);
00024 
00025 
00026 void BonnMotionMobility::initialize(int stage)
00027 {
00028     LineSegmentsMobilityBase::initialize(stage);
00029 
00030     EV << "initializing BonnMotionMobility stage " << stage << endl;
00031 
00032     if (stage == 1)
00033     {
00034         int nodeId = par("nodeId");
00035         if (nodeId == -1)
00036             nodeId = getParentModule()->getIndex();
00037 
00038         const char *fname = par("traceFile");
00039         const BonnMotionFile *bmFile = BonnMotionFileCache::getInstance()->getFile(fname);
00040 
00041         vecp = bmFile->getLine(nodeId);
00042         if (!vecp)
00043             error("invalid nodeId %d -- no such line in file '%s'", nodeId, fname);
00044         vecpos = 0;
00045 
00046         // obtain initial position
00047         const BonnMotionFile::Line& vec = *vecp;
00048         if (vec.size()>=3)
00049         {
00050             pos.x = vec[1];
00051             pos.y = vec[2];
00052             targetPos = pos;
00053         }
00054         updatePosition();
00055     }
00056 }
00057 
00058 BonnMotionMobility::~BonnMotionMobility()
00059 {
00060     BonnMotionFileCache::deleteInstance();
00061 }
00062 
00063 void BonnMotionMobility::setTargetPosition()
00064 {
00065     const BonnMotionFile::Line& vec = *vecp;
00066 
00067     if (vecpos+2 >= (int)vec.size())
00068     {
00069         stationary = true;
00070         return;
00071     }
00072 
00073     targetTime = vec[vecpos];
00074     targetPos.x = vec[vecpos+1];
00075     targetPos.y = vec[vecpos+2];
00076     vecpos += 3;
00077 
00078     EV << "TARGET: t=" << targetTime << " (" << targetPos.x << "," << targetPos.y << ")\n";
00079 }
00080 
00081 void BonnMotionMobility::fixIfHostGetsOutside()
00082 {
00083     raiseErrorIfOutside();
00084 }
00085