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

al_receiving.c File Reference

#include "standard.h"
#include "al.h"
#include "al_sending.h"
#include "al_receiving.h"
#include "rcpc.h"
#include "crc4.h"
#include "arq.h"
#include "uep_rcpcc.h"
#include "LList.h"
#include "between.h"

Go to the source code of this file.

Defines

#define DEF_MAX_ARQ   3

Functions

al_receiving_entitynew_al_receiving_entity (channel_info *nfo)
void send_to_al (al_receiving_entity *which, byte b)
void send_closing_flag (al_receiving_entity *which)
int al_indication (al_receiving_entity *which)
byte al_receive (al_receiving_entity *which)

Variables

int debug


Define Documentation

#define DEF_MAX_ARQ   3
 

Definition at line 12 of file al_receiving.c.


Function Documentation

int al_indication al_receiving_entity which  ) 
 

Definition at line 139 of file al_receiving.c.

References blevel(), and al_receiving_entity::outgoing_data.

Referenced by decode_audio(), and decode_video().

00144 {
00145   if (blevel(which->outgoing_data))
00146     return 1;
00147   else
00148     return 0;
00149 }

byte al_receive al_receiving_entity which  ) 
 

Definition at line 152 of file al_receiving.c.

References bread(), byte, and al_receiving_entity::outgoing_data.

Referenced by decode_audio(), and decode_video().

00156 {
00157   byte b;
00158 
00159   bread(which->outgoing_data, &b);
00160 
00161   return b;
00162 }

al_receiving_entity* new_al_receiving_entity channel_info nfo  ) 
 

Definition at line 21 of file al_receiving.c.

References al_receiving_entity::bad_payloads, byte, al_receiving_entity::crc_bytes, channel_info::crc_bytes, error(), al_receiving_entity::framed, channel_info::framed, al_receiving_entity::incoming_data, al_receiving_entity::initialized, al_receiving_entity::last_recd, al_receiving_entity::last_written, MAX_AL_BUFFER_SIZE, al_receiving_entity::max_arq, mkbuffer(), al_receiving_entity::old_threshold, channel_info::old_threshold, al_receiving_entity::outgoing_data, al_receiving_entity::rcpc_code, channel_info::rcpc_code, al_receiving_entity::rcpc_rate, channel_info::rcpc_rate, al_receiving_entity::seq_num, channel_info::seq_num, al_receiving_entity::type, and channel_info::type.

Referenced by finish_config().

00025 {
00026   al_receiving_entity *new_al;
00027   
00028   new_al = (al_receiving_entity *) malloc(sizeof(al_receiving_entity));
00029   /*  printf("new al_receiving entity has address %x\n",new_al); */
00030   if (new_al == NULL)
00031     error("new_al_receiving_entity", "can't malloc al_receiving_entity");
00032   else {
00033     new_al->outgoing_data = mkbuffer(MAX_AL_BUFFER_SIZE, sizeof(byte));
00034     new_al->incoming_data = mkbuffer(MAX_AL_BUFFER_SIZE, sizeof(byte));
00035 
00036     new_al->type = nfo->type;
00037     new_al->framed = nfo->framed;
00038     new_al->seq_num = nfo->seq_num;
00039 
00040     new_al->rcpc_code = nfo->rcpc_code;
00041     new_al->rcpc_rate = nfo->rcpc_rate;
00042 
00043     new_al->crc_bytes = nfo->crc_bytes;
00044 
00045     new_al->old_threshold = nfo->old_threshold;
00046 
00047     /* Initialize other parameters */
00048     new_al->max_arq = DEF_MAX_ARQ;
00049     new_al->last_recd = 31;
00050     new_al->last_written = 31;
00051     new_al->initialized = 0;
00052     new_al->bad_payloads = 0;
00053   }
00054   return new_al;
00055 }

void send_closing_flag al_receiving_entity which  ) 
 

Definition at line 68 of file al_receiving.c.

References blevel(), bread(), bwrite(), byte, crc16(), crc8(), al_receiving_entity::incoming_data, al_receiving_entity::outgoing_data, and al_receiving_entity::type.

Referenced by demultiplex().

00075 {
00076   byte inbuf[MAX_AL_BUFFER_SIZE];
00077   byte inbyte;
00078   byte computedCRC,receivedCRC;
00079   unsigned short computedCRC16,receivedCRC16;
00080   int i;
00081   int len=blevel(which->incoming_data);
00082   
00083   if (len > 0) {
00084     if (which->type == AL1) {
00085     /* just transfer incoming buffer to outgoing buffer.. */
00086       for(i=0;i<len;i++) {
00087         bread(which->incoming_data,(void *) &inbyte);
00088         bwrite(which->outgoing_data,(void *) &inbyte);
00089       }
00090     }
00091     else if (which->type == AL2) {
00092     /* check one byte crc, if good transfer to outgoing.  if not, put back
00093        into incoming */
00094       computedCRC = 0;
00095       for(i=0;i<len-1;i++) {
00096         bread(which->incoming_data,(void *) inbuf+i);
00097         crc8(&computedCRC,inbuf[i]);
00098       }
00099       bread(which->incoming_data,(void *) inbuf+(len-1));
00100       receivedCRC = inbuf[len-1];
00101       if (computedCRC == receivedCRC) { /* put data without crc into outgoing buf */
00102         if (debug) printf("AL receiving good CRC\n");
00103         for(i=0;i<len-1;i++)
00104           bwrite(which->outgoing_data,(void *) inbuf + i);
00105       }
00106       else { /* put all data back into incoming_data, bad crc */
00107         if (debug) printf("AL receiving bad CRC\n");
00108         for(i=0;i<len;i++)
00109           bwrite(which->incoming_data,(void *) inbuf + i);
00110       }
00111     }
00112     else if (which->type == AL3) {
00113     /* check two byte crc, if good transfer to outgoing.  if not, put back into
00114        incoming */
00115       computedCRC16 = 0;
00116       for(i=0;i<len-2;i++) {
00117         bread(which->incoming_data,(void *) inbuf+i);
00118         crc16(&computedCRC16,inbuf[i]);
00119       }
00120       bread(which->incoming_data,(void *) inbuf+(len-2));
00121       bread(which->incoming_data,(void *) inbuf+(len-1));
00122       receivedCRC16 = inbuf[len-2];
00123       receivedCRC16 = (receivedCRC16 << 8) | (inbuf[len-1]);
00124       if (computedCRC16 == receivedCRC16) { /* put data without crc into outgoing buf */
00125         if (debug) printf("AL receiving good CRC\n");
00126         for(i=0;i<len-2;i++)
00127           bwrite(which->outgoing_data,(void *) inbuf + i);
00128       }
00129       else { /* bad crc, send it anyway. could modify to send with an error msg */
00130         if (debug) printf("AL receiving bad CRC\n");
00131         for(i=0;i<len-2;i++)
00132           bwrite(which->outgoing_data,(void *) inbuf + i);
00133       }
00134     }
00135   }
00136 }

void send_to_al al_receiving_entity which,
byte  b
 

Definition at line 59 of file al_receiving.c.

References bwrite(), and al_receiving_entity::incoming_data.

Referenced by demultiplex().

00063 {
00064   bwrite(which->incoming_data, &b);
00065 }


Variable Documentation

int debug
 

Definition at line 23 of file main.c.

Referenced by apply_errors(), decode_bch(), do_cmd(), encode_bch(), gen_poly(), GetRcpcBits(), MakeNewVideoPacket(), Makeppx(), mdecode_bch(), multiplex(), rcpcc16_decode(), rcpcc16_encode(), set_config(), and show_vars().


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