Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions
fskmodem_int.h File Reference

FSK Modem Support. More...

Go to the source code of this file.

Data Structures

struct  filter_struct
 
struct  fsk_data
 

Macros

#define NCOLA   0x4000
 
#define PARITY_EVEN   1
 
#define PARITY_NONE   0
 
#define PARITY_ODD   2
 

Functions

int fsk_serial (fsk_data *fskd, short *buffer, int *len, int *outbyte)
 
int fskmodem_init (fsk_data *fskd)
 

Detailed Description

FSK Modem Support.

Note
Includes code and algorithms from the Zapata library.

Definition in file fskmodem_int.h.

Macro Definition Documentation

◆ NCOLA

#define NCOLA   0x4000

Definition at line 32 of file fskmodem_int.h.

◆ PARITY_EVEN

#define PARITY_EVEN   1

Definition at line 28 of file fskmodem_int.h.

◆ PARITY_NONE

#define PARITY_NONE   0

Definition at line 27 of file fskmodem_int.h.

◆ PARITY_ODD

#define PARITY_ODD   2

Definition at line 29 of file fskmodem_int.h.

Function Documentation

◆ fsk_serial()

int fsk_serial ( fsk_data fskd,
short *  buffer,
int *  len,
int *  outbyte 
)

Definition at line 224 of file fskmodem_float.c.

References a, demodulator(), get_bit_raw(), GET_SAMPLE, idemodulator(), IGET_SAMPLE, fsk_data::instop, fsk_data::ispb, len(), fsk_data::nbit, fsk_data::nstop, fsk_data::parity, ast_frame::samples, fsk_data::spb, fsk_data::state, STATE_GET_BYTE, STATE_SEARCH_STARTBIT, STATE_SEARCH_STARTBIT2, STATE_SEARCH_STARTBIT3, fsk_data::x1, fsk_data::x2, fsk_data::xi1, and fsk_data::xi2.

225 {
226  int a;
227  int i,j,n1,r;
228  int samples = 0;
229  int olen;
230 
231  switch (fskd->state) {
232  /* Pick up where we left off */
234  goto search_startbit2;
236  goto search_startbit3;
237  case STATE_GET_BYTE:
238  goto getbyte;
239  }
240  /* We await for start bit */
241  do {
242  /* this was jesus's nice, reasonable, working (at least with RTTY) code
243  to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
244  just start sending a start bit with nothing preceding it at the beginning
245  of a transmission (what a LOSING design), we cant do it this elegantly */
246  /*
247  if (demodulator(zap,&x1)) return(-1);
248  for (;;) {
249  if (demodulator(zap,&x2)) return(-1);
250  if (x1>0 && x2<0) break;
251  x1 = x2;
252  }
253  */
254  /* this is now the imprecise, losing, but functional code to detect the
255  beginning of a start bit in the TDD sceanario. It just looks for sufficient
256  level to maybe, perhaps, guess, maybe that its maybe the beginning of
257  a start bit, perhaps. This whole thing stinks! */
258  if (demodulator(fskd, &fskd->x1, GET_SAMPLE))
259  return -1;
260  samples++;
261  for (;;) {
262 search_startbit2:
263  if (*len <= 0) {
265  return 0;
266  }
267  samples++;
268  if (demodulator(fskd, &fskd->x2, GET_SAMPLE))
269  return(-1);
270 #if 0
271  printf("x2 = %5.5f ", fskd->x2);
272 #endif
273  if (fskd->x2 < -0.5)
274  break;
275  }
276 search_startbit3:
277  /* We await for 0.5 bits before using DPLL */
278  i = fskd->spb/2;
279  if (*len < i) {
281  return 0;
282  }
283  for (; i>0; i--) {
284  if (demodulator(fskd, &fskd->x1, GET_SAMPLE))
285  return(-1);
286 #if 0
287  printf("x1 = %5.5f ", fskd->x1);
288 #endif
289  samples++;
290  }
291 
292  /* x1 must be negative (start bit confirmation) */
293 
294  } while (fskd->x1 > 0);
295  fskd->state = STATE_GET_BYTE;
296 
297 getbyte:
298 
299  /* Need at least 80 samples (for 1200) or
300  1320 (for 45.5) to be sure we'll have a byte */
301  if (fskd->nbit < 8) {
302  if (*len < 1320)
303  return 0;
304  } else {
305  if (*len < 80)
306  return 0;
307  }
308  /* Now we read the data bits */
309  j = fskd->nbit;
310  for (a = n1 = 0; j; j--) {
311  olen = *len;
312  i = get_bit_raw(fskd, buffer, len);
313  buffer += (olen - *len);
314  if (i == -1)
315  return(-1);
316  if (i)
317  n1++;
318  a >>= 1;
319  a |= i;
320  }
321  j = 8-fskd->nbit;
322  a >>= j;
323 
324  /* We read parity bit (if exists) and check parity */
325  if (fskd->parity) {
326  olen = *len;
327  i = get_bit_raw(fskd, buffer, len);
328  buffer += (olen - *len);
329  if (i == -1)
330  return(-1);
331  if (i)
332  n1++;
333  if (fskd->parity == 1) { /* parity=1 (even) */
334  if (n1&1)
335  a |= 0x100; /* error */
336  } else { /* parity=2 (odd) */
337  if (!(n1&1))
338  a |= 0x100; /* error */
339  }
340  }
341 
342  /* We read STOP bits. All of them must be 1 */
343 
344  for (j = fskd->nstop;j;j--) {
345  r = get_bit_raw(fskd, buffer, len);
346  if (r == -1)
347  return(-1);
348  if (!r)
349  a |= 0x200;
350  }
351 
352  /* And finally we return */
353  /* Bit 8 : Parity error */
354  /* Bit 9 : Framming error*/
355 
356  *outbyte = a;
358  return 1;
359 }
#define STATE_SEARCH_STARTBIT3
float nstop
#define STATE_SEARCH_STARTBIT2
static int demodulator(fsk_data *fskd, float *retval, float x)
#define STATE_GET_BYTE
static int get_bit_raw(fsk_data *fskd, short *buffer, int *len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define STATE_SEARCH_STARTBIT
struct ast_framehook_interface i
Definition: framehook.c:38
#define GET_SAMPLE
static struct test_val a

◆ fskmodem_init()

int fskmodem_init ( fsk_data fskd)

Definition at line 195 of file fskmodem_int.c.

References fsk_data::bw, coef_in, coef_out, fsk_data::demod_filter, fsk_data::f_mark_idx, fsk_data::f_space_idx, filter_struct::icoefs, filter_struct::ip, filter_struct::ixv, filter_struct::iyv, fsk_data::mark_filter, and fsk_data::space_filter.

Referenced by callerid_new(), and tdd_new().

196 {
197  int i;
198 
199  fskd->space_filter.ip = 0;
200  fskd->mark_filter.ip = 0;
201  fskd->demod_filter.ip = 0;
202 
203  for ( i = 0 ; i < 7 ; i++ ) {
204  fskd->space_filter.icoefs[i] =
205  coef_in[fskd->f_space_idx][fskd->bw][i] * 256;
206  fskd->space_filter.ixv[i] = 0;;
207  fskd->space_filter.iyv[i] = 0;;
208 
209  fskd->mark_filter.icoefs[i] =
210  coef_in[fskd->f_mark_idx][fskd->bw][i] * 256;
211  fskd->mark_filter.ixv[i] = 0;;
212  fskd->mark_filter.iyv[i] = 0;;
213 
214  fskd->demod_filter.icoefs[i] =
215  coef_out[fskd->bw][i] * 1024;
216  fskd->demod_filter.ixv[i] = 0;;
217  fskd->demod_filter.iyv[i] = 0;;
218  }
219  return 0;
220 }
static double coef_out[NBW][8]
Coefficients for output filter Coefficients table, generated by program "mkfilter" Format: coef[IDX_B...
Definition: fskmodem_int.c:88
struct filter_struct demod_filter
Definition: fskmodem_int.h:65
struct filter_struct space_filter
Definition: fskmodem_int.h:64
int f_space_idx
static double coef_in[NF][NBW][8]
Coefficients for input filters Coefficients table, generated by program "mkfilter" mkfilter is part o...
Definition: fskmodem_int.c:66
struct ast_framehook_interface i
Definition: framehook.c:38
int f_mark_idx
struct filter_struct mark_filter
Definition: fskmodem_int.h:63