fskmodem.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fsk_data

Defines

#define PARITY_NONE   0
#define PARITY_EVEN   1
#define PARITY_ODD   2
#define NCOLA   0x4000

Functions

int fsk_serie (fsk_data *fskd, short *buffer, int *len, int *outbyte)


Define Documentation

#define NCOLA   0x4000

Definition at line 25 of file fskmodem.h.

#define PARITY_EVEN   1

Definition at line 21 of file fskmodem.h.

#define PARITY_NONE   0

Definition at line 20 of file fskmodem.h.

#define PARITY_ODD   2

Definition at line 22 of file fskmodem.h.


Function Documentation

int fsk_serie ( fsk_data fskd,
short *  buffer,
int *  len,
int *  outbyte 
)

Definition at line 168 of file fskmodem.c.

00169 {
00170    int a;
00171    int i,j,n1,r;
00172    int samples=0;
00173    int olen;
00174    switch(fskd->state) {
00175       /* Pick up where we left off */
00176    case STATE_SEARCH_STARTBIT2:
00177       goto search_startbit2;
00178    case STATE_SEARCH_STARTBIT3:
00179       goto search_startbit3;
00180    case STATE_GET_BYTE:
00181       goto getbyte;
00182    }
00183    /* Esperamos bit de start  */
00184    do {
00185 /* this was jesus's nice, reasonable, working (at least with RTTY) code
00186 to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
00187 just start sending a start bit with nothing preceding it at the beginning
00188 of a transmission (what a LOSING design), we cant do it this elegantly */
00189 /*
00190       if (demodulador(zap,&x1)) return(-1);
00191       for(;;) {
00192          if (demodulador(zap,&x2)) return(-1);
00193          if (x1>0 && x2<0) break;
00194          x1=x2;
00195       }
00196 */
00197 /* this is now the imprecise, losing, but functional code to detect the
00198 beginning of a start bit in the TDD sceanario. It just looks for sufficient
00199 level to maybe, perhaps, guess, maybe that its maybe the beginning of
00200 a start bit, perhaps. This whole thing stinks! */
00201       if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
00202       samples++;
00203       for(;;)
00204          {
00205 search_startbit2:       
00206          if (!*len) {
00207             fskd->state = STATE_SEARCH_STARTBIT2;
00208             return 0;
00209          }
00210          samples++;
00211          if (demodulador(fskd,&fskd->x2,GET_SAMPLE)) return(-1);
00212 #if 0
00213          printf("x2 = %5.5f ", fskd->x2);
00214 #endif         
00215          if (fskd->x2 < -0.5) break; 
00216          }
00217 search_startbit3:       
00218       /* Esperamos 0.5 bits antes de usar DPLL */
00219       i=fskd->spb/2;
00220       if (*len < i) {
00221          fskd->state = STATE_SEARCH_STARTBIT3;
00222          return 0;
00223       }
00224       for(;i;i--) { if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1); 
00225 #if 0
00226          printf("x1 = %5.5f ", fskd->x1);
00227 #endif         
00228    samples++; }
00229 
00230       /* x1 debe ser negativo (confirmación del bit de start) */
00231 
00232    } while (fskd->x1>0);
00233    fskd->state = STATE_GET_BYTE;
00234 
00235 getbyte:
00236 
00237    /* Need at least 80 samples (for 1200) or
00238       1320 (for 45.5) to be sure we'll have a byte */
00239    if (fskd->nbit < 8) {
00240       if (*len < 1320)
00241          return 0;
00242    } else {
00243       if (*len < 80)
00244          return 0;
00245    }
00246    /* Leemos ahora los bits de datos */
00247    j=fskd->nbit;
00248    for (a=n1=0;j;j--) {
00249       olen = *len;
00250       i=get_bit_raw(fskd, buffer, len);
00251       buffer += (olen - *len);
00252       if (i == -1) return(-1);
00253       if (i) n1++;
00254       a>>=1; a|=i;
00255    }
00256    j=8-fskd->nbit;
00257    a>>=j;
00258 
00259    /* Leemos bit de paridad (si existe) y la comprobamos */
00260    if (fskd->paridad) {
00261       olen = *len;
00262       i=get_bit_raw(fskd, buffer, len); 
00263       buffer += (olen - *len);
00264       if (i == -1) return(-1);
00265       if (i) n1++;
00266       if (fskd->paridad==1) { /* paridad=1 (par) */
00267          if (n1&1) a|=0x100;     /* error */
00268       } else {       /* paridad=2 (impar) */
00269          if (!(n1&1)) a|=0x100;  /* error */
00270       }
00271    }
00272    
00273    /* Leemos bits de STOP. Todos deben ser 1 */
00274    
00275    for (j=fskd->nstop;j;j--) {
00276       r = get_bit_raw(fskd, buffer, len);
00277       if (r == -1) return(-1);
00278       if (!r) a|=0x200;
00279    }
00280 
00281    /* Por fin retornamos  */
00282    /* Bit 8 : Error de paridad */
00283    /* Bit 9 : Error de Framming */
00284 
00285    *outbyte = a;
00286    fskd->state = STATE_SEARCH_STARTBIT;
00287    return 1;
00288 }


Generated on Wed Oct 28 17:00:55 2009 for Asterisk by  doxygen 1.5.6