Mon Mar 19 11:30:48 2012

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.

Referenced by callerid_feed(), callerid_feed_jp(), and tdd_feed().

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


Generated on Mon Mar 19 11:30:48 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7