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

📄 billiard_mobility.pr.c

📁 opnet环境中实现aodv路由协议建模
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: billiard_mobility.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
const char billiard_mobility_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A modeler 7 43C50830 43C50830 1 wind Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 8f3 1                                                                                                                                                                                                                                                                                                                                                                                                        ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>



/* Header Block */

#include <math.h>

#define PI	 3.141592654

/* transition macro */
#define UPDATE ( op_intrpt_type () == OPC_INTRPT_SELF ) 

/* Mobility */
#define Disabled 0
#define Enabled 1

/* End of Header Block */


#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define	BINIT
#endif /* #if !defined (VOSD_NO_FIN) */



/* State variable definitions */
typedef struct
	{
	/* Internal state tracking for FSM */
	FSM_SYS_STATE
	/* State Variables */
	Distribution *	         		one;
	Objid	                  		node_id;
	double	                 		POS_TIMER;
	double	                 		STEP_DIST;
	Objid	                  		process_id;
	double	                 		angle;
	double	                 		abs;
	double	                 		ord;
	Objid	                  		net_id;
	int	                    		MOBILE;
	double	                 		XMAX;
	double	                 		XMIN;
	double	                 		YMAX;
	double	                 		YMIN;
	int	                    		DEBUG;
	int	                    		node_addr;
	} billiard_mobility_state;

#define pr_state_ptr            		((billiard_mobility_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define one                     		pr_state_ptr->one
#define node_id                 		pr_state_ptr->node_id
#define POS_TIMER               		pr_state_ptr->POS_TIMER
#define STEP_DIST               		pr_state_ptr->STEP_DIST
#define process_id              		pr_state_ptr->process_id
#define angle                   		pr_state_ptr->angle
#define abs                     		pr_state_ptr->abs
#define ord                     		pr_state_ptr->ord
#define net_id                  		pr_state_ptr->net_id
#define MOBILE                  		pr_state_ptr->MOBILE
#define XMAX                    		pr_state_ptr->XMAX
#define XMIN                    		pr_state_ptr->XMIN
#define YMAX                    		pr_state_ptr->YMAX
#define YMIN                    		pr_state_ptr->YMIN
#define DEBUG                   		pr_state_ptr->DEBUG
#define node_addr               		pr_state_ptr->node_addr

/* These macro definitions will define a local variable called	*/
/* "op_sv_ptr" in each function containing a FIN statement.	*/
/* This variable points to the state variable data structure,	*/
/* and can be used from a C debugger to display their values.	*/
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#if defined (OPD_PARALLEL)
#  define FIN_PREAMBLE_DEC	billiard_mobility_state *op_sv_ptr; OpT_Sim_Context * tcontext_ptr;
#  define FIN_PREAMBLE_CODE	\
		if (VosS_Mt_Perform_Lock) \
			VOS_THREAD_SPECIFIC_DATA_GET (VosI_Globals.simi_mt_context_data_key, tcontext_ptr, SimT_Context *); \
		else \
			tcontext_ptr = VosI_Globals.simi_sequential_context_ptr; \
		op_sv_ptr = ((billiard_mobility_state *)(tcontext_ptr->mod_state_ptr));
#else
#  define FIN_PREAMBLE_DEC	billiard_mobility_state *op_sv_ptr;
#  define FIN_PREAMBLE_CODE	op_sv_ptr = pr_state_ptr;
#endif


/* No Function Block */


#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif

/* Undefine optional tracing in FIN/FOUT/FRET */
/* The FSM has its own tracing code and the other */
/* functions should not have any tracing.		  */
#undef FIN_TRACING
#define FIN_TRACING

#undef FOUTRET_TRACING
#define FOUTRET_TRACING

#if defined (__cplusplus)
extern "C" {
#endif
	void billiard_mobility (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype billiard_mobility_init (int * init_block_ptr);
	VosT_Address billiard_mobility_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
	void billiard_mobility_diag (OP_SIM_CONTEXT_ARG_OPT);
	void billiard_mobility_terminate (OP_SIM_CONTEXT_ARG_OPT);
	void billiard_mobility_svar (void *, const char *, void **);


	VosT_Fun_Status Vos_Define_Object (VosT_Obtype * obst_ptr, const char * name, unsigned int size, unsigned int init_obs, unsigned int inc_obs);
	VosT_Address Vos_Alloc_Object_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype ob_hndl);
	VosT_Fun_Status Vos_Poolmem_Dealloc_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Address ob_ptr);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
billiard_mobility (OP_SIM_CONTEXT_ARG_OPT)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (billiard_mobility ());
	if (1)
		{
		double	altitude,latitude,longitude,rand, prev_angle,x,y,z,x_pos,y_pos,z_pos;
		Distribution * first_interval_dist;
		double  first_interval;


		FSM_ENTER ("billiard_mobility")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "billiard_mobility [init enter execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [init enter execs], state0_enter_exec)
				{
				// init Objids
				node_id = op_topo_parent (op_id_self());
				op_ima_obj_attr_get(node_id,"wlan_mac.station_address",&node_addr);
				process_id = op_id_self();
				net_id = op_topo_parent(node_id);
				
				// read different attributes
				op_ima_obj_attr_get(op_id_self(), "Mobility", &MOBILE);
				op_ima_obj_attr_get(node_id, "DEBUG", &DEBUG);
				op_ima_obj_attr_get(op_id_self(), "mobil_POS_TIMER", &POS_TIMER);
				op_ima_obj_attr_get(op_id_self(), "mobil_STEP_DIST", &STEP_DIST);
				op_ima_obj_attr_get(op_id_self(), "grid_XMIN", &XMIN);
				op_ima_obj_attr_get(op_id_self(), "grid_XMAX", &XMAX);
				op_ima_obj_attr_get(op_id_self(), "grid_YMIN", &YMIN);
				op_ima_obj_attr_get(op_id_self(), "grid_YMAX", &YMAX);
				
				// initialize distributions for random movement
				one = op_dist_load ("uniform", -1, 1);
				angle = op_dist_outcome (one) * PI;
				first_interval_dist = op_dist_load ("uniform_double", 0.0,POS_TIMER);
				first_interval = op_dist_outcome(first_interval_dist);
				// sechedule first interruption f
				op_intrpt_schedule_self(op_sim_time()+POS_TIMER+first_interval,0);
				
				
				}

				FSM_PROFILE_SECTION_OUT (billiard_mobility [init enter execs], state0_enter_exec)

			/** state (init) exit executives **/
			FSM_STATE_EXIT_FORCED (0, "init", "billiard_mobility [init exit execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [init exit execs], state0_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (billiard_mobility [init exit execs], state0_exit_exec)


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



			/** state (idle) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "billiard_mobility [idle enter execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [idle enter execs], state1_enter_exec)
				{
				}

				FSM_PROFILE_SECTION_OUT (billiard_mobility [idle enter execs], state1_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,"billiard_mobility")


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "idle", "billiard_mobility [idle exit execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [idle exit execs], state1_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (billiard_mobility [idle exit execs], state1_exit_exec)


			/** state (idle) transition processing **/
			FSM_PROFILE_SECTION_IN (billiard_mobility [idle trans conditions], state1_trans_conds)
			FSM_INIT_COND (UPDATE)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")
			FSM_PROFILE_SECTION_OUT (billiard_mobility [idle trans conditions], state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "UPDATE", "", "idle", "change_position")
				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, ;, "default", "", "idle", "idle")
				}
				/*---------------------------------------------------------*/



			/** state (change_position) enter executives **/
			FSM_STATE_ENTER_FORCED (2, "change_position", state2_enter_exec, "billiard_mobility [change_position enter execs]")
				FSM_PROFILE_SECTION_IN (billiard_mobility [change_position enter execs], state2_enter_exec)
				{
				if(MOBILE == Enabled)
				{
				// Get the current position of the node
				op_ima_obj_attr_get(node_id,"x position",&x_pos);
				op_ima_obj_attr_get(node_id,"y position",&y_pos);
				

⌨️ 快捷键说明

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