Thu Apr 28 2011 16:57:19

Asterisk developer's documentation


tdd.h File Reference

TTY/TDD Generation support. More...

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

Go to the source code of this file.

Defines

#define TDD_BYTES_PER_CHAR   2700

Typedefs

typedef struct tdd_state TDDSTATE

Functions

int ast_tdd_gen_ecdisa (unsigned char *outbuf, int len)
int tdd_feed (struct tdd_state *tdd, unsigned char *ubuf, int samples)
void tdd_free (struct tdd_state *tdd)
int tdd_gen_holdtone (unsigned char *outbuf)
int tdd_generate (struct tdd_state *tdd, unsigned char *buf, const char *string)
void tdd_init (void)
struct tdd_statetdd_new (void)

Detailed Description

TTY/TDD Generation support.

Note:
Includes code and algorithms from the Zapata library.

Definition in file tdd.h.


Define Documentation

#define TDD_BYTES_PER_CHAR   2700

Definition at line 27 of file tdd.h.

Referenced by dahdi_sendtext().


Typedef Documentation

typedef struct tdd_state TDDSTATE

Definition at line 30 of file tdd.h.


Function Documentation

int ast_tdd_gen_ecdisa ( unsigned char *  outbuf,
int  len 
)

Generate Echo Canceller disable tone (2100HZ)

Parameters:
outbufThis is the buffer to receive the tone data
lenThis is the length (in samples) of the tone data to generate Returns 0 if no error, and -1 if error.

Definition at line 143 of file tdd.c.

References ecdisa, len(), and tdd_state::pos.

Referenced by dahdi_setoption().

{
   int pos = 0;
   int cnt;
   while (len) {
      cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len;
      memcpy(outbuf + pos, ecdisa, cnt);
      pos += cnt;
      len -= cnt;
   }
   return 0;
}
int tdd_feed ( struct tdd_state tdd,
unsigned char *  ubuf,
int  samples 
)

Read samples into the state machine, and return character (if any).

Parameters:
tddWhich state machine to act upon
ubufcontaining your samples
samplesnumber of samples contained within the buffer.

Send received audio to the TDD demodulator. Returns -1 on error, 0 for "needs more samples", and > 0 (the character) if reception of a character is complete.

Definition at line 156 of file tdd.c.

References ast_log(), AST_MULAW, buf, calloc, free, fsk_serial(), tdd_state::fskd, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, tdd_state::mode, tdd_state::oldlen, tdd_state::oldstuff, and tdd_decode_baudot().

Referenced by dahdi_read().

{
   int mylen = len;
   int olen;
   int b = 'X';
   int res;
   int c,x;
   short *buf = calloc(1, 2 * len + tdd->oldlen);
   short *obuf = buf;
   if (!buf) {
      ast_log(LOG_WARNING, "Out of memory\n");
      return -1;
   }
   memcpy(buf, tdd->oldstuff, tdd->oldlen);
   mylen += tdd->oldlen / 2;
   for (x = 0; x < len; x++) 
      buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]);
   c = res = 0;
   while (mylen >= 1320) { /* has to have enough to work on */
      olen = mylen;
      res = fsk_serial(&tdd->fskd, buf, &mylen, &b);
      if (mylen < 0) {
         ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
         free(obuf);
         return -1;
      }
      buf += (olen - mylen);
      if (res < 0) {
         ast_log(LOG_NOTICE, "fsk_serial failed\n");
         free(obuf);
         return -1;
      }
      if (res == 1) {
         /* Ignore invalid bytes */
         if (b > 0x7f)
            continue;
         c = tdd_decode_baudot(tdd, b);
         if ((c < 1) || (c > 126))
            continue; /* if not valid */
         break;
      }
   }
   if (mylen) {
      memcpy(tdd->oldstuff, buf, mylen * 2);
      tdd->oldlen = mylen * 2;
   } else
      tdd->oldlen = 0;
   free(obuf);
   if (res) {
      tdd->mode = 2; 
/* put it in mode where it
         reliably puts teleprinter in correct shift mode */
      return(c);
   }
   return 0;
}
void tdd_free ( struct tdd_state tdd)

Free a TDD state machine

Parameters:
tddThis is the tdd_state state machine to free This function frees tdd_state tdd.

Definition at line 213 of file tdd.c.

References free.

Referenced by dahdi_setoption().

{
   free(tdd);
}
int tdd_gen_holdtone ( unsigned char *  buf)

Generate hold tone

Parameters:
outbufThis is the buffer to receive the tone data

Generate TDD hold tone

Parameters:
bufResult buffer
Todo:
How big should this be???

Definition at line 280 of file tdd.c.

References PUT_AUDIO_SAMPLE, and tdd_getcarrier().

{
   int bytes = 0;
   float scont = 0.0, cr = 1.0, ci=0.0;
   while (scont < tddsb * 10.0) {
      PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1));
      scont += 1.0;
   }
   return bytes;
}
int tdd_generate ( struct tdd_state tdd,
unsigned char *  buf,
const char *  string 
)

Generates a CallerID FSK stream in ulaw format suitable for transmission.

Parameters:
tddtdd structure
bufBuffer to use. This needs to be large enough to accomodate all the generated samples.
stringThis is the string to send. This function creates a stream of TDD data in ulaw format. It returns the size (in bytes) of the data (if it returns a size of 0, there is probably an error)

Baudot letters

Baudot figures

Definition at line 291 of file tdd.c.

References tdd_state::charnum, tdd_state::mode, and PUT_TDD.

Referenced by dahdi_sendtext().

{
   int bytes = 0;
   int i,x;
   char c;
   /*! Baudot letters */
   static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV";
   /*! Baudot figures */
   static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;";
   /* Initial carriers (real/imaginary) */
   float cr = 1.0;
   float ci = 0.0;
   float scont = 0.0;

   for(x = 0; str[x]; x++) {
      /* Do synch for each 72th character */
      if ( (tdd->charnum++) % 72 == 0) 
         PUT_TDD(tdd->mode ? 27 /* FIGS */ : 31 /* LTRS */);

      c = toupper(str[x]);
#if   0
      printf("%c",c); fflush(stdout);
#endif
      if (c == 0) { /* send null */
         PUT_TDD(0);
         continue;
      }
      if (c == '\r') { /* send c/r */
         PUT_TDD(8);
         continue;
      }
      if (c == '\n') { /* send c/r and l/f */
         PUT_TDD(8);
         PUT_TDD(2);
         continue;
      }
      if (c == ' ') { /* send space */
         PUT_TDD(4);
         continue;
      }
      for (i = 0; i < 31; i++) {
         if (lstr[i] == c)
            break;
      }
      if (i < 31) {        /* if we found it */
         if (tdd->mode) { /* if in figs mode, change it */
            PUT_TDD(31); /* Send LTRS */
            tdd->mode = 0;
         }
         PUT_TDD(i);
         continue;
      }
      for (i = 0; i < 31; i++) {
         if (fstr[i] == c)
            break;
      }
      if (i < 31) {             /* if we found it */
         if (tdd->mode != 1) { /* if in ltrs mode, change it */
            PUT_TDD(27);      /* send FIGS */
            tdd->mode = 1;
         }
         PUT_TDD(i);           /* send byte */
         continue;
      }
   }
   return bytes;
}
void tdd_init ( void  )

CallerID Initialization Initializes the TDD system. Mostly stuff for inverse FFT

Definition at line 89 of file tdd.c.

References cos, TDD_MARK, and TDD_SPACE.

Referenced by main().

{
   /* Initialize stuff for inverse FFT */
   dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0);
   di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0);
   dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0);
   di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0);
}
struct tdd_state* tdd_new ( void  ) [read]

Create a TDD state machine This function returns a malloc'd instance of the tdd_state data structure. Returns a pointer to a malloc'd tdd_state structure, or NULL on error.

Definition at line 98 of file tdd.c.

References ast_log(), fsk_data::bw, calloc, tdd_state::charnum, fsk_data::cont, fsk_data::f_mark_idx, fsk_data::f_space_idx, tdd_state::fskd, fskmodem_init(), fsk_data::hdlc, fsk_data::instop, fsk_data::ispb, LOG_WARNING, tdd_state::mode, fsk_data::nbit, fsk_data::nstop, fsk_data::parity, fsk_data::pcola, fsk_data::pllids, fsk_data::pllispb, fsk_data::pllispb2, tdd_state::pos, fsk_data::spb, fsk_data::state, fsk_data::x0, and fsk_data::xi0.

Referenced by dahdi_setoption().

{
   struct tdd_state *tdd;
   tdd = calloc(1, sizeof(*tdd));
   if (tdd) {
#ifdef INTEGER_CALLERID
      tdd->fskd.ispb = 176;        /* 45.5 baud */
      /* Set up for 45.5 / 8000 freq *32 to allow ints */
      tdd->fskd.pllispb  = (int)((8000 * 32 * 2) / 90);
      tdd->fskd.pllids   = tdd->fskd.pllispb / 32;
      tdd->fskd.pllispb2 = tdd->fskd.pllispb / 2;
      tdd->fskd.hdlc = 0;         /* Async */
      tdd->fskd.nbit = 5;         /* 5 bits */
      tdd->fskd.instop = 1;       /* integer rep of 1.5 stop bits */
      tdd->fskd.parity = 0;       /* No parity */
      tdd->fskd.bw=0;             /* Filter 75 Hz */
      tdd->fskd.f_mark_idx = 0;   /* 1400 Hz */
      tdd->fskd.f_space_idx = 1;  /* 1800 Hz */
      tdd->fskd.xi0  = 0;
      tdd->fskd.state = 0;
      tdd->pos = 0;
      tdd->mode = 0;
      fskmodem_init(&tdd->fskd);
#else
      tdd->fskd.spb = 176;        /* 45.5 baud */
      tdd->fskd.hdlc = 0;         /* Async */
      tdd->fskd.nbit = 5;         /* 5 bits */
      tdd->fskd.nstop = 1.5;      /* 1.5 stop bits */
      tdd->fskd.parity = 0;       /* No parity */
      tdd->fskd.bw=0;             /* Filter 75 Hz */
      tdd->fskd.f_mark_idx = 0;   /* 1400 Hz */
      tdd->fskd.f_space_idx = 1;  /* 1800 Hz */
      tdd->fskd.pcola = 0;        /* No clue */
      tdd->fskd.cont = 0;         /* Digital PLL reset */
      tdd->fskd.x0 = 0.0;
      tdd->fskd.state = 0;
      tdd->pos = 0;
      tdd->mode = 2;
#endif
      tdd->charnum = 0;
   } else
      ast_log(LOG_WARNING, "Out of memory\n");
   return tdd;
}