TTY/TDD Generation support. More...
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_state * | tdd_new (void) |
TTY/TDD Generation support.
Definition in file tdd.h.
#define TDD_BYTES_PER_CHAR 2700 |
Definition at line 27 of file tdd.h.
Referenced by dahdi_sendtext().
int ast_tdd_gen_ecdisa | ( | unsigned char * | outbuf, | |
int | len | |||
) |
Generate Echo Canceller disable tone (2100HZ)
outbuf | This is the buffer to receive the tone data | |
len | This is the length (in samples) of the tone data to generate Returns 0 if no error, and -1 if error. |
Definition at line 149 of file tdd.c.
References ecdisa, and tdd_state::pos.
Referenced by dahdi_setoption().
int tdd_feed | ( | struct tdd_state * | tdd, | |
unsigned char * | ubuf, | |||
int | samples | |||
) |
Read samples into the state machine, and return character (if any).
tdd | Which state machine to act upon | |
ubuf | containing your samples | |
samples | number 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 162 of file tdd.c.
References ast_log(), AST_MULAW, calloc, free, fsk_serial(), tdd_state::fskd, LOG_ERROR, LOG_NOTICE, LOG_WARNING, tdd_state::mode, tdd_state::oldlen, tdd_state::oldstuff, and tdd_decode_baudot().
Referenced by dahdi_read().
00163 { 00164 int mylen = len; 00165 int olen; 00166 int b = 'X'; 00167 int res; 00168 int c,x; 00169 short *buf = calloc(1, 2 * len + tdd->oldlen); 00170 short *obuf = buf; 00171 if (!buf) { 00172 ast_log(LOG_WARNING, "Out of memory\n"); 00173 return -1; 00174 } 00175 memcpy(buf, tdd->oldstuff, tdd->oldlen); 00176 mylen += tdd->oldlen / 2; 00177 for (x = 0; x < len; x++) 00178 buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]); 00179 c = res = 0; 00180 while (mylen >= 1320) { /* has to have enough to work on */ 00181 olen = mylen; 00182 res = fsk_serial(&tdd->fskd, buf, &mylen, &b); 00183 if (mylen < 0) { 00184 ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen); 00185 free(obuf); 00186 return -1; 00187 } 00188 buf += (olen - mylen); 00189 if (res < 0) { 00190 ast_log(LOG_NOTICE, "fsk_serial failed\n"); 00191 free(obuf); 00192 return -1; 00193 } 00194 if (res == 1) { 00195 /* Ignore invalid bytes */ 00196 if (b > 0x7f) 00197 continue; 00198 c = tdd_decode_baudot(tdd, b); 00199 if ((c < 1) || (c > 126)) 00200 continue; /* if not valid */ 00201 break; 00202 } 00203 } 00204 if (mylen) { 00205 memcpy(tdd->oldstuff, buf, mylen * 2); 00206 tdd->oldlen = mylen * 2; 00207 } else 00208 tdd->oldlen = 0; 00209 free(obuf); 00210 if (res) { 00211 tdd->mode = 2; 00212 /* put it in mode where it 00213 reliably puts teleprinter in correct shift mode */ 00214 return(c); 00215 } 00216 return 0; 00217 }
void tdd_free | ( | struct tdd_state * | tdd | ) |
int tdd_gen_holdtone | ( | unsigned char * | buf | ) |
Generate hold tone
outbuf | This is the buffer to receive the tone data |
Generate TDD hold tone
buf | Result buffer |
Definition at line 286 of file tdd.c.
References PUT_AUDIO_SAMPLE, and tdd_getcarrier().
00287 { 00288 int bytes = 0; 00289 float scont = 0.0, cr = 1.0, ci=0.0; 00290 while (scont < tddsb * 10.0) { 00291 PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); 00292 scont += 1.0; 00293 } 00294 return bytes; 00295 }
int tdd_generate | ( | struct tdd_state * | tdd, | |
unsigned char * | buf, | |||
const char * | string | |||
) |
Generates a CallerID FSK stream in ulaw format suitable for transmission.
tdd | tdd structure | |
buf | Buffer to use. This needs to be large enough to accomodate all the generated samples. | |
string | This 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 297 of file tdd.c.
References tdd_state::charnum, tdd_state::mode, and PUT_TDD.
Referenced by dahdi_sendtext().
00298 { 00299 int bytes = 0; 00300 int i,x; 00301 char c; 00302 /*! Baudot letters */ 00303 static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV"; 00304 /*! Baudot figures */ 00305 static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;"; 00306 /* Initial carriers (real/imaginary) */ 00307 float cr = 1.0; 00308 float ci = 0.0; 00309 float scont = 0.0; 00310 00311 for(x = 0; str[x]; x++) { 00312 /* Do synch for each 72th character */ 00313 if ( (tdd->charnum++) % 72 == 0) 00314 PUT_TDD(tdd->mode ? 27 /* FIGS */ : 31 /* LTRS */); 00315 00316 c = toupper(str[x]); 00317 #if 0 00318 printf("%c",c); fflush(stdout); 00319 #endif 00320 if (c == 0) { /* send null */ 00321 PUT_TDD(0); 00322 continue; 00323 } 00324 if (c == '\r') { /* send c/r */ 00325 PUT_TDD(8); 00326 continue; 00327 } 00328 if (c == '\n') { /* send c/r and l/f */ 00329 PUT_TDD(8); 00330 PUT_TDD(2); 00331 continue; 00332 } 00333 if (c == ' ') { /* send space */ 00334 PUT_TDD(4); 00335 continue; 00336 } 00337 for (i = 0; i < 31; i++) { 00338 if (lstr[i] == c) 00339 break; 00340 } 00341 if (i < 31) { /* if we found it */ 00342 if (tdd->mode) { /* if in figs mode, change it */ 00343 PUT_TDD(31); /* Send LTRS */ 00344 tdd->mode = 0; 00345 } 00346 PUT_TDD(i); 00347 continue; 00348 } 00349 for (i = 0; i < 31; i++) { 00350 if (fstr[i] == c) 00351 break; 00352 } 00353 if (i < 31) { /* if we found it */ 00354 if (tdd->mode != 1) { /* if in ltrs mode, change it */ 00355 PUT_TDD(27); /* send FIGS */ 00356 tdd->mode = 1; 00357 } 00358 PUT_TDD(i); /* send byte */ 00359 continue; 00360 } 00361 } 00362 return bytes; 00363 }
void tdd_init | ( | void | ) |
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 104 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().
00105 { 00106 struct tdd_state *tdd; 00107 tdd = calloc(1, sizeof(*tdd)); 00108 if (tdd) { 00109 #ifdef INTEGER_CALLERID 00110 tdd->fskd.ispb = 176; /* 45.5 baud */ 00111 /* Set up for 45.5 / 8000 freq *32 to allow ints */ 00112 tdd->fskd.pllispb = (int)((8000 * 32 * 2) / 90); 00113 tdd->fskd.pllids = tdd->fskd.pllispb / 32; 00114 tdd->fskd.pllispb2 = tdd->fskd.pllispb / 2; 00115 tdd->fskd.hdlc = 0; /* Async */ 00116 tdd->fskd.nbit = 5; /* 5 bits */ 00117 tdd->fskd.instop = 1; /* integer rep of 1.5 stop bits */ 00118 tdd->fskd.parity = 0; /* No parity */ 00119 tdd->fskd.bw=0; /* Filter 75 Hz */ 00120 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00121 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00122 tdd->fskd.xi0 = 0; 00123 tdd->fskd.state = 0; 00124 tdd->pos = 0; 00125 tdd->mode = 0; 00126 fskmodem_init(&tdd->fskd); 00127 #else 00128 tdd->fskd.spb = 176; /* 45.5 baud */ 00129 tdd->fskd.hdlc = 0; /* Async */ 00130 tdd->fskd.nbit = 5; /* 5 bits */ 00131 tdd->fskd.nstop = 1.5; /* 1.5 stop bits */ 00132 tdd->fskd.parity = 0; /* No parity */ 00133 tdd->fskd.bw=0; /* Filter 75 Hz */ 00134 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00135 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00136 tdd->fskd.pcola = 0; /* No clue */ 00137 tdd->fskd.cont = 0; /* Digital PLL reset */ 00138 tdd->fskd.x0 = 0.0; 00139 tdd->fskd.state = 0; 00140 tdd->pos = 0; 00141 tdd->mode = 2; 00142 #endif 00143 tdd->charnum = 0; 00144 } else 00145 ast_log(LOG_WARNING, "Out of memory\n"); 00146 return tdd; 00147 }