#include <ANSimMobility.h>
Inheritance diagram for ANSimMobility:

Protected Member Functions | |
| virtual void | initialize (int) |
| Initializes mobility model parameters. | |
| virtual void | setTargetPosition () |
| Overridden from LineSegmentsMobilityBase. | |
| void | extractDataFrom (cXMLElement *node) |
| Utility: extract data from given <position_update> element. | |
| virtual void | fixIfHostGetsOutside () |
| Overridden from LineSegmentsMobilityBase. | |
Protected Attributes | |
| int | nodeId |
| we'll have to compare this to the <node_id> elements | |
| cXMLElement * | nextPosChange |
| points to the next <position_change> element | |
|
|
Utility: extract data from given <position_update> element.
00092 {
00093 // extract data from <position_update> element
00094 // FIXME start_time has to be taken into account too! as pause from prev element's end_time
00095 const char *startTimeStr = firstChildWithTag(node, "start_time")->getNodeValue();
00096 const char *endTimeStr = firstChildWithTag(node, "end_time")->getNodeValue();
00097 cXMLElement *destElem = firstChildWithTag(node, "destination");
00098 const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue();
00099 const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue();
00100
00101 if (!endTimeStr || !xStr || !yStr)
00102 error("no content in <end_time>, <destination>/<xpos> or <ypos> element at %s", node->getSourceLocation());
00103
00104 targetTime = atof(endTimeStr);
00105 targetPos.x = atof(xStr);
00106 targetPos.y = atof(yStr);
00107 }
|
|
|
Overridden from LineSegmentsMobilityBase.
Implements LineSegmentsMobilityBase. 00110 {
00111 raiseErrorIfOutside();
00112 }
|
|
|
Initializes mobility model parameters.
Reimplemented from LineSegmentsMobilityBase. 00038 {
00039 LineSegmentsMobilityBase::initialize(stage);
00040
00041 EV << "initializing ANSimMobility stage " << stage << endl;
00042
00043 if (stage == 1)
00044 {
00045 nodeId = par("nodeId");
00046 if (nodeId == -1)
00047 nodeId = parentModule()->index();
00048
00049 // get script: param should point to <simulation> element
00050 cXMLElement *rootElem = par("ansimTrace");
00051 if (strcmp(rootElem->getTagName(),"simulation")!=0)
00052 error("ansimTrace: <simulation> is expected as root element not <%s> at %s",
00053 rootElem->getTagName(), rootElem->getSourceLocation());
00054 nextPosChange = rootElem->getElementByPath("mobility/position_change");
00055 if (!nextPosChange)
00056 error("element doesn't have <mobility> child or <position_change> grandchild at %s",
00057 rootElem->getSourceLocation());
00058
00059 // set initial position;
00060 setTargetPosition();
00061 pos = targetPos;
00062 updatePosition();
00063 }
00064 }
|
|
|
Overridden from LineSegmentsMobilityBase.
Implements LineSegmentsMobilityBase. 00068 {
00069 // find next <position_update> element with matching <node_id> tag (current one also OK)
00070 while (nextPosChange)
00071 {
00072 const char *nodeIdStr = firstChildWithTag(nextPosChange, "node_id")->getNodeValue();
00073 if (nodeIdStr && atoi(nodeIdStr)==nodeId)
00074 break;
00075 nextPosChange = nextPosChange->getNextSibling();
00076 }
00077
00078 if (!nextPosChange)
00079 {
00080 stationary = true;
00081 return;
00082 }
00083
00084 // extract data from it
00085 extractDataFrom(nextPosChange);
00086
00087 // skip this one
00088 nextPosChange = nextPosChange->getNextSibling();
00089 }
|
|
|
points to the next <position_change> element
|
|
|
we'll have to compare this to the <node_id> elements
|
1.4.1