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

📄 billiard_mobility.pr.c

📁 在OPNET中实现AODV路由协议
💻 C
📖 第 1 页 / 共 2 页
字号:
				// calcul the new x and y position according to the STEP_DIST and the current direction (angle)
				x=x_pos+STEP_DIST*cos(angle);
				y=y_pos+STEP_DIST*sin(angle);
				
				// if the new x position is outside the network grid boundaries
				if ((x<XMIN)||(XMAX<x))
					{
					// if the new y position is also outside the network grid boundaries
					if ((y<YMIN)||(YMAX<y))
						{
						// come back to the previous position (on x and y)
						x=x_pos-STEP_DIST*cos(angle);
						y=y_pos-STEP_DIST*sin(angle);
						// and calculate a random new direction
						angle=op_dist_outcome(one)*PI;	
						}
					// if new y position are still in the network boundaries 
					else 
						{
						// come back to the previous position (only on x)
						x=x_pos-STEP_DIST*cos(angle);
						// and calculate a random new direction
						angle=op_dist_outcome(one)*PI;
						}
					}
				
				// if only the new y position is outside (x and y outside handle before) the network boundaries 
				if ((y<YMIN)||(YMAX<y))
					{
					// come back to the previous position (only on y)
					y=y_pos-STEP_DIST*sin(angle);
					// and compute new direction
					angle=op_dist_outcome(one)*PI;
					}
				
				if(DEBUG > 1) printf("\n{{ node %d }} @ mobility : \n      > previous pos (%f,%f) <--> new position (%f,%f)\n      > direction %f\n",node_addr,x_pos,y_pos,x,y,angle);
				
				// set the new position of the node
				op_ima_obj_attr_set(node_id, "x position",x);
				op_ima_obj_attr_set(node_id, "y position",y);
				
				// schedule the interuption for the next movement (position updating)
				op_intrpt_schedule_self(op_sim_time()+POS_TIMER,0);
				
				}
				}

				FSM_PROFILE_SECTION_OUT (billiard_mobility [change_position enter execs], state2_enter_exec)

			/** state (change_position) exit executives **/
			FSM_STATE_EXIT_FORCED (2, "change_position", "billiard_mobility [change_position exit execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [change_position exit execs], state2_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (billiard_mobility [change_position exit execs], state2_exit_exec)


			/** state (change_position) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "change_position", "idle")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,"billiard_mobility")
		}
	}




void
billiard_mobility_diag (OP_SIM_CONTEXT_ARG_OPT)
	{
	/* No Diagnostic Block */
	}




void
billiard_mobility_terminate (OP_SIM_CONTEXT_ARG_OPT)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = __LINE__;
#endif

	FIN_MT (billiard_mobility_terminate ())

	Vos_Poolmem_Dealloc_MT (OP_SIM_CONTEXT_THREAD_INDEX_COMMA pr_state_ptr);

	FOUT
	}


/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in billiard_mobility_svar function. */
#undef one
#undef node_id
#undef POS_TIMER
#undef STEP_DIST
#undef process_id
#undef angle
#undef abs
#undef ord
#undef net_id
#undef MOBILE
#undef XMAX
#undef XMIN
#undef YMAX
#undef YMIN
#undef DEBUG
#undef node_addr

#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE

#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE

VosT_Obtype
billiard_mobility_init (int * init_block_ptr)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	VosT_Obtype obtype = OPC_NIL;
	FIN_MT (billiard_mobility_init (init_block_ptr))

	Vos_Define_Object (&obtype, "proc state vars (billiard_mobility)",
		sizeof (billiard_mobility_state), 0, 20);
	*init_block_ptr = 0;

	FRET (obtype)
	}

VosT_Address
billiard_mobility_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype obtype, int init_block)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	billiard_mobility_state * ptr;
	FIN_MT (billiard_mobility_alloc (obtype))

	ptr = (billiard_mobility_state *)Vos_Alloc_Object_MT (VOS_THREAD_INDEX_COMMA obtype);
	if (ptr != OPC_NIL)
		ptr->_op_current_block = init_block;
	FRET ((VosT_Address)ptr)
	}



void
billiard_mobility_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
	{
	billiard_mobility_state		*prs_ptr;

	FIN_MT (billiard_mobility_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (void *)OPC_NIL;
		FOUT
		}
	prs_ptr = (billiard_mobility_state *)gen_ptr;

	if (strcmp ("one" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->one);
		FOUT
		}
	if (strcmp ("node_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->node_id);
		FOUT
		}
	if (strcmp ("POS_TIMER" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->POS_TIMER);
		FOUT
		}
	if (strcmp ("STEP_DIST" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->STEP_DIST);
		FOUT
		}
	if (strcmp ("process_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->process_id);
		FOUT
		}
	if (strcmp ("angle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->angle);
		FOUT
		}
	if (strcmp ("abs" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->abs);
		FOUT
		}
	if (strcmp ("ord" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->ord);
		FOUT
		}
	if (strcmp ("net_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->net_id);
		FOUT
		}
	if (strcmp ("MOBILE" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->MOBILE);
		FOUT
		}
	if (strcmp ("XMAX" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->XMAX);
		FOUT
		}
	if (strcmp ("XMIN" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->XMIN);
		FOUT
		}
	if (strcmp ("YMAX" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->YMAX);
		FOUT
		}
	if (strcmp ("YMIN" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->YMIN);
		FOUT
		}
	if (strcmp ("DEBUG" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->DEBUG);
		FOUT
		}
	if (strcmp ("node_addr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->node_addr);
		FOUT
		}
	*var_p_ptr = (void *)OPC_NIL;

	FOUT
	}

⌨️ 快捷键说明

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