#include "asterisk.h"
#include <stdio.h>
#include "asterisk/fskmodem.h"
Go to the source code of this file.
Defines | |
#define | BWLIST {75,800} |
#define | FLIST {1400,1800,1200,2200,1300,2100} |
#define | GET_SAMPLE get_sample(&buffer, len) |
#define | NBW 2 |
#define | NF 6 |
#define | STATE_GET_BYTE 3 |
#define | STATE_SEARCH_STARTBIT 0 |
#define | STATE_SEARCH_STARTBIT2 1 |
#define | STATE_SEARCH_STARTBIT3 2 |
Functions | |
static int | demodulator (fsk_data *fskd, float *retval, float x) |
static float | filterL (fsk_data *fskd, float in) |
static float | filterM (fsk_data *fskd, float in) |
static float | filterS (fsk_data *fskd, float in) |
int | fsk_serial (fsk_data *fskd, short *buffer, int *len, int *outbyte) |
static int | get_bit_raw (fsk_data *fskd, short *buffer, int *len) |
static float | get_sample (short **buffer, int *len) |
Variables | |
static double | coef_in [NF][NBW][8] |
Coefficients for input filters Coefficients table, generated by program "mkfilter" mkfilter is part of the zapatatelephony.org distribution Format: coef[IDX_FREC][IDX_BW][IDX_COEF] IDX_COEF = 0 => 1/GAIN IDX_COEF = 1-6 => Coefficientes y[n]. | |
static double | coef_out [NBW][8] |
Coefficients for output filter Coefficients table, generated by program "mkfilter" Format: coef[IDX_BW][IDX_COEF] IDX_COEF = 0 => 1/GAIN IDX_COEF = 1-6 => Coefficientes y[n]. |
Definition in file fskmodem_float.c.
#define BWLIST {75,800} |
Definition at line 44 of file fskmodem_float.c.
#define FLIST {1400,1800,1200,2200,1300,2100} |
Definition at line 46 of file fskmodem_float.c.
#define GET_SAMPLE get_sample(&buffer, len) |
#define NBW 2 |
Definition at line 43 of file fskmodem_float.c.
#define NF 6 |
Definition at line 45 of file fskmodem_float.c.
#define STATE_GET_BYTE 3 |
#define STATE_SEARCH_STARTBIT 0 |
Definition at line 48 of file fskmodem_float.c.
#define STATE_SEARCH_STARTBIT2 1 |
#define STATE_SEARCH_STARTBIT3 2 |
static int demodulator | ( | fsk_data * | fskd, | |
float * | retval, | |||
float | x | |||
) | [inline, static] |
Definition at line 171 of file fskmodem_float.c.
References fsk_data::cola_demod, fsk_data::cola_filter, fsk_data::cola_in, filterL(), filterM(), filterS(), NCOLA, and fsk_data::pcola.
Referenced by fsk_serial(), and get_bit_raw().
00172 { 00173 float xS,xM; 00174 00175 fskd->cola_in[fskd->pcola] = x; 00176 00177 xS = filterS(fskd,x); 00178 xM = filterM(fskd,x); 00179 00180 fskd->cola_filter[fskd->pcola] = xM-xS; 00181 00182 x = filterL(fskd,xM*xM - xS*xS); 00183 00184 fskd->cola_demod[fskd->pcola++] = x; 00185 fskd->pcola &= (NCOLA-1); 00186 00187 *retval = x; 00188 return 0; 00189 }
static float filterL | ( | fsk_data * | fskd, | |
float | in | |||
) | [inline, static] |
Low-pass filter for demodulated data
Definition at line 149 of file fskmodem_float.c.
References fsk_data::bw, fsk_data::flp, fsk_data::flxv, and fsk_data::flyv.
Referenced by demodulator().
00150 { 00151 int i, j; 00152 double s; 00153 double *pc; 00154 00155 pc = &coef_out[fskd->bw][0]; 00156 fskd->flxv[(fskd->flp + 6) & 7] = in * (*pc++); 00157 00158 s = (fskd->flxv[fskd->flp] + fskd->flxv[(fskd->flp+6)&7]) + 00159 6 * (fskd->flxv[(fskd->flp+1)&7] + fskd->flxv[(fskd->flp+5)&7]) + 00160 15 * (fskd->flxv[(fskd->flp+2)&7] + fskd->flxv[(fskd->flp+4)&7]) + 00161 20 * fskd->flxv[(fskd->flp+3)&7]; 00162 00163 for (i = 0,j = fskd->flp;i<6;i++,j++) 00164 s += fskd->flyv[j&7]*(*pc++); 00165 fskd->flyv[j&7] = s; 00166 fskd->flp++; 00167 fskd->flp &= 7; 00168 return s; 00169 }
static float filterM | ( | fsk_data * | fskd, | |
float | in | |||
) | [inline, static] |
Band-pass filter for MARK frequency
Definition at line 111 of file fskmodem_float.c.
References fsk_data::bw, fsk_data::f_mark_idx, fsk_data::fmp, fsk_data::fmxv, and fsk_data::fmyv.
Referenced by demodulator().
00112 { 00113 int i, j; 00114 double s; 00115 double *pc; 00116 00117 pc = &coef_in[fskd->f_mark_idx][fskd->bw][0]; 00118 fskd->fmxv[(fskd->fmp+6)&7] = in*(*pc++); 00119 00120 s = (fskd->fmxv[(fskd->fmp + 6) & 7] - fskd->fmxv[fskd->fmp]) + 3 * (fskd->fmxv[(fskd->fmp + 2) & 7] - fskd->fmxv[(fskd->fmp + 4) & 7]); 00121 for (i = 0, j = fskd->fmp; i < 6; i++, j++) 00122 s += fskd->fmyv[j&7]*(*pc++); 00123 fskd->fmyv[j&7] = s; 00124 fskd->fmp++; 00125 fskd->fmp &= 7; 00126 return s; 00127 }
static float filterS | ( | fsk_data * | fskd, | |
float | in | |||
) | [inline, static] |
Band-pass filter for SPACE frequency
Definition at line 130 of file fskmodem_float.c.
References fsk_data::bw, fsk_data::f_space_idx, fsk_data::fsp, fsk_data::fsxv, and fsk_data::fsyv.
Referenced by demodulator().
00131 { 00132 int i, j; 00133 double s; 00134 double *pc; 00135 00136 pc = &coef_in[fskd->f_space_idx][fskd->bw][0]; 00137 fskd->fsxv[(fskd->fsp+6)&7] = in*(*pc++); 00138 00139 s = (fskd->fsxv[(fskd->fsp + 6) & 7] - fskd->fsxv[fskd->fsp]) + 3 * (fskd->fsxv[(fskd->fsp + 2) & 7] - fskd->fsxv[(fskd->fsp + 4) & 7]); 00140 for (i = 0, j = fskd->fsp; i < 6; i++, j++) 00141 s += fskd->fsyv[j&7]*(*pc++); 00142 fskd->fsyv[j&7] = s; 00143 fskd->fsp++; 00144 fskd->fsp &= 7; 00145 return s; 00146 }
int fsk_serial | ( | fsk_data * | fskd, | |
short * | buffer, | |||
int * | len, | |||
int * | outbyte | |||
) |
Definition at line 226 of file fskmodem_float.c.
References demodulator(), GET_SAMPLE, fsk_data::nbit, ast_frame::samples, fsk_data::spb, fsk_data::state, STATE_GET_BYTE, STATE_SEARCH_STARTBIT2, STATE_SEARCH_STARTBIT3, fsk_data::x1, and fsk_data::x2.
00227 { 00228 int a; 00229 int i,j,n1,r; 00230 int samples = 0; 00231 int olen; 00232 00233 switch (fskd->state) { 00234 /* Pick up where we left off */ 00235 case STATE_SEARCH_STARTBIT2: 00236 goto search_startbit2; 00237 case STATE_SEARCH_STARTBIT3: 00238 goto search_startbit3; 00239 case STATE_GET_BYTE: 00240 goto getbyte; 00241 } 00242 /* We await for start bit */ 00243 do { 00244 /* this was jesus's nice, reasonable, working (at least with RTTY) code 00245 to look for the beginning of the start bit. Unfortunately, since TTY/TDD's 00246 just start sending a start bit with nothing preceding it at the beginning 00247 of a transmission (what a LOSING design), we cant do it this elegantly */ 00248 /* 00249 if (demodulator(zap,&x1)) return(-1); 00250 for (;;) { 00251 if (demodulator(zap,&x2)) return(-1); 00252 if (x1>0 && x2<0) break; 00253 x1 = x2; 00254 } 00255 */ 00256 /* this is now the imprecise, losing, but functional code to detect the 00257 beginning of a start bit in the TDD sceanario. It just looks for sufficient 00258 level to maybe, perhaps, guess, maybe that its maybe the beginning of 00259 a start bit, perhaps. This whole thing stinks! */ 00260 if (demodulator(fskd, &fskd->x1, GET_SAMPLE)) 00261 return -1; 00262 samples++; 00263 for (;;) { 00264 search_startbit2: 00265 if (*len <= 0) { 00266 fskd->state = STATE_SEARCH_STARTBIT2; 00267 return 0; 00268 } 00269 samples++; 00270 if (demodulator(fskd, &fskd->x2, GET_SAMPLE)) 00271 return(-1); 00272 #if 0 00273 printf("x2 = %5.5f ", fskd->x2); 00274 #endif 00275 if (fskd->x2 < -0.5) 00276 break; 00277 } 00278 search_startbit3: 00279 /* We await for 0.5 bits before using DPLL */ 00280 i = fskd->spb/2; 00281 if (*len < i) { 00282 fskd->state = STATE_SEARCH_STARTBIT3; 00283 return 0; 00284 } 00285 for (; i>0; i--) { 00286 if (demodulator(fskd, &fskd->x1, GET_SAMPLE)) 00287 return(-1); 00288 #if 0 00289 printf("x1 = %5.5f ", fskd->x1); 00290 #endif 00291 samples++; 00292 } 00293 00294 /* x1 must be negative (start bit confirmation) */ 00295 00296 } while (fskd->x1 > 0); 00297 fskd->state = STATE_GET_BYTE; 00298 00299 getbyte: 00300 00301 /* Need at least 80 samples (for 1200) or 00302 1320 (for 45.5) to be sure we'll have a byte */ 00303 if (fskd->nbit < 8) { 00304 if (*len < 1320) 00305 return 0; 00306 } else { 00307 if (*len < 80) 00308 return 0; 00309 } 00310 /* Now we read the data bits */ 00311 j = fskd->nbit; 00312 for (a = n1 = 0; j; j--) { 00313 olen = *len; 00314 i = get_bit_raw(fskd, buffer, len); 00315 buffer += (olen - *len); 00316 if (i == -1) 00317 return(-1); 00318 if (i) 00319 n1++; 00320 a >>= 1; 00321 a |= i; 00322 } 00323 j = 8-fskd->nbit; 00324 a >>= j; 00325 00326 /* We read parity bit (if exists) and check parity */ 00327 if (fskd->parity) { 00328 olen = *len; 00329 i = get_bit_raw(fskd, buffer, len); 00330 buffer += (olen - *len); 00331 if (i == -1) 00332 return(-1); 00333 if (i) 00334 n1++; 00335 if (fskd->parity == 1) { /* parity=1 (even) */ 00336 if (n1&1) 00337 a |= 0x100; /* error */ 00338 } else { /* parity=2 (odd) */ 00339 if (!(n1&1)) 00340 a |= 0x100; /* error */ 00341 } 00342 } 00343 00344 /* We read STOP bits. All of them must be 1 */ 00345 00346 for (j = fskd->nstop;j;j--) { 00347 r = get_bit_raw(fskd, buffer, len); 00348 if (r == -1) 00349 return(-1); 00350 if (!r) 00351 a |= 0x200; 00352 } 00353 00354 /* And finally we return */ 00355 /* Bit 8 : Parity error */ 00356 /* Bit 9 : Framming error*/ 00357 00358 *outbyte = a; 00359 fskd->state = STATE_SEARCH_STARTBIT; 00360 return 1; 00361 }
static int get_bit_raw | ( | fsk_data * | fskd, | |
short * | buffer, | |||
int * | len | |||
) | [static] |
Definition at line 191 of file fskmodem_float.c.
References fsk_data::cont, demodulator(), f, GET_SAMPLE, fsk_data::spb, and fsk_data::x0.
00192 { 00193 /* This function implements a DPLL to synchronize with the bits */ 00194 float x,spb,spb2,ds; 00195 int f; 00196 00197 spb = fskd->spb; 00198 if (fskd->spb == 7) 00199 spb = 8000.0 / 1200.0; 00200 ds = spb/32.; 00201 spb2 = spb/2.; 00202 00203 for (f = 0;;) { 00204 if (demodulator(fskd, &x, GET_SAMPLE)) 00205 return -1; 00206 if ((x * fskd->x0) < 0) { /* Transition */ 00207 if (!f) { 00208 if (fskd->cont<(spb2)) 00209 fskd->cont += ds; 00210 else 00211 fskd->cont -= ds; 00212 f = 1; 00213 } 00214 } 00215 fskd->x0 = x; 00216 fskd->cont += 1.; 00217 if (fskd->cont > spb) { 00218 fskd->cont -= spb; 00219 break; 00220 } 00221 } 00222 f = (x > 0) ? 0x80 : 0; 00223 return f; 00224 }
static float get_sample | ( | short ** | buffer, | |
int * | len | |||
) | [inline, static] |
Definition at line 53 of file fskmodem_float.c.
00054 { 00055 float retval; 00056 retval = (float) **buffer / 256; 00057 (*buffer)++; 00058 (*len)--; 00059 return retval; 00060 };
double coef_in[NF][NBW][8] [static] |
Coefficients for input filters Coefficients table, generated by program "mkfilter" mkfilter is part of the zapatatelephony.org distribution Format: coef[IDX_FREC][IDX_BW][IDX_COEF] IDX_COEF = 0 => 1/GAIN IDX_COEF = 1-6 => Coefficientes y[n].
Definition at line 71 of file fskmodem_float.c.
Referenced by fskmodem_init().
double coef_out[NBW][8] [static] |
Initial value:
{ { 1.3868644653e-08,-6.3283665042e-01,4.0895057217e+00,-1.1020074592e+01,1.5850766191e+01,-1.2835109292e+01,5.5477477340e+00,0.0000000000e+00, }, { 3.1262119724e-03,-7.8390522307e-03,8.5209627801e-02,-4.0804129163e-01,1.1157139955e+00,-1.8767603680e+00,1.8916395224e+00,0.0000000000e+00, }, }
Definition at line 104 of file fskmodem_float.c.
Referenced by fskmodem_init().