📄 proc.pr.c
字号:
/* Process model C form file: Proc.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 Proc_pr_c [] = "MIL_3_Tfile_Hdr_ 90A 30A modeler 7 3FC4E672 3FC4E672 1 juventus pdm106 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 */
#include <math.h>
#define PRINT_INIT
#define PRINT_SRC_ARVL
#define PRINT_SENSE
#define PRINT_TX
#define PRINT_ROB
#define PRINT_RX_ARVL
#define SRC_QUEUE 1
#define PROC_INT 1
#define TX_STRM 0
#define RX_STRM 0
#define SRC_STRM 1
#define RX_ARVL ( (op_intrpt_type() == OPC_INTRPT_STRM) && (op_intrpt_code() == RX_STRM) )
#define SRC_ARVL ( (op_intrpt_type() == OPC_INTRPT_STRM) && (op_intrpt_code() == SRC_STRM) )
#define RTS_INT 1
#define CTS_INT 2
#define ACK_INT 3
#define DATA_INT 4
#define VCS_BUSY_INT 5
#define VCS_FREE_INT 6
#define ROB_INT 7
#define TEST_INT 8
#define RTS ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == RTS_INT) )
#define CTS ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == CTS_INT) )
#define ACK ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == ACK_INT) )
#define DATA ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == DATA_INT) )
#define VCS_busy ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == VCS_BUSY_INT) )
#define VCS_free ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == VCS_FREE_INT) )
#define ROB ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == ROB_INT) )
#define TEST ( (op_intrpt_type() == OPC_INTRPT_SELF) && (op_intrpt_code() == TEST_INT) )
#define PCS (op_intrpt_type() == OPC_INTRPT_STAT)
#define END (op_intrpt_type() == OPC_INTRPT_ENDSIM)
/* 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 */
double tx_range;
double rx_range;
Objid proc_id;
Objid node_id;
char nodename[20];
int userid;
Objid subnet_id;
double xpos;
double ypos;
int numnodes;
Objid tx_id;
Objid txcomp_id;
Objid txch_id;
double difs;
double sifs;
Objid rx_id;
Objid rxcomp_id;
Objid rxch_id;
int pcs_state;
int vcs_state;
int inprogress;
double vcs_duration;
Evhandle chfreeint;
Evhandle nexttxevent;
int txcode;
Evhandle robevent;
int txreq;
double rob;
Objid srcobjid;
Prohandle srcprohandle;
} Proc_state;
#define pr_state_ptr ((Proc_state*) SimI_Mod_State_Ptr)
#define tx_range pr_state_ptr->tx_range
#define rx_range pr_state_ptr->rx_range
#define proc_id pr_state_ptr->proc_id
#define node_id pr_state_ptr->node_id
#define nodename pr_state_ptr->nodename
#define userid pr_state_ptr->userid
#define subnet_id pr_state_ptr->subnet_id
#define xpos pr_state_ptr->xpos
#define ypos pr_state_ptr->ypos
#define numnodes pr_state_ptr->numnodes
#define tx_id pr_state_ptr->tx_id
#define txcomp_id pr_state_ptr->txcomp_id
#define txch_id pr_state_ptr->txch_id
#define difs pr_state_ptr->difs
#define sifs pr_state_ptr->sifs
#define rx_id pr_state_ptr->rx_id
#define rxcomp_id pr_state_ptr->rxcomp_id
#define rxch_id pr_state_ptr->rxch_id
#define pcs_state pr_state_ptr->pcs_state
#define vcs_state pr_state_ptr->vcs_state
#define inprogress pr_state_ptr->inprogress
#define vcs_duration pr_state_ptr->vcs_duration
#define chfreeint pr_state_ptr->chfreeint
#define nexttxevent pr_state_ptr->nexttxevent
#define txcode pr_state_ptr->txcode
#define robevent pr_state_ptr->robevent
#define txreq pr_state_ptr->txreq
#define rob pr_state_ptr->rob
#define srcobjid pr_state_ptr->srcobjid
#define srcprohandle pr_state_ptr->srcprohandle
/* 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 Proc_state *op_sv_ptr = pr_state_ptr;
/* No Function Block */
enum { _block_origin = __LINE__ };
/* 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 Proc (void);
Compcode Proc_init (void **);
void Proc_diag (void);
void Proc_terminate (void);
void Proc_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
Proc (void)
{
int _block_origin = 0;
FIN (Proc ());
if (1)
{
int namelength = 0;
int i = 0;
int i_temp = 0;
int nodenum = 0;
int tempint = 0;
int tempint2 = 0;
Objid other_node_id;
double other_xpos = 0.0;
double other_ypos = 0.0;
double distance = 0.0;
double tempdouble = 0.0;
Objid other_proc_id;
Objid other_rx_id;
Objid other_rxcomp_id;
Objid other_rxch_id;
int numreceivers = 0;
Objid *receivers;
Packet *pktptr;
Packet *origpktptr;
char pktname[20];
int srcid;
int destid;
FSM_ENTER (Proc)
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (INIT) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "INIT", "Proc [INIT enter execs]")
FSM_PROFILE_SECTION_IN ("Proc [INIT enter execs]", state0_enter_exec)
{
/*Initialise Variables*/
userid = 0;
numnodes = 0;
inprogress = 0;
pcs_state = 0;
vcs_state = 0;
txcode = 0;
txreq = 0;
tx_range = 0.0;
rx_range = 0.0;
xpos = 0.0;
ypos = 0.0;
difs = 0.0;
sifs = 0.0;
vcs_duration = 0.0;
rob = -1.0;
/*Read in the simulation attributes*/
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "DIFS", &difs);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "SIFS", &sifs);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "tx_range", &tx_range);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "rx_range", &rx_range);
/*Obtain the required object ID's for this node*/
proc_id = op_id_self();
node_id = op_topo_parent(proc_id);
subnet_id = op_topo_parent(node_id);
tx_id = op_topo_assoc(proc_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_RATX, 0);
txcomp_id = op_topo_child(tx_id, OPC_OBJTYPE_COMP, 0);
txch_id = op_topo_child(txcomp_id, OPC_OBJTYPE_RATXCH, 0);
rx_id = op_topo_assoc(proc_id, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);
rxcomp_id = op_topo_child(rx_id, OPC_OBJTYPE_COMP, 0);
rxch_id = op_topo_child(rxcomp_id, OPC_OBJTYPE_RARXCH, 0);
/****************************************************************************************/
/*Derive the appropriate user ID from the node name and set the user ID object attribute*/
/****************************************************************************************/
/*Read the node name into a string*/
op_ima_obj_attr_get(node_id, "name", &nodename);
/*Extract the numerical part of the node name*/
namelength = strlen(nodename);
for(i=12; i<=namelength; i++)
{
i_temp = nodename[i];
i_temp = i_temp - '0';
if(i_temp >=0)
nodenum = 10*nodenum + i_temp;
}
/*Set the user ID object attribute*/
userid = nodenum;
op_ima_obj_attr_set(node_id, "user id", userid);
#ifdef PRINT_INIT
printf("INIT STATE - ENTER EXECS\n");
printf("Difs = %lf\n", difs);
printf("Sifs = %lf\n", sifs);
printf("Transmission Range = %lf\n", tx_range);
printf("Receiving Range = %lf\n", rx_range);
printf("Node Name = %s\n", nodename);
op_ima_obj_attr_get(node_id, "user id", &tempint);
printf("Object Attribute User ID = %d\n", tempint);
#endif
/*Schedule an interrupt to carry out the rest of the initialisation once all user IDs have been set*/
op_intrpt_schedule_self(op_sim_time(), 0);
/*Get a handle to the root process model of the packet generator*/
srcobjid = op_id_from_name(node_id, OPC_OBJTYPE_PROC, "SRC");
srcprohandle = op_pro_root(srcobjid);
/*Schedule an interrupt to carry out the initialisation of the packet generator once all user IDs have been set*/
op_intrpt_schedule_process(srcprohandle, op_sim_time(), PROC_INT);
}
FSM_PROFILE_SECTION_OUT ("Proc [INIT enter execs]", state0_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,Proc)
/** state (INIT) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, "INIT", "Proc [INIT exit execs]")
FSM_PROFILE_SECTION_IN ("Proc [INIT exit execs]", state0_exit_exec)
{
/*********************************************************************************************/
/*Determine the receiving range of the nodes and hence determine which nodes are within */
/*communications range. Set the receiver group as appropriate. */
/*********************************************************************************************/
/*Determine the number of mobile nodes*/
numnodes = op_topo_object_count(OPC_OBJTYPE_NDMOB);
/*Determine the location of this node*/
op_ima_obj_attr_get(node_id, "x position", &xpos);
op_ima_obj_attr_get(node_id, "y position", &ypos);
for(i=0;i<numnodes;i++)
{
/*Get the object ID of a node in the subnet*/
other_node_id = op_topo_child(subnet_id, OPC_OBJTYPE_NDMOB, i);
/*Determine the location of the another node*/
op_ima_obj_attr_get(other_node_id, "x position", &other_xpos);
op_ima_obj_attr_get(other_node_id, "y position", &other_ypos);
/*Work out the distance between nodes*/
distance = sqrt((other_xpos - xpos)*(other_xpos - xpos) + (other_ypos - ypos)*(other_ypos - ypos));
/*Add them to the receiver group if they are within receiving range*/
if(distance < rx_range)
{
/*Get the object ID of the other nodes receiver channel*/
other_proc_id = op_topo_child(other_node_id, OPC_OBJTYPE_QUEUE, 0);
other_rx_id = op_topo_assoc(other_proc_id, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);
other_rxcomp_id = op_topo_child(other_rx_id, OPC_OBJTYPE_COMP, 0);
other_rxch_id = op_topo_child(other_rxcomp_id, OPC_OBJTYPE_RARXCH, 0);
/*Add the node to the receiver group of this transmitter*/
op_radio_txch_rxch_add(txch_id, other_rxch_id);
}
}
#ifdef PRINT_INIT
printf("INIT STATE - EXIT EXECS\n");
printf("Number of Mobile Nodes = %d\n", numnodes);
printf("Obtaining Information On The Receiver Group\n");
op_radio_txch_rxgroup_get(txch_id, &numreceivers, &receivers);
printf("Number of Receivers = %d\n", numreceivers);
for(i=0;i<numreceivers;i++)
{
op_ima_obj_attr_get(op_topo_parent(op_topo_assoc(op_topo_parent(op_topo_parent(receivers[i])), OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_QUEUE, 0)), "user id", &tempint);
printf("Receiver User ID = %d\n", tempint);
}
#endif
}
FSM_PROFILE_SECTION_OUT ("Proc [INIT exit execs]", state0_exit_exec)
/** state (INIT) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "INIT", "WAIT")
/*---------------------------------------------------------*/
/** state (WAIT) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, state1_enter_exec, "WAIT", "Proc [WAIT enter execs]")
FSM_PROFILE_SECTION_IN ("Proc [WAIT enter execs]", state1_enter_exec)
{
}
FSM_PROFILE_SECTION_OUT ("Proc [WAIT enter execs]", state1_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,Proc)
/** state (WAIT) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "WAIT", "Proc [WAIT exit execs]")
FSM_PROFILE_SECTION_IN ("Proc [WAIT exit execs]", state1_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT ("Proc [WAIT exit execs]", state1_exit_exec)
/** state (WAIT) transition processing **/
FSM_PROFILE_SECTION_IN ("Proc [WAIT trans conditions]", state1_trans_conds)
FSM_INIT_COND (TEST)
FSM_TEST_COND (SRC_ARVL)
FSM_TEST_COND (CTS)
FSM_TEST_COND (RTS)
FSM_TEST_COND (DATA)
FSM_TEST_COND (ACK)
FSM_TEST_COND (PCS)
FSM_TEST_COND (RX_ARVL)
FSM_TEST_COND (VCS_busy)
FSM_TEST_COND (VCS_free)
FSM_TEST_COND (ROB)
FSM_TEST_LOGIC ("WAIT")
FSM_PROFILE_SECTION_OUT ("Proc [WAIT trans conditions]", state1_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "TEST", "", "WAIT", "TEST")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "SRC_ARVL", "", "WAIT", "SRC_ARVL")
FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "CTS", "", "WAIT", "TX")
FSM_CASE_TRANSIT (3, 4, state4_enter_exec, ;, "RTS", "", "WAIT", "TX")
FSM_CASE_TRANSIT (4, 4, state4_enter_exec, ;, "DATA", "", "WAIT", "TX")
FSM_CASE_TRANSIT (5, 4, state4_enter_exec, ;, "ACK", "", "WAIT", "TX")
FSM_CASE_TRANSIT (6, 5, state5_enter_exec, ;, "PCS", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (7, 6, state6_enter_exec, ;, "RX_ARVL", "", "WAIT", "RX_ARVL")
FSM_CASE_TRANSIT (8, 5, state5_enter_exec, ;, "VCS_busy", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (9, 5, state5_enter_exec, ;, "VCS_free", "", "WAIT", "SENSE")
FSM_CASE_TRANSIT (10, 7, state7_enter_exec, ;, "ROB", "", "WAIT", "ROB")
}
/*---------------------------------------------------------*/
/** state (TEST) enter executives **/
FSM_STATE_ENTER_FORCED (2, state2_enter_exec, "TEST", "Proc [TEST enter execs]")
FSM_PROFILE_SECTION_IN ("Proc [TEST enter execs]", state2_enter_exec)
{
/*Create an RTS packet*/
pktptr = op_pk_create_fmt("RTS_pkt");
/*set the appropriate size of the packet*/
op_pk_total_size_set(pktptr, 160);
/*Set the fields of the RTS packet*/
op_pk_nfd_set(pktptr, "SRC", 3);
//TEMPORARY FOR NOW
op_pk_nfd_set(pktptr, "DEST", 3);
//TEMPORARY FOR NOW
op_pk_nfd_set(pktptr, "DURATION", 3.0);
/*Transmit the packet*/
op_pk_send(pktptr, TX_STRM);
}
FSM_PROFILE_SECTION_OUT ("Proc [TEST enter execs]", state2_enter_exec)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -