Go to the source code of this file.
Defines | |
#define | TDD_BYTES_PER_CHAR 2700 |
Typedefs | |
typedef 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) |
tdd_state * | tdd_new (void) |
Definition in file tdd.h.
#define TDD_BYTES_PER_CHAR 2700 |
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 143 of file tdd.c.
References ecdisa, and tdd_state::pos.
Referenced by dahdi_setoption().
00144 { 00145 int pos = 0; 00146 int cnt; 00147 while (len) { 00148 cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len; 00149 memcpy(outbuf + pos, ecdisa, cnt); 00150 pos += cnt; 00151 len -= cnt; 00152 } 00153 return 0; 00154 }
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 156 of file tdd.c.
References ast_log(), AST_MULAW, buf, 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().
00157 { 00158 int mylen = len; 00159 int olen; 00160 int b = 'X'; 00161 int res; 00162 int c,x; 00163 short *buf = calloc(1, 2 * len + tdd->oldlen); 00164 short *obuf = buf; 00165 if (!buf) { 00166 ast_log(LOG_WARNING, "Out of memory\n"); 00167 return -1; 00168 } 00169 memcpy(buf, tdd->oldstuff, tdd->oldlen); 00170 mylen += tdd->oldlen / 2; 00171 for (x = 0; x < len; x++) 00172 buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]); 00173 c = res = 0; 00174 while (mylen >= 1320) { /* has to have enough to work on */ 00175 olen = mylen; 00176 res = fsk_serial(&tdd->fskd, buf, &mylen, &b); 00177 if (mylen < 0) { 00178 ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen); 00179 free(obuf); 00180 return -1; 00181 } 00182 buf += (olen - mylen); 00183 if (res < 0) { 00184 ast_log(LOG_NOTICE, "fsk_serial failed\n"); 00185 free(obuf); 00186 return -1; 00187 } 00188 if (res == 1) { 00189 /* Ignore invalid bytes */ 00190 if (b > 0x7f) 00191 continue; 00192 c = tdd_decode_baudot(tdd, b); 00193 if ((c < 1) || (c > 126)) 00194 continue; /* if not valid */ 00195 break; 00196 } 00197 } 00198 if (mylen) { 00199 memcpy(tdd->oldstuff, buf, mylen * 2); 00200 tdd->oldlen = mylen * 2; 00201 } else 00202 tdd->oldlen = 0; 00203 free(obuf); 00204 if (res) { 00205 tdd->mode = 2; 00206 /* put it in mode where it 00207 reliably puts teleprinter in correct shift mode */ 00208 return(c); 00209 } 00210 return 0; 00211 }
void tdd_free | ( | struct tdd_state * | tdd | ) |
int tdd_gen_holdtone | ( | unsigned char * | buf | ) |
Generate TDD hold tone
Definition at line 278 of file tdd.c.
References PUT_AUDIO_SAMPLE, and tdd_getcarrier().
00279 { 00280 int bytes = 0; 00281 float scont = 0.0, cr = 1.0, ci=0.0; 00282 while (scont < tddsb * 10.0) { 00283 PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); 00284 scont += 1.0; 00285 } 00286 return bytes; 00287 }
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 289 of file tdd.c.
References tdd_state::charnum, tdd_state::mode, and PUT_TDD.
Referenced by dahdi_sendtext().
00290 { 00291 int bytes = 0; 00292 int i,x; 00293 char c; 00294 /*! Baudot letters */ 00295 static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV"; 00296 /*! Baudot figures */ 00297 static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;"; 00298 /* Initial carriers (real/imaginary) */ 00299 float cr = 1.0; 00300 float ci = 0.0; 00301 float scont = 0.0; 00302 00303 for(x = 0; str[x]; x++) { 00304 /* Do synch for each 72th character */ 00305 if ( (tdd->charnum++) % 72 == 0) 00306 PUT_TDD(tdd->mode ? 27 /* FIGS */ : 31 /* LTRS */); 00307 00308 c = toupper(str[x]); 00309 #if 0 00310 printf("%c",c); fflush(stdout); 00311 #endif 00312 if (c == 0) { /* send null */ 00313 PUT_TDD(0); 00314 continue; 00315 } 00316 if (c == '\r') { /* send c/r */ 00317 PUT_TDD(8); 00318 continue; 00319 } 00320 if (c == '\n') { /* send c/r and l/f */ 00321 PUT_TDD(8); 00322 PUT_TDD(2); 00323 continue; 00324 } 00325 if (c == ' ') { /* send space */ 00326 PUT_TDD(4); 00327 continue; 00328 } 00329 for (i = 0; i < 31; i++) { 00330 if (lstr[i] == c) 00331 break; 00332 } 00333 if (i < 31) { /* if we found it */ 00334 if (tdd->mode) { /* if in figs mode, change it */ 00335 PUT_TDD(31); /* Send LTRS */ 00336 tdd->mode = 0; 00337 } 00338 PUT_TDD(i); 00339 continue; 00340 } 00341 for (i = 0; i < 31; i++) { 00342 if (fstr[i] == c) 00343 break; 00344 } 00345 if (i < 31) { /* if we found it */ 00346 if (tdd->mode != 1) { /* if in ltrs mode, change it */ 00347 PUT_TDD(27); /* send FIGS */ 00348 tdd->mode = 1; 00349 } 00350 PUT_TDD(i); /* send byte */ 00351 continue; 00352 } 00353 } 00354 return bytes; 00355 }
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().
00090 { 00091 /* Initialize stuff for inverse FFT */ 00092 dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0); 00093 di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0); 00094 dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0); 00095 di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0); 00096 }
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 98 of file tdd.c.
References ast_log(), calloc, fskmodem_init(), and LOG_WARNING.
Referenced by dahdi_setoption().
00099 { 00100 struct tdd_state *tdd; 00101 tdd = calloc(1, sizeof(*tdd)); 00102 if (tdd) { 00103 #ifdef INTEGER_CALLERID 00104 tdd->fskd.ispb = 176; /* 45.5 baud */ 00105 /* Set up for 45.5 / 8000 freq *32 to allow ints */ 00106 tdd->fskd.pllispb = (int)((8000 * 32 * 2) / 90); 00107 tdd->fskd.pllids = tdd->fskd.pllispb / 32; 00108 tdd->fskd.pllispb2 = tdd->fskd.pllispb / 2; 00109 tdd->fskd.hdlc = 0; /* Async */ 00110 tdd->fskd.nbit = 5; /* 5 bits */ 00111 tdd->fskd.instop = 1; /* integer rep of 1.5 stop bits */ 00112 tdd->fskd.parity = 0; /* No parity */ 00113 tdd->fskd.bw=0; /* Filter 75 Hz */ 00114 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00115 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00116 tdd->fskd.xi0 = 0; 00117 tdd->fskd.state = 0; 00118 tdd->pos = 0; 00119 tdd->mode = 0; 00120 fskmodem_init(&tdd->fskd); 00121 #else 00122 tdd->fskd.spb = 176; /* 45.5 baud */ 00123 tdd->fskd.hdlc = 0; /* Async */ 00124 tdd->fskd.nbit = 5; /* 5 bits */ 00125 tdd->fskd.nstop = 1.5; /* 1.5 stop bits */ 00126 tdd->fskd.parity = 0; /* No parity */ 00127 tdd->fskd.bw=0; /* Filter 75 Hz */ 00128 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00129 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00130 tdd->fskd.pcola = 0; /* No clue */ 00131 tdd->fskd.cont = 0; /* Digital PLL reset */ 00132 tdd->fskd.x0 = 0.0; 00133 tdd->fskd.state = 0; 00134 tdd->pos = 0; 00135 tdd->mode = 2; 00136 #endif 00137 tdd->charnum = 0; 00138 } else 00139 ast_log(LOG_WARNING, "Out of memory\n"); 00140 return tdd; 00141 }