Main Page | Class List | File List | Class Members | File Members

rcpc.h File Reference

#include "Buffer.h"

Go to the source code of this file.

Classes

struct  buf_rcpc

Functions

int max_arq (int rtype)
int inc_xmit_count (buf_rcpc *br)
buf_rcpcfind_rcpc (Buffer *rcpcs, int seq_num)
buf_rcpcplace_rcpc (Buffer *rcpcs, int seq_num, byte *data, int num_bytes, int arq_type, int last_written, int *last_recd, int old_threshold)


Function Documentation

buf_rcpc* find_rcpc Buffer rcpcs,
int  seq_num
 

Definition at line 64 of file rcpc.c.

References blevel(), bpeek(), and buf_rcpc::sequence_number.

Referenced by place_rcpc().

00069 {
00070   int i;
00071   buf_rcpc *rcpc;
00072  
00073   for (i=blevel(rcpcs)-1; i >= 0; i--) {
00074     rcpc = bpeek(rcpcs, i);
00075     if (seq_num == rcpc->sequence_number)
00076       return (rcpc);
00077   }
00078   return(NULL);
00079 }

int inc_xmit_count buf_rcpc br  ) 
 

Definition at line 55 of file rcpc.c.

References buf_rcpc::xmit_count.

00059 {
00060   br->xmit_count = (br->xmit_count + 1);
00061     return (br->xmit_count) % 2;
00062 }

int max_arq int  rtype  ) 
 

Definition at line 8 of file rcpc.c.

References error().

Referenced by GetRcpcBits().

00012 {
00013   int rval;
00014 
00015   switch (rtype) {
00016     case 24:
00017       rval = 3;
00018       break;
00019     case 23:
00020     case 22:
00021       rval = 2;
00022       break;
00023     case 21:
00024     case 20:
00025     case 19:
00026     case 18:
00027     case 17:
00028     case 16:
00029       rval = 1;
00030       break;
00031     case 15:
00032     case 14:
00033     case 13:
00034     case 12:
00035     case 11:
00036     case 10:
00037     case 9:
00038     case 8:
00039     case 7:
00040     case 6:
00041     case 5:
00042     case 4:
00043     case 3:
00044     case 2:
00045     case 1:
00046     case 0:
00047       rval = 0;
00048       break;
00049     default:
00050       error("max_arq","Invalid rtype input");
00051   }
00052 }

buf_rcpc* place_rcpc Buffer rcpcs,
int  seq_num,
byte data,
int  num_bytes,
int  arq_type,
int  last_written,
int *  last_recd,
int  old_threshold
 

Definition at line 81 of file rcpc.c.

References between(), buf_rcpc::block, bpeek(), bwrite(), buf_rcpc::count, data, find_rcpc(), Buffer::full, buf_rcpc::length, minus(), num_bytes(), buf_rcpc::sequence_number, and buf_rcpc::xmit_count.

00094 {
00095   buf_rcpc *rcpc,new_rcpc;
00096   int i,old;
00097 
00098 
00099   old = minus(last_written,old_threshold);
00100   if (between(seq_num,old,last_written) || (seq_num == last_written)) {
00101     printf("place_rcpc() - Disregarding packet %d.  It's too old\n",seq_num);
00102     return(NULL);
00103   } 
00104   else {
00105     if ((between(seq_num,*last_recd,old)) || (seq_num == old)) { 
00106       /* it's a new entry */
00107       *last_recd = seq_num;
00108       /* cheat to find out if we're going to overwrite the last buffer entry
00109        * and if we are, be sure to free any allocated blocks
00110        */
00111       if (rcpcs->full) {
00112         rcpc=bpeek(rcpcs, 0);
00113         if (rcpc->block[0]!=NULL) free(rcpc->block[0]);
00114         if (rcpc->block[1]!=NULL) free(rcpc->block[1]);
00115         if (rcpc->block[2]!=NULL) free(rcpc->block[2]);
00116         if (rcpc->block[3]!=NULL) free(rcpc->block[3]);
00117       }
00118       new_rcpc.sequence_number=seq_num;
00119       new_rcpc.count=1;
00120       new_rcpc.xmit_count=1;
00121       new_rcpc.length=num_bytes;
00122       new_rcpc.block[0]=malloc(num_bytes);
00123       new_rcpc.block[1]=NULL;
00124       new_rcpc.block[2]=NULL;
00125       new_rcpc.block[3]=NULL;
00126       if (new_rcpc.block[0]==NULL) {
00127         fprintf(stderr, "place_rcpc: malloc() failure\n");
00128         return NULL;
00129       }
00130       for (i=0; i<num_bytes; i++) {
00131         new_rcpc.block[0][i]=data[i];
00132       }
00133       bwrite(rcpcs, &new_rcpc);
00134       return(find_rcpc(rcpcs,seq_num));
00135     }
00136     else { /* it's a retransmission */
00137       /* 
00138        */
00139         printf("Got retransmission of sequence number %d\n",seq_num);
00140         rcpc = find_rcpc(rcpcs,seq_num);
00141         if (rcpc->count == 4) {
00142           printf("place_rcpc()-ERROR tried to place block into full rcpc struct\n");
00143           return(NULL);
00144         }
00145         if (arq_type == 1) {
00146           for (i=0; i<num_bytes; i++) {
00147             rcpc->block[0][i]=data[i];
00148           }
00149         } else {
00150           rcpc->block[rcpc->count]=malloc(num_bytes);
00151           if (rcpc->block[rcpc->count]==NULL) {
00152             fprintf(stderr, "place_rcpc: malloc() failure\n");
00153             return(rcpc);
00154           }
00155           for (i=0; i<num_bytes; i++) {
00156             rcpc->block[rcpc->count][i]=data[i];
00157           }
00158           rcpc->count++;
00159         }
00160         /* rcpc->xmit_count++; */
00161         return(rcpc);
00162       }
00163     }
00164 /*  } */
00165 }


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1