Asterisk - The Open Source Telephony Project GIT-master-773870a
Loading...
Searching...
No Matches
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)
 Retrieve a serial byte into outbyte. Buffer is a pointer into a series of shorts and len records the number of bytes in the buffer. len will be overwritten with the number of bytes left that were not consumed.
 

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.

◆ 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 
)

Retrieve a serial byte into outbyte. Buffer is a pointer into a series of shorts and len records the number of bytes in the buffer. len will be overwritten with the number of bytes left that were not consumed.

Return values
0Still looking for something...
1An output byte was received and stored in outbyte
-1An error occured in the transmission He must be called with at least 80 bytes of buffer.

Definition at line 224 of file fskmodem_float.c.

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

References a, demodulator(), get_bit_raw(), GET_SAMPLE, len(), fsk_data::nbit, fsk_data::nstop, fsk_data::parity, fsk_data::spb, fsk_data::state, STATE_GET_BYTE, STATE_SEARCH_STARTBIT, STATE_SEARCH_STARTBIT2, STATE_SEARCH_STARTBIT3, fsk_data::x1, and fsk_data::x2.

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