Wed Jan 8 2020 09:50:12

Asterisk developer's documentation


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

#define NCOLA   0x4000

Definition at line 32 of file fskmodem_int.h.

#define PARITY_EVEN   1

Definition at line 28 of file fskmodem_int.h.

#define PARITY_NONE   0

Definition at line 27 of file fskmodem_int.h.

#define PARITY_ODD   2

Definition at line 29 of file fskmodem_int.h.

Function Documentation

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

Definition at line 226 of file fskmodem_float.c.

References 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.

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

Definition at line 197 of file fskmodem_int.c.

References fsk_data::bw, 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().

198 {
199  int i;
200 
201  fskd->space_filter.ip = 0;
202  fskd->mark_filter.ip = 0;
203  fskd->demod_filter.ip = 0;
204 
205  for ( i = 0 ; i < 7 ; i++ ) {
206  fskd->space_filter.icoefs[i] =
207  coef_in[fskd->f_space_idx][fskd->bw][i] * 256;
208  fskd->space_filter.ixv[i] = 0;;
209  fskd->space_filter.iyv[i] = 0;;
210 
211  fskd->mark_filter.icoefs[i] =
212  coef_in[fskd->f_mark_idx][fskd->bw][i] * 256;
213  fskd->mark_filter.ixv[i] = 0;;
214  fskd->mark_filter.iyv[i] = 0;;
215 
216  fskd->demod_filter.icoefs[i] =
217  coef_out[fskd->bw][i] * 1024;
218  fskd->demod_filter.ixv[i] = 0;;
219  fskd->demod_filter.iyv[i] = 0;;
220  }
221  return 0;
222 }
static double coef_out[NBW][8]
Coefficients for output filter Coefficients table, generated by program &quot;mkfilter&quot; Format: coef[IDX_B...
Definition: fskmodem_int.c:90
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 &quot;mkfilter&quot; mkfilter is part o...
Definition: fskmodem_int.c:68
struct ast_framehook_interface i
Definition: framehook.c:40
int f_mark_idx
struct filter_struct mark_filter
Definition: fskmodem_int.h:63