#include "asterisk.h"
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <ctype.h>
#include "asterisk/ulaw.h"
#include "asterisk/tdd.h"
#include "asterisk/logger.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_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 index = (short)(rint(8192.0 * (y))); \ *(buf++) = AST_LIN2MU(index); \ bytes++; \ } while(0)
#define PUT_BYTE | ( | a | ) |
Value:
do { \ *(buf++) = (a); \ bytes++; \ } while(0)
Definition at line 216 of file tdd.c.
Referenced by ast_callerid_vmwi_generate(), and callerid_generate().
#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 | |||
) |
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 127 of file tdd.c.
References ecdisa, and tdd_state::pos.
Referenced by dahdi_setoption().
00128 { 00129 int pos = 0; 00130 int cnt; 00131 while (len) { 00132 cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len; 00133 memcpy(outbuf + pos, ecdisa, cnt); 00134 pos += cnt; 00135 len -= cnt; 00136 } 00137 return 0; 00138 }
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 switch (data) { 00077 case 0x1f: 00078 tdd->modo = 0; 00079 break; 00080 case 0x1b: 00081 tdd->modo = 1; 00082 break; 00083 default: 00084 if (tdd->modo == 0) 00085 d = ltrs[data]; 00086 else 00087 d = figs[data]; 00088 break; 00089 } 00090 return d; 00091 }
int tdd_feed | ( | struct tdd_state * | tdd, | |
unsigned char * | ubuf, | |||
int | samples | |||
) |
tdd | Which state machine to act upon | |
ubuf | containing your samples | |
samples | number of samples contained within the buffer. |
Definition at line 140 of file tdd.c.
References ast_log(), AST_MULAW, calloc, free, fsk_serie(), tdd_state::fskd, LOG_ERROR, LOG_NOTICE, LOG_WARNING, tdd_state::mode, tdd_state::oldlen, tdd_state::oldstuff, and tdd_decode_baudot().
00141 { 00142 int mylen = len; 00143 int olen; 00144 int b = 'X'; 00145 int res; 00146 int c,x; 00147 short *buf = calloc(1, 2 * len + tdd->oldlen); 00148 short *obuf = buf; 00149 if (!buf) { 00150 ast_log(LOG_WARNING, "Out of memory\n"); 00151 return -1; 00152 } 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_serial 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_serial 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)) 00178 continue; /* if not valid */ 00179 break; 00180 } 00181 } 00182 if (mylen) { 00183 memcpy(tdd->oldstuff, buf, mylen * 2); 00184 tdd->oldlen = mylen * 2; 00185 } else 00186 tdd->oldlen = 0; 00187 free(obuf); 00188 if (res) { 00189 tdd->mode = 2; 00190 /* put it in mode where it 00191 reliably puts teleprinter in correct shift mode */ 00192 return(c); 00193 } 00194 return 0; 00195 }
void tdd_free | ( | struct tdd_state * | tdd | ) |
int tdd_generate | ( | struct tdd_state * | tdd, | |
unsigned char * | buf, | |||
const char * | string | |||
) |
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 261 of file tdd.c.
References tdd_state::charnum, tdd_state::mode, and PUT_TDD.
Referenced by dahdi_sendtext().
00262 { 00263 int bytes=0; 00264 int i,x; 00265 char c; 00266 /*! Baudot letters */ 00267 static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV"; 00268 /*! Baudot figures */ 00269 static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;"; 00270 /* Initial carriers (real/imaginary) */ 00271 float cr = 1.0; 00272 float ci = 0.0; 00273 float scont = 0.0; 00274 00275 for(x = 0; str[x]; x++) { 00276 /* Do synch for each 72th character */ 00277 if ( (tdd->charnum++) % 72 == 0) 00278 PUT_TDD(tdd->mode ? 27 /* FIGS */ : 31 /* LTRS */); 00279 00280 c = toupper(str[x]); 00281 #if 0 00282 printf("%c",c); fflush(stdout); 00283 #endif 00284 if (c == 0) { /* send null */ 00285 PUT_TDD(0); 00286 continue; 00287 } 00288 if (c == '\r') { /* send c/r */ 00289 PUT_TDD(8); 00290 continue; 00291 } 00292 if (c == '\n') { /* send c/r and l/f */ 00293 PUT_TDD(8); 00294 PUT_TDD(2); 00295 continue; 00296 } 00297 if (c == ' ') { /* send space */ 00298 PUT_TDD(4); 00299 continue; 00300 } 00301 for (i = 0; i < 31; i++) { 00302 if (lstr[i] == c) 00303 break; 00304 } 00305 if (i < 31) { /* if we found it */ 00306 if (tdd->mode) { /* if in figs mode, change it */ 00307 PUT_TDD(31); /* Send LTRS */ 00308 tdd->mode = 0; 00309 } 00310 PUT_TDD(i); 00311 continue; 00312 } 00313 for (i = 0; i < 31; i++) { 00314 if (fstr[i] == c) 00315 break; 00316 } 00317 if (i < 31) { /* if we found it */ 00318 if (tdd->mode != 1) { /* if in ltrs mode, change it */ 00319 PUT_TDD(27); /* send FIGS */ 00320 tdd->mode = 1; 00321 } 00322 PUT_TDD(i); /* send byte */ 00323 continue; 00324 } 00325 } 00326 return bytes; 00327 }
static float tdd_getcarrier | ( | float * | cr, | |
float * | ci, | |||
int | bit | |||
) | [inline, static] |
Definition at line 202 of file tdd.c.
References t.
00203 { 00204 /* Move along. There's nothing to see here... */ 00205 float t; 00206 t = *cr * dr[bit] - *ci * di[bit]; 00207 *ci = *cr * di[bit] + *ci * dr[bit]; 00208 *cr = t; 00209 00210 t = 2.0 - (*cr * *cr + *ci * *ci); 00211 *cr *= t; 00212 *ci *= t; 00213 return *cr; 00214 }
void tdd_init | ( | void | ) |
Initializes the TDD system. Mostly stuff for inverse FFT
Definition at line 93 of file tdd.c.
References TDD_MARK, and TDD_SPACE.
Referenced by main().
00094 { 00095 /* Initialize stuff for inverse FFT */ 00096 dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0); 00097 di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0); 00098 dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0); 00099 di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0); 00100 }
struct tdd_state* tdd_new | ( | void | ) |
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 102 of file tdd.c.
References ast_log(), calloc, and LOG_WARNING.
Referenced by dahdi_setoption().
00103 { 00104 struct tdd_state *tdd; 00105 tdd = calloc(1, sizeof(*tdd)); 00106 if (tdd) { 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 = 0; 00121 tdd->charnum = 0; 00122 } else 00123 ast_log(LOG_WARNING, "Out of memory\n"); 00124 return tdd; 00125 }
float di[4] [static] |
Definition at line 59 of file tdd.c.
Referenced by dialed_interface_destroy(), dialed_interface_duplicate(), and try_calling().
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().