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

FSK Modem Support. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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)
 

Detailed Description

FSK Modem Support.

Note
Includes code and algorithms from the Zapata library.

Definition in file fskmodem_float.h.

Macro Definition Documentation

◆ NCOLA

#define NCOLA   0x4000

Definition at line 32 of file fskmodem_float.h.

Referenced by demodulator().

◆ PARITY_EVEN

#define PARITY_EVEN   1

Definition at line 28 of file fskmodem_float.h.

◆ PARITY_NONE

#define PARITY_NONE   0

Definition at line 27 of file fskmodem_float.h.

◆ PARITY_ODD

#define PARITY_ODD   2

Definition at line 29 of file fskmodem_float.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.

Referenced by callerid_feed(), callerid_feed_jp(), and tdd_feed().

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