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_generate (struct tdd_state *tdd, unsigned char *buf, const char *string) |
void | tdd_init (void) |
struct 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 diable 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 126 of file tdd.c.
References ecdisa, and tdd_state::pos.
00127 { 00128 int pos = 0; 00129 int cnt; 00130 while (len) { 00131 cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len; 00132 memcpy(outbuf + pos, ecdisa, cnt); 00133 pos += cnt; 00134 len -= cnt; 00135 } 00136 return 0; 00137 }
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 139 of file tdd.c.
References ast_log(), AST_MULAW, free, fsk_serie(), tdd_state::fskd, LOG_ERROR, LOG_NOTICE, LOG_WARNING, malloc, tdd_state::mode, tdd_state::oldlen, tdd_state::oldstuff, and tdd_decode_baudot().
00140 { 00141 int mylen = len; 00142 int olen; 00143 int b = 'X'; 00144 int res; 00145 int c,x; 00146 short *buf = malloc(2 * len + tdd->oldlen); 00147 short *obuf = buf; 00148 if (!buf) { 00149 ast_log(LOG_WARNING, "Out of memory\n"); 00150 return -1; 00151 } 00152 memset(buf, 0, 2 * len + tdd->oldlen); 00153 memcpy(buf, tdd->oldstuff, tdd->oldlen); 00154 mylen += tdd->oldlen/2; 00155 for (x = 0; x < len; x++) 00156 buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]); 00157 c = res = 0; 00158 while (mylen >= 1320) { /* has to have enough to work on */ 00159 olen = mylen; 00160 res = fsk_serie(&tdd->fskd, buf, &mylen, &b); 00161 if (mylen < 0) { 00162 ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d) (olen was %d)\n", mylen, olen); 00163 free(obuf); 00164 return -1; 00165 } 00166 buf += (olen - mylen); 00167 if (res < 0) { 00168 ast_log(LOG_NOTICE, "fsk_serie failed\n"); 00169 free(obuf); 00170 return -1; 00171 } 00172 if (res == 1) { 00173 /* Ignore invalid bytes */ 00174 if (b > 0x7f) 00175 continue; 00176 c = tdd_decode_baudot(tdd,b); 00177 if ((c < 1) || (c > 126)) continue; /* if not valid */ 00178 break; 00179 } 00180 } 00181 if (mylen) { 00182 memcpy(tdd->oldstuff, buf, mylen * 2); 00183 tdd->oldlen = mylen * 2; 00184 } else 00185 tdd->oldlen = 0; 00186 free(obuf); 00187 if (res) { 00188 tdd->mode = 2; /* put it in mode where it 00189 reliably puts teleprinter in correct shift mode */ 00190 return(c); 00191 } 00192 return 0; 00193 }
void tdd_free | ( | struct tdd_state * | tdd | ) |
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) |
Definition at line 259 of file tdd.c.
References tdd_state::mode, and PUT_TDD.
00260 { 00261 int bytes=0; 00262 int i,x; 00263 char c; 00264 static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV"; 00265 static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?&\000./;"; 00266 /* Initial carriers (real/imaginary) */ 00267 float cr = 1.0; 00268 float ci = 0.0; 00269 float scont = 0.0; 00270 00271 for(x = 0; str[x]; x++) { 00272 c = toupper(str[x]); 00273 #if 0 00274 printf("%c",c); fflush(stdout); 00275 #endif 00276 if (c == 0) { /* send null */ 00277 PUT_TDD(0); 00278 continue; 00279 } 00280 if (c == '\r') { /* send c/r */ 00281 PUT_TDD(8); 00282 continue; 00283 } 00284 if (c == '\n') { /* send c/r and l/f */ 00285 PUT_TDD(8); 00286 PUT_TDD(2); 00287 continue; 00288 } 00289 if (c == ' ') { /* send space */ 00290 PUT_TDD(4); 00291 continue; 00292 } 00293 for (i = 0; i < 31; i++) { 00294 if (lstr[i] == c) 00295 break; 00296 } 00297 if (i < 31) { /* if we found it */ 00298 if (tdd->mode) { /* if in figs mode, change it */ 00299 PUT_TDD(31); /* Send LTRS */ 00300 tdd->mode = 0; 00301 } 00302 PUT_TDD(i); 00303 continue; 00304 } 00305 for (i = 0; i < 31; i++) { 00306 if (fstr[i] == c) 00307 break; 00308 } 00309 if (i < 31) { /* if we found it */ 00310 if (tdd->mode != 1) { /* if in ltrs mode, change it */ 00311 PUT_TDD(27); /* send FIGS */ 00312 tdd->mode = 1; 00313 } 00314 PUT_TDD(i); /* send byte */ 00315 continue; 00316 } 00317 } 00318 return bytes; 00319 }
void tdd_init | ( | void | ) |
CallerID Initialization
Initializes the TDD system. Mostly stuff for inverse FFT
Definition at line 92 of file tdd.c.
References TDD_MARK, and TDD_SPACE.
00093 { 00094 /* Initialize stuff for inverse FFT */ 00095 dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0); 00096 di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0); 00097 dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0); 00098 di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0); 00099 }
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 101 of file tdd.c.
References ast_log(), fsk_data::bw, fsk_data::cont, fsk_data::f_mark_idx, fsk_data::f_space_idx, tdd_state::fskd, fsk_data::hdlc, LOG_WARNING, malloc, tdd_state::mode, fsk_data::nbit, fsk_data::nstop, fsk_data::paridad, fsk_data::pcola, tdd_state::pos, fsk_data::spb, fsk_data::state, and fsk_data::x0.
00102 { 00103 struct tdd_state *tdd; 00104 tdd = malloc(sizeof(struct tdd_state)); 00105 if (tdd) { 00106 memset(tdd, 0, sizeof(struct tdd_state)); 00107 tdd->fskd.spb = 176; /* 45.5 baud */ 00108 tdd->fskd.hdlc = 0; /* Async */ 00109 tdd->fskd.nbit = 5; /* 5 bits */ 00110 tdd->fskd.nstop = 1.5; /* 1.5 stop bits */ 00111 tdd->fskd.paridad = 0; /* No parity */ 00112 tdd->fskd.bw=0; /* Filter 75 Hz */ 00113 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00114 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00115 tdd->fskd.pcola = 0; /* No clue */ 00116 tdd->fskd.cont = 0; /* Digital PLL reset */ 00117 tdd->fskd.x0 = 0.0; 00118 tdd->fskd.state = 0; 00119 tdd->pos = 0; 00120 tdd->mode = 2; 00121 } else 00122 ast_log(LOG_WARNING, "Out of memory\n"); 00123 return tdd; 00124 }