00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class MobileNode;
00047
00048 #ifndef __ns_mobilenode_h__
00049 #define __ns_mobilenode_h__
00050
00051 #define MN_POSITION_UPDATE_INTERVAL 30.0 // seconds
00052 #define MAX_SPEED 5.0 // meters per second (33.55 mph)
00053 #define MIN_SPEED 0.0
00054
00055
00056 #include "object.h"
00057 #include "trace.h"
00058 #include "lib/bsd-list.h"
00059 #include "phy.h"
00060 #include "topography.h"
00061 #include "arp.h"
00062 #include "node.h"
00063 #include "gridkeeper.h"
00064 #include "energy-model.h"
00065 #include "location.h"
00066
00067
00068
00069 #if COMMENT_ONLY
00070 -----------------------
00071 | |
00072 | Upper Layers |
00073 | |
00074 -----------------------
00075 | |
00076 | |
00077 ------- -------
00078 | | | |
00079 | LL | | LL |
00080 | | | |
00081 ------- -------
00082 | |
00083 | |
00084 ------- -------
00085 | | | |
00086 | Queue | | Queue |
00087 | | | |
00088 ------- -------
00089 | |
00090 | |
00091 ------- -------
00092 | | | |
00093 | Mac | | Mac |
00094 | | | |
00095 ------- -------
00096 | |
00097 | |
00098 ------- ------- -----------------------
00099 | | | | | |
00100 | Netif | <--- | Netif | <--- | Mobile Node |
00101 | | | | | |
00102 ------- ------- -----------------------
00103 | |
00104 | |
00105 -----------------------
00106 | |
00107 | Channel(s) |
00108 | |
00109 -----------------------
00110 #endif
00111 class MobileNode;
00112
00113 class PositionHandler : public Handler {
00114 public:
00115 PositionHandler(MobileNode* n) : node(n) {}
00116 void handle(Event*);
00117 private:
00118 MobileNode *node;
00119 };
00120
00121 class MobileNode : public Node
00122 {
00123 friend class PositionHandler;
00124 public:
00125 MobileNode();
00126 virtual int command(int argc, const char*const* argv);
00127
00128 double distance(MobileNode*);
00129 double propdelay(MobileNode*);
00130 void start(void);
00131 inline void getLoc(double *x, double *y, double *z) {
00132 update_position(); *x = X_; *y = Y_; *z = Z_;
00133 }
00134 inline void getVelo(double *dx, double *dy, double *dz) {
00135 *dx = dX_ * speed_; *dy = dY_ * speed_; *dz = 0.0;
00136 }
00137 inline MobileNode* nextnode() { return link_.le_next; }
00138 inline int base_stn() { return base_stn_;}
00139 inline void set_base_stn(int addr) { base_stn_ = addr; }
00140
00141 void dump(void);
00142
00143 inline MobileNode*& next() { return next_; }
00144 inline double X() { return X_; }
00145 inline double Y() { return Y_; }
00146 inline double Z() { return Z_; }
00147 inline double speed() { return speed_; }
00148 inline double dX() { return dX_; }
00149 inline double dY() { return dY_; }
00150 inline double dZ() { return dZ_; }
00151 inline double destX() { return destX_; }
00152 inline double destY() { return destY_; }
00153 inline double radius() { return radius_; }
00154 inline double getUpdateTime() { return position_update_time_; }
00155
00156
00157 void update_position();
00158 void log_energy(int);
00159
00160 virtual void idle_energy_patch(float, float);
00161
00162
00163 MobileNode* nextX_;
00164 MobileNode* prevX_;
00165
00166 protected:
00167
00168
00169
00170 double position_update_time_;
00171 double position_update_interval_;
00172
00173
00174
00175
00176
00177 double X_;
00178 double Y_;
00179 double Z_;
00180 double speed_;
00181
00182
00183
00184
00185
00186
00187 double dX_;
00188 double dY_;
00189 double dZ_;
00190
00191
00192 double destX_;
00193 double destY_;
00194
00195
00196
00197
00198 MobileNode* next_;
00199 double radius_;
00200
00201
00202 PositionHandler pos_handle_;
00203 Event pos_intr_;
00204
00205 void log_movement();
00206 void random_direction();
00207 void random_speed();
00208 void random_destination();
00209 int set_destination(double x, double y, double speed);
00210
00211 private:
00212 inline int initialized() {
00213 return (T_ && log_target_ &&
00214 X_ >= T_->lowerX() && X_ <= T_->upperX() &&
00215 Y_ >= T_->lowerY() && Y_ <= T_->upperY());
00216 }
00217 void random_position();
00218 void bound_position();
00219 int random_motion_;
00220
00221
00222
00223
00224 LIST_ENTRY(MobileNode) link_;
00225
00226
00227
00228
00229
00230 Topography *T_;
00231
00232
00233
00234 Trace* log_target_;
00235
00236
00237
00238 int base_stn_;
00239
00240
00241
00242 };
00243
00244 #endif // ns_mobilenode_h
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255