示例#1
0
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
{
	int a;
	int i, j, n1, r;
	int samples = 0;
	int olen;
	int beginlen = *len;
	int beginlenx;
	
	switch (fskd->state) {
		/* Pick up where we left off */
	case STATE_SEARCH_STARTBIT2:
		goto search_startbit2;
	case STATE_SEARCH_STARTBIT3:
		goto search_startbit3;
	case STATE_GET_BYTE:
		goto getbyte;
	}
	/* We await for start bit	*/
	do {
		/* this was jesus's nice, reasonable, working (at least with RTTY) code
		to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
		just start sending a start bit with nothing preceding it at the beginning
		of a transmission (what a LOSING design), we cant do it this elegantly */
		/* NOT USED
				if (demodulator(zap,&x1)) 
					return -1;
				for(;;) {
					if (demodulator(zap,&x2)) 
						return -1;
					if (x1>0 && x2<0) break;
					x1=x2;
				}
		*/
		/* this is now the imprecise, losing, but functional code to detect the
		beginning of a start bit in the TDD sceanario. It just looks for sufficient
		level to maybe, perhaps, guess, maybe that its maybe the beginning of
		a start bit, perhaps. This whole thing stinks! */
		beginlenx = beginlen; /* just to avoid unused war warnings */
		if (idemodulator(fskd, &fskd->xi1, IGET_SAMPLE))
			return -1;
		samples++;
		for(;;) {
search_startbit2:		   
			if (*len <= 0) {
				fskd->state = STATE_SEARCH_STARTBIT2;
				return 0;
			}
			samples++;
			if (idemodulator(fskd, &fskd->xi2, IGET_SAMPLE)) 
				return -1;
#if 0
			printf("xi2 = %d ", fskd->xi2);
#endif			
			if (fskd->xi2 < 512) {
				break;
			}
		}
search_startbit3:		   
		/* We await for 0.5 bits before using DPLL */
		i = fskd->ispb / 2;
		if (*len < i) {
			fskd->state = STATE_SEARCH_STARTBIT3;
			return 0;
		}
		for (; i > 0; i--) {
			if (idemodulator(fskd, &fskd->xi1, IGET_SAMPLE))
				return(-1); 
#if 0
			printf("xi1 = %d ", fskd->xi1);
#endif
			samples++; 
		}

		/* x1 must be negative (start bit confirmation) */

	} while (fskd->xi1 > 0);
	fskd->state = STATE_GET_BYTE;

getbyte:

	/* Need at least 80 samples (for 1200) or
		1320 (for 45.5) to be sure we'll have a byte */
	if (fskd->nbit < 8) {
		if (*len < 1320)
			return 0;
	} else {
		if (*len < 80)
			return 0;
	}

	/* Now we read the data bits */
	j = fskd->nbit;
	for (a = n1 = 0; j; j--) {
		olen = *len;
		i = get_bit_raw(fskd, buffer, len);
		buffer += (olen - *len);
		if (i == -1) 
			return -1;
		if (i) 
			n1++;
		a >>= 1; 
		a |= i;
	}
	j = 8 - fskd->nbit;
	a >>= j;

	/* We read parity bit (if exists) and check parity */
	if (fskd->parity) {
		olen = *len;
		i = get_bit_raw(fskd, buffer, len); 
		buffer += (olen - *len);
		if (i == -1) 
			return -1;
		if (i) 
			n1++;
		if (fskd->parity == 1) {	/* parity=1 (even) */
			if (n1 & 1) 
				a |= 0x100;			/* error */
		} else {					/* parity=2 (odd) */
			if (!(n1 & 1)) 
				a |= 0x100;			/* error */
		}
	}
	
	/* We read STOP bits. All of them must be 1 */
	
	for (j = fskd->instop; j; j--) {
		r = get_bit_raw(fskd, buffer, len);
		if (r == -1) 
			return -1;
		if (!r) 
			a |= 0x200;
	}

	/* And finally we return  
	 * Bit 8 : Parity error 
	 * Bit 9 : Framming error
	*/
		
	*outbyte = a;
	fskd->state = STATE_SEARCH_STARTBIT;
	return 1;
}
示例#2
0
int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
{
	int a;
	int i,j,n1,r;
	int samples=0;
	int olen;
	switch(fskd->state) {
		/* Pick up where we left off */
	case STATE_SEARCH_STARTBIT2:
		goto search_startbit2;
	case STATE_SEARCH_STARTBIT3:
		goto search_startbit3;
	case STATE_GET_BYTE:
		goto getbyte;
	}
	/* Esperamos bit de start	*/
	do {
/* this was jesus's nice, reasonable, working (at least with RTTY) code
to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
just start sending a start bit with nothing preceding it at the beginning
of a transmission (what a LOSING design), we cant do it this elegantly */
/*
		if (demodulador(zap,&x1)) return(-1);
		for(;;) {
			if (demodulador(zap,&x2)) return(-1);
			if (x1>0 && x2<0) break;
			x1=x2;
		}
*/
/* this is now the imprecise, losing, but functional code to detect the
beginning of a start bit in the TDD sceanario. It just looks for sufficient
level to maybe, perhaps, guess, maybe that its maybe the beginning of
a start bit, perhaps. This whole thing stinks! */
		if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
		samples++;
		for(;;)
		   {
search_startbit2:		   
			if (!*len) {
				fskd->state = STATE_SEARCH_STARTBIT2;
				return 0;
			}
			samples++;
			if (demodulador(fskd,&fskd->x2,GET_SAMPLE)) return(-1);
#if 0
			printf("x2 = %5.5f ", fskd->x2);
#endif			
			if (fskd->x2 < -0.5) break; 
		   }
search_startbit3:		   
		/* Esperamos 0.5 bits antes de usar DPLL */
		i=fskd->spb/2;
		if (*len < i) {
			fskd->state = STATE_SEARCH_STARTBIT3;
			return 0;
		}
		for(;i;i--) { if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1); 
#if 0
			printf("x1 = %5.5f ", fskd->x1);
#endif			
	samples++; }

		/* x1 debe ser negativo (confirmación del bit de start) */

	} while (fskd->x1>0);
	fskd->state = STATE_GET_BYTE;

getbyte:

	/* Need at least 80 samples (for 1200) or
		1320 (for 45.5) to be sure we'll have a byte */
	if (fskd->nbit < 8) {
		if (*len < 1320)
			return 0;
	} else {
		if (*len < 80)
			return 0;
	}
	/* Leemos ahora los bits de datos */
	j=fskd->nbit;
	for (a=n1=0;j;j--) {
		olen = *len;
		i=get_bit_raw(fskd, buffer, len);
		buffer += (olen - *len);
		if (i == -1) return(-1);
		if (i) n1++;
		a>>=1; a|=i;
	}
	j=8-fskd->nbit;
	a>>=j;

	/* Leemos bit de paridad (si existe) y la comprobamos */
	if (fskd->paridad) {
		olen = *len;
		i=get_bit_raw(fskd, buffer, len); 
		buffer += (olen - *len);
		if (i == -1) return(-1);
		if (i) n1++;
		if (fskd->paridad==1) {	/* paridad=1 (par) */
			if (n1&1) a|=0x100;		/* error */
		} else {			/* paridad=2 (impar) */
			if (!(n1&1)) a|=0x100;	/* error */
		}
	}
	
	/* Leemos bits de STOP. Todos deben ser 1 */
	
	for (j=fskd->nstop;j;j--) {
		r = get_bit_raw(fskd, buffer, len);
		if (r == -1) return(-1);
		if (!r) a|=0x200;
	}

	/* Por fin retornamos  */
	/* Bit 8 : Error de paridad */
	/* Bit 9 : Error de Framming */

	*outbyte = a;
	fskd->state = STATE_SEARCH_STARTBIT;
	return 1;
}