⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macros.h

📁 WSN仿真一例假定节点0(node[0])周期性广播消息其它节点接收到消息并转发出去
💻 H
字号:
//-------------------------------------------------------------------//  file name: macros.h// //    - macros available within a sensor node are defined here////-------------------------------------------------------------------/** * @name Node ID * @ingroup group_macros *///@{/**- macro that returns a node's ID (value ranges from 0 to NNODES-1) * * @hideinitializer */#define ID (int)parentModule()->index()//@}/** * @name Graphics Related Macros * @ingroup group_macros *///@{// /**- macro that returns the color of a node (int value) *- the value actually used is COLOR%MAXCOLOR   * * @hideinitializer */#define COLOR (int)(parentModule()->par("COLOR"))/**- macro that returns the number of the graphical symbol used to display a node (int value) *- the value actually used is KIND%MAXKIND  * * @hideinitializer */#define KIND  (int)(parentModule()->par("KIND"))// problems with using blackboard for the general parameters: //#define COLOR *(int*)((blackboard*)this->parentModule()->submodule("sm_blackboard"))->lookupParam("gv_color")//#define KIND  *(int*)((blackboard*)this->parentModule()->submodule("sm_blackboard"))->lookupParam("gv_kind")/**- macro that updates the color of a node *- the value actually used is COLOR%MAXCOLOR  * * @hideinitializer */#define UPDATECOLOR(color) {\	parentModule()->par("COLOR") = color;													\	char tempstring[30];																			\	sprintf(tempstring,"p=%d,%d,exact;i=snode_%d_%d",PX+MX,PY+MY,COLOR % MAXCOLOR,KIND % MAXKIND);	\	parentModule()->setDisplayString(tempstring);											}/**- macro that updates the kind of a node *- the value actually used is KIND%MAXKIND  * * @hideinitializer */#define UPDATEKIND(kind) {\	parentModule()->par("KIND") = kind;														\	char tempstring[30];																			\	sprintf(tempstring,"p=%d,%d,exact;i=snode_%d_%d",PX+MX,PY+MY,COLOR % MAXCOLOR,kind % MAXKIND);	\	parentModule()->setDisplayString(tempstring);											}/**- macro that updates both the color and the kind of a node *- values actually used are: COLOR%MAXCOLOR, KIND%MAXKIND  * * @hideinitializer */#define UPDATEGRAPHICS(color,kind) {\	parentModule()->par("COLOR") = color;													\	parentModule()->par("KIND") = kind;														\	char tempstring[30];																			\	sprintf(tempstring,"p=%d,%d,exact;i=snode_%d_%d",PX+MX,PY+MY,COLOR % MAXCOLOR,KIND % MAXKIND);	\	parentModule()->setDisplayString(tempstring);											}/**- macro that refreshes the image and position of a node *- slow execution speed  * * @hideinitializer */#define REFRESHIMAGE {\	char tempstring[30];																			\	sprintf(tempstring,"p=%d,%d,exact;i=snode_%d_%d",PX+MX,PY+MY,COLOR % MAXCOLOR,KIND % MAXKIND);	\	parentModule()->setDisplayString(tempstring);											}//@}/** * @name Current Node Position * @ingroup group_macros *///@{/**- current X position  * * @hideinitializer */#define PX (int)parentModule()->par("PX")/**- current Y position  * * @hideinitializer */#define PY (int)parentModule()->par("PY")//@}/** * @name Signal Strength * @ingroup group_macros *///@{/**- macro that returns the current signal strength of a node  * * @hideinitializer */#define SSTRENGTH (int)(parentModule()->par("sstrength"))/**- macro that updates the signal strength of a node *- it produces re-computations of the current node's neighbors *- expect slow execution when using it often  * * @hideinitializer */#define UPDATESSTRENGTH(sstrength) {\ };//@}/** * @name Energy Related Macros * @ingroup group_macros *///@{/**- macro that returns the current energy of a node *- it uses the blackboard, so do not use it in the initialize() function!  * * @hideinitializer */#define NRJ *(double *)lookup("gv_energy")/**- macro that returns the consumed energy of a node until the present time *- it uses the blackboard, so do not use it in the initialize() function!  * * @hideinitializer */#define NRJ_CONSUMED *(double *)lookup("gv_energyconsumed")/**- macro that substracts an amount of consumed energy *- it uses the blackboard, so do not use it in the initialize() function!  * * @hideinitializer */#define NRJ_CONSUME(nrj) {\  double energy = 0.0,energyconsumed = 0.0;			\  if (lookup("gv_energy")!=NULL)					\	  energy = NRJ;									\  if (lookup("gv_energyconsumed")!=NULL)			\	  energyconsumed = NRJ_CONSUMED;				\  publish("gv_energy",energy-nrj);					\  publish("gv_energyconsumed",energyconsumed+nrj);	}/**- macro that adds an amount of consumed energy *- it uses the blackboard, so do not use it in the initialize() function!  * * @hideinitializer */#define NRJ_ADD(nrj) {publish("gv_energy",NRJ+nrj);}/**- macro that gives a simple estimation of the remaining life time *- feel free to implement it as a more complex function inside the energy module *- it uses the blackboard, so do not use it in the initialize() function!  * * @hideinitializer */#define NRJ_LIFETIME (simtime_t)(simTime() * NRJ / NRJ_CONSUMED) //@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -