#include "asterisk.h"
#include <time.h>
#include <math.h>
#include <ctype.h>
#include "asterisk/logger.h"
#include "asterisk/ulaw.h"
#include "asterisk/tdd.h"
#include "asterisk/fskmodem.h"
#include "ecdisa.h"
Go to the source code of this file.
Data Structures | |
struct | tdd_state |
Defines | |
#define | PUT_AUDIO_SAMPLE(y) |
#define | PUT_BYTE(a) |
#define | PUT_TDD(byte) |
#define | PUT_TDD_BAUD(bit) |
#define | PUT_TDD_MARKMS |
#define | PUT_TDD_STOP |
#define | TDD_MARK 1400.0 |
#define | TDD_SPACE 1800.0 |
Functions | |
int | ast_tdd_gen_ecdisa (unsigned char *outbuf, int len) |
static int | tdd_decode_baudot (struct tdd_state *tdd, unsigned char data) |
int | tdd_feed (struct tdd_state *tdd, unsigned char *ubuf, int len) |
void | tdd_free (struct tdd_state *tdd) |
int | tdd_gen_holdtone (unsigned char *buf) |
int | tdd_generate (struct tdd_state *tdd, unsigned char *buf, const char *str) |
static float | tdd_getcarrier (float *cr, float *ci, int bit) |
void | tdd_init (void) |
tdd_state * | tdd_new (void) |
Variables | |
static float | di [4] |
static float | dr [4] |
static float | tddsb = 176.0 |
Definition in file tdd.c.
#define PUT_AUDIO_SAMPLE | ( | y | ) |
Value:
do { \ int __pas_idx = (short)(rint(8192.0 * (y))); \ *(buf++) = AST_LIN2MU(__pas_idx); \ bytes++; \ } while(0)
#define PUT_BYTE | ( | a | ) |
#define PUT_TDD | ( | byte | ) |
#define PUT_TDD_MARKMS |
Value:
do { \ int x; \ for (x = 0; x < 8; x++) \ PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); \ } while(0)
#define TDD_MARK 1400.0 |
#define TDD_SPACE 1800.0 |
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().
00150 { 00151 int pos = 0; 00152 int cnt; 00153 while (len) { 00154 cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len; 00155 memcpy(outbuf + pos, ecdisa, cnt); 00156 pos += cnt; 00157 len -= cnt; 00158 } 00159 return 0; 00160 }
static int tdd_decode_baudot | ( | struct tdd_state * | tdd, | |
unsigned char | data | |||
) | [static] |
Definition at line 65 of file tdd.c.
References tdd_state::modo.
Referenced by tdd_feed().
00066 { 00067 static char ltrs[32] = { '<','E','\n','A',' ','S','I','U', 00068 '\n','D','R','J','N','F','C','K', 00069 'T','Z','L','W','H','Y','P','Q', 00070 'O','B','G','^','M','X','V','^' }; 00071 static char figs[32] = { '<','3','\n','-',' ','\'','8','7', 00072 '\n','$','4','\'',',','!',':','(', 00073 '5','\"',')','2','=','6','0','1', 00074 '9','?','+','^','.','/',';','^' }; 00075 int d = 0; /* return 0 if not decodeable */ 00076 if (data < 32) { 00077 switch (data) { 00078 case 0x1f: 00079 tdd->modo = 0; 00080 break; 00081 case 0x1b: 00082 tdd->modo = 1; 00083 break; 00084 default: 00085 if (tdd->modo == 0) 00086 d = ltrs[data]; 00087 else 00088 d = figs[data]; 00089 break; 00090 } 00091 } 00092 return d; 00093 }
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. |
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 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 }
static float tdd_getcarrier | ( | float * | cr, | |
float * | ci, | |||
int | bit | |||
) | [inline, static] |
Definition at line 224 of file tdd.c.
Referenced by tdd_gen_holdtone().
00225 { 00226 /* Move along. There's nothing to see here... */ 00227 float t; 00228 t = *cr * dr[bit] - *ci * di[bit]; 00229 *ci = *cr * di[bit] + *ci * dr[bit]; 00230 *cr = t; 00231 00232 t = 2.0 - (*cr * *cr + *ci * *ci); 00233 *cr *= t; 00234 *ci *= t; 00235 return *cr; 00236 }
void tdd_init | ( | void | ) |
CallerID Initialization Initializes the TDD system. Mostly stuff for inverse FFT
Definition at line 95 of file tdd.c.
References cos, M_PI, TDD_MARK, and TDD_SPACE.
Referenced by main().
00096 { 00097 /* Initialize stuff for inverse FFT */ 00098 dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0); 00099 di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0); 00100 dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0); 00101 di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0); 00102 }
struct tdd_state* tdd_new | ( | void | ) |
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(), calloc, fskmodem_init(), and LOG_WARNING.
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 }
float di[4] [static] |
Definition at line 59 of file tdd.c.
Referenced by dial_exec_full(), dialed_interface_destroy(), and dialed_interface_duplicate().
float dr[4] [static] |
Definition at line 59 of file tdd.c.
Referenced by abort_request(), append_transaction(), build_transactions(), cancel_request(), check_request(), discover_transactions(), dundi_do_lookup(), dundi_lookup_internal(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_internal(), dundi_prop_precache(), dundi_query_eid_internal(), dundifunc_read(), optimize_transactions(), precache_trans(), precache_transactions(), query_transactions(), register_request(), and unregister_request().