Wed Aug 18 22:34:23 2010

Asterisk developer's documentation


fskmodem_float.h File Reference

FSK Modem Support. More...

Go to the source code of this file.

Data Structures

struct  fsk_data

Defines

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

Functions

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


Detailed Description

FSK Modem Support.

Note:
Includes code and algorithms from the Zapata library.

Definition in file fskmodem_float.h.


Define Documentation

#define NCOLA   0x4000

Definition at line 32 of file fskmodem_float.h.

Referenced by demodulator().

#define PARITY_EVEN   1

Definition at line 28 of file fskmodem_float.h.

#define PARITY_NONE   0

Definition at line 27 of file fskmodem_float.h.

#define PARITY_ODD   2

Definition at line 29 of file fskmodem_float.h.


Function Documentation

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

Definition at line 222 of file fskmodem_float.c.

00223 {
00224    int a;
00225    int i,j,n1,r;
00226    int samples = 0;
00227    int olen;
00228    int beginlen=*len;
00229    int beginlenx;
00230    
00231    switch (fskd->state) {
00232       /* Pick up where we left off */
00233    case STATE_SEARCH_STARTBIT2:
00234       goto search_startbit2;
00235    case STATE_SEARCH_STARTBIT3:
00236       goto search_startbit3;
00237    case STATE_GET_BYTE:
00238       goto getbyte;
00239    }
00240    /* We await for start bit  */
00241    do {
00242       /* this was jesus's nice, reasonable, working (at least with RTTY) code
00243       to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
00244       just start sending a start bit with nothing preceding it at the beginning
00245       of a transmission (what a LOSING design), we cant do it this elegantly */
00246       /*
00247       if (demodulator(zap,&x1)) return(-1);
00248       for (;;) {
00249          if (demodulator(zap,&x2)) return(-1);
00250          if (x1>0 && x2<0) break;
00251          x1 = x2;
00252       }
00253       */
00254       /* this is now the imprecise, losing, but functional code to detect the
00255       beginning of a start bit in the TDD sceanario. It just looks for sufficient
00256       level to maybe, perhaps, guess, maybe that its maybe the beginning of
00257       a start bit, perhaps. This whole thing stinks! */
00258       beginlenx=beginlen; /* just to avoid unused war warnings */
00259       if (demodulator(fskd, &fskd->x1, GET_SAMPLE))
00260          return -1;
00261       samples++;
00262       for (;;) {
00263 search_startbit2:       
00264          if (*len <= 0) {
00265             fskd->state  =  STATE_SEARCH_STARTBIT2;
00266             return 0;
00267          }
00268          samples++;
00269          if (demodulator(fskd, &fskd->x2, GET_SAMPLE))
00270             return(-1);
00271 #if 0
00272          printf("x2  =  %5.5f ", fskd->x2);
00273 #endif         
00274          if (fskd->x2 < -0.5)
00275             break; 
00276       }
00277 search_startbit3:       
00278       /* We await for 0.5 bits before using DPLL */
00279       i = fskd->spb/2;
00280       if (*len < i) {
00281          fskd->state = STATE_SEARCH_STARTBIT3;
00282          return 0;
00283       }
00284       for (; i>0; i--) {
00285          if (demodulator(fskd, &fskd->x1, GET_SAMPLE))
00286             return(-1); 
00287 #if 0
00288          printf("x1 = %5.5f ", fskd->x1);
00289 #endif         
00290          samples++;
00291       }
00292 
00293       /* x1 must be negative (start bit confirmation) */
00294 
00295    } while (fskd->x1 > 0);
00296    fskd->state = STATE_GET_BYTE;
00297 
00298 getbyte:
00299 
00300    /* Need at least 80 samples (for 1200) or
00301       1320 (for 45.5) to be sure we'll have a byte */
00302    if (fskd->nbit < 8) {
00303       if (*len < 1320)
00304          return 0;
00305    } else {
00306       if (*len < 80)
00307          return 0;
00308    }
00309    /* Now we read the data bits */
00310    j = fskd->nbit;
00311    for (a = n1 = 0; j; j--) {
00312       olen = *len;
00313       i = get_bit_raw(fskd, buffer, len);
00314       buffer += (olen - *len);
00315       if (i == -1)
00316          return(-1);
00317       if (i)
00318          n1++;
00319       a >>= 1;
00320       a |= i;
00321    }
00322    j = 8-fskd->nbit;
00323    a >>= j;
00324 
00325    /* We read parity bit (if exists) and check parity */
00326    if (fskd->parity) {
00327       olen = *len;
00328       i = get_bit_raw(fskd, buffer, len); 
00329       buffer += (olen - *len);
00330       if (i == -1)
00331          return(-1);
00332       if (i)
00333          n1++;
00334       if (fskd->parity == 1) {   /* parity=1 (even) */
00335          if (n1&1)
00336             a |= 0x100;    /* error */
00337       } else {       /* parity=2 (odd) */
00338          if (!(n1&1))
00339             a |= 0x100; /* error */
00340       }
00341    }
00342    
00343    /* We read STOP bits. All of them must be 1 */
00344    
00345    for (j = fskd->nstop;j;j--) {
00346       r = get_bit_raw(fskd, buffer, len);
00347       if (r == -1)
00348          return(-1);
00349       if (!r)
00350          a |= 0x200;
00351    }
00352 
00353    /* And finally we return  */
00354    /* Bit 8 : Parity error */
00355    /* Bit 9 : Framming error*/
00356 
00357    *outbyte = a;
00358    fskd->state = STATE_SEARCH_STARTBIT;
00359    return 1;
00360 }


Generated on Wed Aug 18 22:34:23 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7