📄 ramimo_proc_chi.pr.c
字号:
#ifdef PACKET
printf("CHILD PROC\n");
printf("Transmitting a Data Packet from Node %d!\n", userid);
op_pk_nfd_get(pktptr, "SRC", &tempint);
printf("SRC Node = %d\n", tempint);
op_pk_nfd_get(pktptr, "DEST", &tempint);
printf("DEST Node = %d\n", tempint);
op_prg_odb_bkpt("PACKET");
#endif
}
/*If transmission of an ACK packet*/
else if(ACK)
{
/*Create an ACK packet*/
pktptr = op_pk_create_fmt("ACK_pkt");
/*set the appropriate size of the packet - An ACK packet is 14 bytes*/
op_pk_total_size_set(pktptr, ackpktsize);
/*Set the fields of the ACK packet*/
op_pk_nfd_set(pktptr, "SRC", userid);
op_pk_nfd_set(pktptr, "DEST", commnodeid);
op_pk_nfd_set(pktptr, "number", sequencenum);
#ifdef PRINT_TX
printf("CHILD PROC\n");
printf("Transmitting an ACK Packet\n");
printf("Packet Size = %d\n", op_pk_total_size_get(pktptr));
op_pk_nfd_get(pktptr, "SRC", &srcid);
printf("Packet Source = %d\n", srcid);
op_pk_nfd_get(pktptr, "DEST", &destid);
printf("Packet Destination = %d\n", destid);
op_pk_nfd_get(pktptr, "number", &tempdouble);
printf("Packet Sequence Number = %lf\n", tempdouble);
#endif
}
/*Reset the transmission required variable - now that the transmission is taking place*/
txreq = 0;
/*Reset the random backoff interval*/
rob = -1.0;
/*Transmit the packet*/
op_pk_send(pktptr, TX_STRM);
op_prg_odb_bkpt("TX");
op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (state4_enter_exec)
/** state (TX) exit executives **/
FSM_STATE_EXIT_FORCED (4, "TX", "ramimo_proc_chi [TX exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [TX exit execs]", state4_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state4_exit_exec)
/** state (TX) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "TX", "WAIT")
/*---------------------------------------------------------*/
/** state (SENSE) enter executives **/
FSM_STATE_ENTER_FORCED (5, "SENSE", state5_enter_exec, "ramimo_proc_chi [SENSE enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [SENSE enter execs]", state5_enter_exec)
{
/******************************************/
/*Code for physical carrier sensing update*/
/******************************************/
if(PCS)
{
/*Read the update from the receiver or transmitter channels*/
pcs_state = (int) op_stat_local_read(op_intrpt_stat());
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("SENSE STATE\n");
printf("Node ID = %d\n", userid);
printf("Updating the Physical Carrier Sensing Status!\n");
printf("Updated PCS_STATE = %d\n", pcs_state);
#endif
/*If the channel has become busy then any pending transmission or rob calculation interrupts need to be cancelled*/
if(pcs_state == 1)
{
/*Cancel the transmission event if scheduled and not for a DATA or ACK packet transmission*/
/*Remember that no regard is given to the state of the channel when tx a DATA or ACK packet*/
if(op_ev_valid(nexttxevent) == OPC_TRUE)
{
/*Update the backoff time if one has been set*/
if(rob != -1.0)
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Updating backoff time!\n");
printf("Original backoff time was %lfs\n", rob);
#endif
rob = op_ev_time(nexttxevent) - op_sim_time();
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("New backoff time is %lfs\n", rob);
#endif
}
op_ev_cancel(nexttxevent);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Cancelling a Scheduled Transmission Event!\n");
#endif
}
/*Cancel the transmission event if it is not for a DATA or ACK packet transmission*/
/*Remember that no regard is given to the state of the channel when tx a DATA or ACK packet*/
if(op_ev_valid(robevent) == OPC_TRUE)
{
op_ev_cancel(robevent);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Cancelling a Scheduled ROB Event!\n");
#endif
}
}
}
/******************************************************/
/*Code for virtual carrier sensing busy channel update*/
/******************************************************/
else if(VCS_busy)
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("SENSE STATE\n");
printf("Node ID = %d\n", userid);
printf("Channel is sensed BUSY via VCS\n");
#endif
/*Cancel the transmission event if scheduled and not for a DATA or ACK packet transmission*/
/*Remember that no regard is given to the state of the channel when tx a DATA or ACK packet*/
if(op_ev_valid(nexttxevent) == OPC_TRUE)
{
/*Update the backoff time if one has been set*/
if(rob != -1.0)
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Updating backoff time!\n");
printf("Original backoff time was %lfs\n", rob);
#endif
rob = op_ev_time(nexttxevent) - op_sim_time();
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("New backoff time is %lfs\n", rob);
#endif
}
op_ev_cancel(nexttxevent);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Cancelling a Scheduled Transmission Event!\n");
#endif
}
/*Cancel the transmission event if it is not for a DATA or ACK packet transmission*/
/*Remember that no regard is given to the state of the channel when tx a DATA or ACK packet*/
if(op_ev_valid(robevent) == OPC_TRUE)
{
op_ev_cancel(robevent);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Cancelling a Scheduled ROB Event!\n");
#endif
}
/*Determine if the channel is already sensed busy*/
if(vcs_state == 1)
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Channel was Already Sensed BUSY via VCS!\n");
printf("Time of Previous Free Interrupt = %lf\n", op_ev_time(chfreeint));
printf("New Time for Free Channel = %lf\n", op_sim_time() + vcs_duration);
#endif
/*Reschedule the channel free interrupt if the new duration is later than the previous*/
if((op_sim_time() + vcs_duration) > op_ev_time(chfreeint))
{
op_ev_cancel(chfreeint);
chfreeint = op_intrpt_schedule_self(op_sim_time() + vcs_duration, VCS_FREE_INT);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Rescheduling Channel Free Time\n");
printf("Channel Free Interrupt Scheduled for %lf seconds\n", op_sim_time() + vcs_duration);
#endif
}
}
else
{
chfreeint = op_intrpt_schedule_self(op_sim_time() + vcs_duration, VCS_FREE_INT);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Channel was not already sensed BUSY via VCS!\n");
printf("Time for Free Channel = %lf\n", op_sim_time() + vcs_duration);
#endif
}
/*Update the vcs state variable*/
vcs_state = 1;
}
/******************************************************/
/*Code for virtual carrier sensing free channel update*/
/******************************************************/
else if(VCS_free)
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("SENSE STATE\n");
printf("Node ID = %d\n", userid);
printf("Channel is sensed FREE via VCS!\n");
#endif
/*Update the vcs state variable*/
vcs_state = 0;
}
/************************************/
/*Code for the channel becoming free*/
/************************************/
/*If the channel is now free then a random backoff interrupt may need to be scheduled, either for a retransmission*/
/*attempt or a new transmission*/
if((pcs_state == 0) && (vcs_state == 0))
{
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Channel has just become FREE!\n");
#endif
/*Reschedule a transmission interrupt if required - based on the random backoff procedure*/
if( (busy == 1) && (txreq != 0) )
{
/*Schedule ROB interrupt in eifs time*/
robevent = op_intrpt_schedule_self(op_sim_time() + difs, ROB_INT);
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Scheduled a Random Backoff Interrupt for an Expected Transmission at %lfs\n", op_ev_time(robevent));
#endif
}
else if(busy == 0)
{
/*Initilise a flag variable*/
flag = 0;
/*Search through the packet queue to identify an appropriate one to transmit*/
for(i=0;i<op_subq_stat(SRC_QUEUE, OPC_QSTAT_PKSIZE);i++)
{
/*Access the packet at the appropriate position*/
pktptr = op_subq_pk_access(SRC_QUEUE, i);
/*Determine the ID of the corresponding source node*/
op_pk_nfd_get(pktptr, "SRC", &srcid);
/*If a packet is found from a different source than the one being handled by the other channel, schedule an RTS for it*/
if((srcid != sharedptr->partxsrcid) && (flag == 0))
{
flag = 1;
/*Set the variable to indicate the ID of the source*/
sharedptr->chitxsrcid = srcid;
/*Set the destination node ID to be associated with the tx interrupt*/
op_pk_nfd_get(pktptr, "nexthop", &commnodeid);
op_pk_nfd_get(pktptr, "number", &sequencenum);
/*Schedule RTS Interrupt in DIFS seconds time*/
robevent = op_intrpt_schedule_self(op_sim_time() + difs, ROB_INT);
txreq = 1;
txstate = RTS_INT;
busy = 1;
/*Reset the random backoff interval if this is a new transmission*/
rob = -1.0;
#ifdef PRINT_SENSE
printf("CHILD PROC\n");
printf("Scheduled a Random Backoff Interrupt for an New Packet Transmission at %lfs\n", op_ev_time(robevent));
op_pk_nfd_get(pktptr, "SRC", &srcid);
printf("Packet Source = %d\n", srcid);
op_pk_nfd_get(pktptr, "DEST", &destid);
printf("Packet Destination = %d\n", destid);
printf("Will be communicating with node %d\n", commnodeid);
printf("Packet Sequence Number = %lf\n", sequencenum);
#endif
}
}
}
}
op_prg_odb_bkpt("SENSE");
op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (state5_enter_exec)
/** state (SENSE) exit executives **/
FSM_STATE_EXIT_FORCED (5, "SENSE", "ramimo_proc_chi [SENSE exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [SENSE exit execs]", state5_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (state5_exit_exec)
/** state (SENSE) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "SENSE", "WAIT")
/*---------------------------------------------------------*/
/** state (RXARVL) enter executives **/
FSM_STATE_ENTER_FORCED (6, "RXARVL", state6_enter_exec, "ramimo_proc_chi [RXARVL enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_chi [RXARVL enter execs]", state6_enter_exec)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -