📄 tty_gen.c
字号:
Word16 char_hist[], /* (i/o): tty character history */
Word16 tty_rate_hist[] /* (i/o): tty baud rate history */
)
{
Word16 i;
Word16 num;
Word16 bit;
Word16 *p_buf;
Word16 write_flag;
bit = 0; /* eliminates compiler warning */
/* Change onset to silence */
if( sub(counter_hist[CURRENT_FRAME],TTY_ONSET) == 0 )
{
counter_hist[CURRENT_FRAME] = TTY_SILENCE;
char_hist[CURRENT_FRAME] = TTY_SILENCE_CHAR;
}
/* If transition from silence to anything else */
if( (current_counter & (TTY_SILENCE|NON_TTY)) != 0
&& sub(counter_hist[CURRENT_FRAME],TTY_SILENCE) != 0
)
{
init_tty_gen( counter_hist[CURRENT_FRAME],
char_hist[CURRENT_FRAME],
tty_rate_hist[CURRENT_FRAME]);
}
/* else if transition from NON_TTY to TTY_SILENCE */
else if( sub(current_counter,NON_TTY) == 0
&& sub(counter_hist[CURRENT_FRAME],TTY_SILENCE) == 0
)
{
init_tty_gen( TTY_SILENCE, TTY_SILENCE_CHAR, 0);
}
/* else if a new character is coming before the old one is finished */
else if( subframe == 0
&& sub(current_counter,counter_hist[CURRENT_FRAME]) != 0
&& (counter_hist[CURRENT_FRAME] & COUNTER_BETWEEN_START_STOP) != 0
)
{
if( sub(bit_num,MARK_HOLD_BIT_NUM) == 0 )
{
/* Cut short the mark hold tone to start new character */
init_tty_gen( counter_hist[CURRENT_FRAME],
char_hist[CURRENT_FRAME],
tty_rate_hist[CURRENT_FRAME]);
}
else if( sub(bit_num,STOP_BIT_NUM) == 0
&& sub(bit_size,FRAMESIZE) >= 0
)
{
/* Shorten the stop bit to 1 bit length if it will be done this frame */
data_bit_len[TTY_45_BAUD] = DATA_BIT_LEN_45_BAUD-4;
data_bit_len[TTY_50_BAUD] = DATA_BIT_LEN_50_BAUD-4;
bit_size = add(bit_size,data_bit_len[tty_rate_hist[CURRENT_FRAME]]);
bit_size = sub(bit_size,stop_bit_len[tty_rate_hist[CURRENT_FRAME]]);
}
else if( sub(bit_num,STOP_BIT_NUM) < 0 )
{
/*
* Shorten to 1 stop bit if next character comes before
* generating stop bit of current character.
*/
data_bit_len[TTY_45_BAUD] = DATA_BIT_LEN_45_BAUD-4;
data_bit_len[TTY_50_BAUD] = DATA_BIT_LEN_50_BAUD-4;
stop_bit_len[tty_rate_hist[CURRENT_FRAME]] = data_bit_len[tty_rate_hist[CURRENT_FRAME]];
}
} /* end if( falling behind) */
p_buf = outbuf;
num = length;
if( sub(bit_size,length) < 0 )
{
num = bit_size;
}
write_flag = 0;
while( num > 0 )
{
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* If current character non_tty, get out of loop */
if( sub(current_counter,NON_TTY) == 0 )
{
init_tty_gen(NON_TTY,0,0);
break;
}
/* else if silence, generate silence */
else if( sub(current_counter,TTY_SILENCE) == 0 )
{
for( i=0 ; i < num ; i++ )
{
p_buf[i] = 0;
}
init_tty_gen(TTY_SILENCE,TTY_SILENCE_CHAR,0); /* init in preparation for next char */
write_flag = 1;
}
else
{
bit = current_char & shl(1,bit_num);
if( bit == 0 )
{
bit = SPACE_FREQ;
}
else
{
bit = MARK_FREQ;
}
if( sub(bit,prev_bit) != 0 )
{
init_tone_gen(tone_param,bit);
}
tone_gen(p_buf,bit,BAUDOT_GAIN,num,tone_param);
write_flag = 1;
/* Update for next iteration */
p_buf += num;
bit_size = sub(bit_size,num);
if( sub(bit_size,1) < 0 ) /* if end of bit */
{
bit_num = add(bit_num,1);
/*
* If a new character immediately follows the
* current character, eliminate the mark hold tone.
*/
if( sub(bit_num,MARK_HOLD_BIT_NUM) == 0 )
{
/* Reset stop bit to 1.5 bits */
stop_bit_len[TTY_45_BAUD] = STOP_BIT_LEN_45_BAUD;
stop_bit_len[TTY_50_BAUD] = STOP_BIT_LEN_50_BAUD;
if( sub(current_counter,counter_hist[CURRENT_FRAME]) != 0
&& (counter_hist[CURRENT_FRAME] & COUNTER_BETWEEN_START_STOP) != 0
)
{
bit_num = add(bit_num,1);
}
}
if( sub(bit_num,MARK_HOLD_BIT_NUM) > 0 ) /* if end of character */
{
/* if start of silence */
if( sub(current_counter,counter_hist[CURRENT_FRAME]) == 0
|| sub(counter_hist[CURRENT_FRAME],NON_TTY) == 0 )
{
counter_hist[CURRENT_FRAME] = TTY_SILENCE;
char_hist[CURRENT_FRAME] = TTY_SILENCE_CHAR;
init_tty_gen(TTY_SILENCE,TTY_SILENCE_CHAR,0);
}
/* else... next character begins right away. */
else /* else start next character */
{
init_tty_gen( counter_hist[CURRENT_FRAME],
char_hist[CURRENT_FRAME],
tty_rate_hist[CURRENT_FRAME]);
}
}
else /* start of next bit */
{
if( sub(bit_num,STOP_BIT_NUM) == 0 )
{
bit_size = stop_bit_len[tty_rate_hist[CURRENT_FRAME+1]];
}
else if( sub(bit_num,MARK_HOLD_BIT_NUM) == 0 )
{
bit_size = MARK_HOLD_LEN;
}
else
{
bit_size = data_bit_len[tty_rate_hist[CURRENT_FRAME+1]];
}
DEBUG(2,printf("bit_num = %d bit_size = %d\n",bit_num,bit_size);)
}
}
} /* end if */
/* Update for next iteration */
prev_bit = bit;
length = sub(length,num);
num = length;
if( sub(bit_size,length) < 0 )
{
num = bit_size;
}
} /* end while */
/* Update history buffers for next iteration at the end of the frame */
if( sub(subframe,sub(num_subfr,1)) == 0 )
{
/* Put last generated character in history buffers */
if( sub(counter_hist[CURRENT_FRAME],current_counter) != 0 )
{
tty_rate_hist[CURRENT_FRAME] = tty_rate_hist[CURRENT_FRAME+1];
}
counter_hist[CURRENT_FRAME] = current_counter;
char_hist[CURRENT_FRAME] = shr(current_char,1) & DATA_BIT_MASK;
for( i=TTY_BUF_SIZE-1 ; i > 0 ; i-- )
{
counter_hist[i] = counter_hist[i-1];
char_hist[i] = char_hist[i-1];
tty_rate_hist[i] = tty_rate_hist[i-1];
}
/* During the mark hold, allow the next character to be generated */
if( sub(bit_num,MARK_HOLD_BIT_NUM) == 0 )
{
stop_bit_len[TTY_45_BAUD] = STOP_BIT_LEN_45_BAUD;
data_bit_len[TTY_45_BAUD] = DATA_BIT_LEN_45_BAUD;
stop_bit_len[TTY_50_BAUD] = STOP_BIT_LEN_50_BAUD;
data_bit_len[TTY_50_BAUD] = DATA_BIT_LEN_50_BAUD;
for( i=CURRENT_FRAME ; i >= 0 ; i-- )
{
/* Remove current_counter from history */
if( current_counter == counter_hist[i] )
{
counter_hist[i] = TTY_FER;
char_hist[i] = 0;
}
else
{
break;
}
}
}
}
return(write_flag);
} /* end tty_gen() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -