?? tty_dec.c
字號:
/* purpose is prohibited. */
/* */
/*-------------------------------------------------------------------*/
#include <stdio.h>
#include "typedef.h"
#include "tty.h"
#include "basic_op.h"
#include "tty_dbg.h"
#define DEBUG_LEVEL 2
#define DEBUG(n,x) if( (n <= DEBUG_LEVEL || DEBUG_LEVEL < 0) && tty_debug_print_flag) {x}
Word16 counter_hist[TTY_BUF_SIZE];
Word16 char_hist[TTY_BUF_SIZE];
Word16 tty_rate_hist[TTY_BUF_SIZE];
/*Word16 debug_frame_counter = 0; */ /* for debugging only */
/*unsigned long tty_dec_char_count = 0;*/ /* Moved to tty_gen.c: for debugging only */
/***********************************************************************
* init_tty_dec()
************************************************************************/
void init_tty_dec()
{
Word16 i;
extern Word16 stop_bit_len[NUM_TTY_RATES];
extern Word16 data_bit_len[NUM_TTY_RATES];
data_bit_len[TTY_45_BAUD] = DATA_BIT_LEN_45_BAUD;
stop_bit_len[TTY_45_BAUD] = STOP_BIT_LEN_45_BAUD;
data_bit_len[TTY_50_BAUD] = DATA_BIT_LEN_50_BAUD;
stop_bit_len[TTY_50_BAUD] = STOP_BIT_LEN_50_BAUD;
for( i=0 ; i < TTY_BUF_SIZE ; i++ )
{
char_hist[i] = 0;
counter_hist[i] = NON_TTY;
tty_rate_hist[i] = DEFAULT_TTY_BAUD_RATE;
}
init_tty_gen(NON_TTY,0,0);
}
/***********************************************************************
* tty_dec()
************************************************************************/
Word16 tty_dec(
Word16 buf[],
Word16 acb_gain,
Word16 tty_header,
Word16 tty_char,
Word16 tty_baud_rate,
Word16 fer_flag,
Word16 subframe,
Word16 num_subfr,
Word16 length
)
{
Word16 counter;
Word16 error;
Word16 num;
Word16 best_num;
Word16 best_counter;
Word16 best_char;
Word16 best_rate;
Word16 i;
Word16 j;
/* Convert the received header values */
counter = tty_header;
tty_header_in( &counter );
if( subframe == 0 )
{
if( sub(fer_flag,1) == 0 )
{
DEBUG(1,fprintf(stdout,"Frame Error\n");)
counter_hist[0] = TTY_FER;
char_hist[0] = 0;
}
/* Detect if Baudot signal is being received */
else if( acb_gain != 0 )
{
counter_hist[0] = NON_TTY;
char_hist[0] = 0;
}
/* Sanity check the received information */
else if( (sub(counter,TTY_SILENCE) == 0 && sub(tty_char,TTY_SILENCE_CHAR) != 0)
|| (sub(counter,TTY_ONSET) == 0 && sub(tty_char,TTY_ONSET_CHAR) != 0)
|| sub(counter,TTY_COUNTER_MAX) > 0
|| sub(counter,TTY_COUNTER_MIN) < 0
|| sub(tty_char,TTY_CHAR_MAX) > 0
|| sub(tty_char,TTY_CHAR_MIN) < 0 )
{
counter_hist[0] = NON_TTY;
char_hist[0] = 0;
}
else
{
counter_hist[0] = counter;
char_hist[0] = tty_char;
tty_rate_hist[0] = tty_baud_rate;
}
/*----------------------------------------------------------------*/
DEBUG(1,
fprintf(stdout,"----------------------------------------\n");
for( i=0 ; i < TTY_BUF_SIZE ; i++ )
{
if( counter_hist[i] == NON_TTY )
fprintf(stdout,"( non )");
else if( counter_hist[i] == TTY_FER )
fprintf(stdout,"( FER )");
else if( counter_hist[i] == TTY_SILENCE && char_hist[i] == TTY_SILENCE_CHAR)
fprintf(stdout," slnce ");
else if( counter_hist[i] == TTY_ONSET && char_hist[i] == TTY_ONSET_CHAR)
fprintf(stdout," onset ");
else if( counter_hist[i] == TTY_EIGHTH_RATE )
fprintf(stdout,"( 8th )");
else
fprintf(stdout,"(%2d,%2d)",10*tty_rate_hist[i]+counter_hist[i],char_hist[i]);
}
fprintf(stdout,"__\n");
) /* end DEBUG() */
/*----------------------------------------------------------------*/
/*************************************************************
* The transition from NON_TTY to any TTY state must
* be voted on by the TTY FER handler. Hence all transitions
* away from NON_TTY is treated as a FER
* This cuts down on false alarms.
*************************************************************/
if( (counter_hist[CURRENT_FRAME] & (TTY_SILENCE|TTY_ONSET|COUNTER_BETWEEN_START_STOP)) != 0
&& sub(counter_hist[CURRENT_FRAME+1],NON_TTY) == 0
)
{
DEBUG(2,fprintf(stdout,"tty_dec(): Illegal transition, forcing FER...\n");)
counter_hist[CURRENT_FRAME] = TTY_FER;
char_hist[CURRENT_FRAME] = 0;
}
/*--------------------------------------------------------------
* Sanity check and correct FER in middle of character
*---------------------------------------------------------------*/
/*********************************************************************
* Check for the start of a new character detected or there is an FER
* at the beginning or end of a character. If it is a new character,
* make sure the next 8 frames have the same counter and
* character value. This corrects FERS in the middle of a
* character. If there is an FER at the transition of a character,
* then use the lookahead frames to vote on the most likely character.
***********************************************************************/
error = 0;
if( ( ( sub(counter_hist[CURRENT_FRAME],counter_hist[CURRENT_FRAME+1]) != 0
|| sub(char_hist[CURRENT_FRAME],char_hist[CURRENT_FRAME+1]) != 0)
&& (counter_hist[CURRENT_FRAME] & COUNTER_BETWEEN_START_STOP) != 0 )
|| sub(counter_hist[CURRENT_FRAME],TTY_FER) == 0
)
{
error = 1;
}
/* If an error was detected above, correct it */
if( error > 0 )
{
/* Look ahead 7 frames max for 50 baud */
error = 7;
if( tty_rate_hist[CURRENT_FRAME+1] == 0 )
{
/* Look ahead 8 frames max for 45.45 baud */
error = 8;
}
best_num = 2;
best_counter = counter_hist[CURRENT_FRAME+1];
best_char = char_hist[CURRENT_FRAME+1];
best_rate = tty_rate_hist[CURRENT_FRAME+1];
for( i=CURRENT_FRAME+1 ; i > sub(CURRENT_FRAME,error) ; i-- )
{
/* Exclude FERs from winning */
if( sub(counter_hist[i],TTY_FER) != 0 )
{
num = 0;
for( j=CURRENT_FRAME+1 ; j > CURRENT_FRAME-error ; j-- )
{
if( sub(counter_hist[i],counter_hist[j]) == 0
&& sub(char_hist[i],char_hist[j]) == 0
&& sub(tty_rate_hist[i],tty_rate_hist[j]) == 0 )
{
num = add(num,1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -