对于状态变量和全局变量,是整个项目可见的,这点可以参照C语言编程中的全局变量和局部变量的概念。
C语言 | opnet |
|
对应关系 |
全局变量 |
状态变量和全局变量 |
对应关系 | 局部变量 |
临时变量 |
三、案例分析
一个进程模型的部份源代码:
void
csma_tx (OP_SIM_CONTEXT_ARG_OPT)
{
....//其它代码
FIN_MT (csma_tx ());
{
/* Temporary Variables */
Boolean state_reentered = OPC_FALSE;
/* End of Temporary Variables */
FSM_ENTER ("csma_tx")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "csma_tx [init enter execs]")
FSM_PROFILE_SECTION_IN ("csma_tx [init enter execs]", state0_enter_exec)
{
op_ima_sim_attr_get_int32("max packet count", &max_packet_count);
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** state (init) exit executives **/
FSM_STATE_EXIT_FORCED (0, "init", "csma_tx [init exit execs]")
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "init", "idle", "tr_0", "csma_tx [init -> idle : default / ]")
/*---------------------------------------------------------*/
/** state (idle) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "idle", state1_enter_exec, "csma_tx [idle enter execs]")
FSM_PROFILE_SECTION_IN ("csma_tx [idle enter execs]", state1_enter_exec)
{
if(state_reentered == OPC_FALSE)
{
printf("进入状态\n");
op_intrpt_schedule_self(op_sim_time() + 0.0001, 1);
}
else
{
printf("这个是次重入过程\n");
}
}
FSM_PROFILE_SECTION_OUT (state1_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"csma_tx")//离开进程函数
/** state (idle) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "idle", "csma_tx [idle exit execs]")
FSM_PROFILE_SECTION_IN ("csma_tx [idle exit execs]", state1_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state1_exit_exec)
/** state (idle) transition processing **/
FSM_PROFILE_SECTION_IN ("csma_tx [idle trans conditions]", state1_trans_conds)
FSM_INIT_COND (PKT_ARVL && FREE)
FSM_TEST_COND (PKT_ARVL && !FREE)
FSM_DFLT_COND
FSM_TEST_LOGIC ("idle")
FSM_PROFILE_SECTION_OUT (state1_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, print_power_channelidle();, "PKT_ARVL && FREE", "print_power_channelidle()", "idle", "tx_pkt", "tr_1", "csma_tx [idle -> tx_pkt : PKT_ARVL && FREE / print_power_channelidle()]")
FSM_CASE_TRANSIT (1, 3, state3_enter_exec, print_power_channelbusy();, "PKT_ARVL && !FREE", "print_power_channelbusy()", "idle", "wait_free", "tr_8", "csma_tx [idle -> wait_free : PKT_ARVL && !FREE / print_power_channelbusy()]")
FSM_CASE_TRANSIT (2, 1, state1_enter_exec, SET_REENTRY;, "default", "SET_REENTRY", "idle", "idle", "tr_3", "csma_tx [idle -> idle : default / SET_REENTRY]")
}
/*---------------------------------------------------------*/
....//其它代码
}
FSM_EXIT (0,"csma_tx")
}
强制状态离开宏,设置离开后的下一个状态2 * sn + 1
非强制状态离开宏,设置离开后的下一个状态2 * sn + 1