fskmodem_float.h File Reference

FSK Modem Support. More...

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 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 226 of file fskmodem_float.c.

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

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


Generated on Thu Apr 16 06:31:10 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6