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

📄 sat_rx.pr.c

📁 基于OPNET的卫星通信程序
💻 C
字号:
/* Process model C form file: sat_rx.pr.c */
/* Portions of this file copyright 1992-2002 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
static const char sat_rx_pr_c [] = "MIL_3_Tfile_Hdr_ 90A 30A modeler 7 433F9DBD 433F9DBD 1 pc50290 atk016000 0 0 none none 0 0 none 0 0 0 0 0 0                                                                                                                                                                                                                                                                                                                                                                                                                    ";
#include <string.h>



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

#if defined (__cplusplus)
extern "C" {
#endif
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif


/* Header Block */

/* Input stream from bus receiver */
#define IN_STRM	   0
/* Conditional macros */
#define PKT_RCVD (op_intrpt_type() == OPC_INTRPT_STRM)
#define END_SIM  (op_intrpt_type() == OPC_INTRPT_ENDSIM)
/* Global variables */
int subm_pkts =0;

/* End of Header Block */


#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(last_line_passed) = __LINE__ - _block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(last_line_passed) = 0; _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 */
	int	                    		rcvd_pkts;
	int	                    		efreercvd_pkts;
	double	                 		data_rate;
	int	                    		pklen;
	int	                    		numberoferrors;
	int	                    		totalnumberoferrors;
	double	                 		loadfactor;
	} sat_rx_state;

#define pr_state_ptr            		((sat_rx_state*) SimI_Mod_State_Ptr)
#define rcvd_pkts               		pr_state_ptr->rcvd_pkts
#define efreercvd_pkts          		pr_state_ptr->efreercvd_pkts
#define data_rate               		pr_state_ptr->data_rate
#define pklen                   		pr_state_ptr->pklen
#define numberoferrors          		pr_state_ptr->numberoferrors
#define totalnumberoferrors     		pr_state_ptr->totalnumberoferrors
#define loadfactor              		pr_state_ptr->loadfactor

/* This macro definition 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
#define FIN_PREAMBLE	sat_rx_state *op_sv_ptr = pr_state_ptr;


/* Function Block */

enum { _block_origin = __LINE__ };
/* This function gets the received packet, destroys it, */
/* and then logs the incremented correctly received packet total */
/* and stores the Offered Load G and Throughput S.*/
void proc_pkt ()
	{
	
	Packet* in_pkt;
	
	/* Get packet from bus receiver input stream */
	in_pkt = op_pk_get (IN_STRM);
	
	/* Get packet data rate*/
	data_rate=op_td_get_dbl (in_pkt, OPC_TDA_RA_RX_DRATE);
	
	/* Get packet length*/
	pklen = op_pk_total_size_get (in_pkt);
	
	/* Get packet Load_Factor*/
	loadfactor=1;
	//loadfactor=op_td_get_dbl (in_pkt, OPC_TDA_RA_MAX_INDEX+2);
	
	/* Get number of errors in each packet*/
	numberoferrors=op_td_get_int (in_pkt, OPC_TDA_RA_NUM_ERRORS);

	/* Accumulate number of errors*/
	totalnumberoferrors=totalnumberoferrors+numberoferrors;
	
	/*Find the number of error free packets*/
	if (numberoferrors == 0)
		{
		++efreercvd_pkts;
		}
	
	/* Destroy the received packet */
	op_pk_destroy (in_pkt);
	
	/* Increment the count of received packets */
	++rcvd_pkts;
		}

/*This fucntion writes the end-of-simulation channel traffic and */
/*and  channel throughput statistics*/
void record_stats()
	{
	
	/* Record final statistics */
	op_stat_scalar_write("Channel Traffic G",(double) loadfactor*(pklen / data_rate)*rcvd_pkts /op_sim_time());
	op_stat_scalar_write("Channel Throuhput S",(double) loadfactor*(pklen / data_rate)*efreercvd_pkts /op_sim_time());
	op_stat_scalar_write("# of total received packets",(int) rcvd_pkts);
	op_stat_scalar_write("# of transmitted packets",(int) subm_pkts);
	op_stat_scalar_write("# of total error free receieved packets",(int) efreercvd_pkts);
	op_stat_scalar_write("BER",(double) totalnumberoferrors / (pklen*rcvd_pkts));
	op_stat_scalar_write("PER",(double) (rcvd_pkts-efreercvd_pkts) / rcvd_pkts);
	}

/* End of Function Block */

/* 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 sat_rx (void);
	Compcode sat_rx_init (void **);
	void sat_rx_diag (void);
	void sat_rx_terminate (void);
	void sat_rx_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
sat_rx (void)
	{
	int _block_origin = 0;
	FIN (sat_rx ());
	if (1)
		{


		FSM_ENTER (sat_rx)

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "sat_rx [init enter execs]")
				FSM_PROFILE_SECTION_IN ("sat_rx [init enter execs]", state0_enter_exec)
				{
				
				/* Initialize accumulator*/
				rcvd_pkts = 0;
				efreercvd_pkts = 0;
				numberoferrors = 0;
				
				}

				FSM_PROFILE_SECTION_OUT ("sat_rx [init enter execs]", state0_enter_exec)

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


			/** state (init) transition processing **/
			FSM_PROFILE_SECTION_IN ("sat_rx [init trans conditions]", state0_trans_conds)
			FSM_INIT_COND (PKT_RCVD)
			FSM_TEST_COND (END_SIM)
			FSM_TEST_LOGIC ("init")
			FSM_PROFILE_SECTION_OUT ("sat_rx [init trans conditions]", state0_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, proc_pkt();, "PKT_RCVD", "proc_pkt()", "init", "idle")
				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, record_stats();, "END_SIM", "record_stats()", "init", "idle")
				}
				/*---------------------------------------------------------*/



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

				FSM_PROFILE_SECTION_OUT ("sat_rx [idle enter execs]", state1_enter_exec)

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


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


			/** state (idle) transition processing **/
			FSM_PROFILE_SECTION_IN ("sat_rx [idle trans conditions]", state1_trans_conds)
			FSM_INIT_COND (PKT_RCVD)
			FSM_TEST_COND (END_SIM)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")
			FSM_PROFILE_SECTION_OUT ("sat_rx [idle trans conditions]", state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, proc_pkt();, "PKT_RCVD", "proc_pkt()", "idle", "idle")
				FSM_CASE_TRANSIT (1, 1, state1_enter_exec, record_stats();, "END_SIM", "record_stats()", "idle", "idle")
				FSM_CASE_TRANSIT (2, 1, state1_enter_exec, ;, "default", "", "idle", "idle")
				}
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,sat_rx)
		}
	}

#if defined (__cplusplus)
	extern "C" { 
#endif
	extern VosT_Fun_Status Vos_Catmem_Register (const char * , int , VosT_Void_Null_Proc, VosT_Address *);
	extern VosT_Address Vos_Catmem_Alloc (VosT_Address, size_t);
	extern VosT_Fun_Status Vos_Catmem_Dealloc (VosT_Address);
#if defined (__cplusplus)
	}
#endif


Compcode
sat_rx_init (void ** gen_state_pptr)
	{
	int _block_origin = 0;
	static VosT_Address	obtype = OPC_NIL;

	FIN (sat_rx_init (gen_state_pptr))

	if (obtype == OPC_NIL)
		{
		/* Initialize memory management */
		if (Vos_Catmem_Register ("proc state vars (sat_rx)",
			sizeof (sat_rx_state), Vos_Vnop, &obtype) == VOSC_FAILURE)
			{
			FRET (OPC_COMPCODE_FAILURE)
			}
		}

	*gen_state_pptr = Vos_Catmem_Alloc (obtype, 1);
	if (*gen_state_pptr == OPC_NIL)
		{
		FRET (OPC_COMPCODE_FAILURE)
		}
	else
		{
		/* Initialize FSM handling */
		((sat_rx_state *)(*gen_state_pptr))->current_block = 0;

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



void
sat_rx_diag (void)
	{
	/* No Diagnostic Block */
	}




void
sat_rx_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (sat_rx_terminate (void))

	Vos_Catmem_Dealloc (pr_state_ptr);

	FOUT
	}


/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in sat_rx_svar function. */
#undef rcvd_pkts
#undef efreercvd_pkts
#undef data_rate
#undef pklen
#undef numberoferrors
#undef totalnumberoferrors
#undef loadfactor



void
sat_rx_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{
	sat_rx_state		*prs_ptr;

	FIN (sat_rx_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (char *)OPC_NIL;
		FOUT
		}
	prs_ptr = (sat_rx_state *)gen_ptr;

	if (strcmp ("rcvd_pkts" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rcvd_pkts);
		FOUT
		}
	if (strcmp ("efreercvd_pkts" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->efreercvd_pkts);
		FOUT
		}
	if (strcmp ("data_rate" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->data_rate);
		FOUT
		}
	if (strcmp ("pklen" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->pklen);
		FOUT
		}
	if (strcmp ("numberoferrors" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->numberoferrors);
		FOUT
		}
	if (strcmp ("totalnumberoferrors" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->totalnumberoferrors);
		FOUT
		}
	if (strcmp ("loadfactor" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->loadfactor);
		FOUT
		}
	*var_p_ptr = (char *)OPC_NIL;

	FOUT
	}

⌨️ 快捷键说明

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