📄 demod_hamaro.c
字号:
}
/*****************************************************************************/
/* FUNCTION: hamaro_connected_state */
/* */
/* PARAMETERS: unit - the unit to process in the CONNECTED state. */
/* pending - the mask of currently pending interrupts. */
/* old - the previous acquisition state. */
/* new - the new (current) acquisition state. */
/* */
/* DESCRIPTION: This function implements the processing required on receipt */
/* of an interrupt in the CONNECTED state. */
/* */
/* RETURNS: Nothing. */
/* */
/* CONTEXT: Will be run in task context. */
/* */
/*****************************************************************************/
static void hamaro_connected_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
DEMOD_CALLBACK_DATA parm;
trace_new( TL_FUNC, "CONNECTED state processing for unit %d\n", unit );
/* If we got a loss of sync interrupt, and the new acquisition state is not
locked and tracking, then we will transition to the signal fade state. */
if ( new != ACQ_LOCKED_AND_TRACKING )
{
trace_new( TL_FUNC, "Switching to FADE state for unit %d\n", unit );
local_state[unit] = FADE;
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_DRIVER_LOST_SIGNAL;
callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
}
}
}
/*****************************************************************************/
/* FUNCTION: hamaro_scanning_state */
/* */
/* PARAMETERS: unit - the unit to process in the SCANNING state. */
/* pending - the mask of currently pending interrupts. */
/* old - the previous acquisition state. */
/* new - the new (current) acquisition state. */
/* */
/* DESCRIPTION: This function implements the processing required on receipt */
/* of an interrupt in the SCANNING state. */
/* */
/* RETURNS: Nothing. */
/* */
/* CONTEXT: Will be run in task context. */
/* */
/*****************************************************************************/
static void hamaro_scanning_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
int rc;
DEMOD_CALLBACK_DATA parm;
u_int32 msg[4];
int return_code;
CODERATE coderate;
trace_new( TL_FUNC, "SCANNING state processing for unit %d\n", unit );
/* If we got an acquisition interrupt, and the new acquisition state is
either locked and tracking or fade, then we will transition to the
connected state. */
if ( (new == ACQ_LOCKED_AND_TRACKING) || (new == ACQ_FADE) )
{
local_state[unit] = CONNECTED;
rc = tick_stop( hHamaroTick[unit] );
if ( rc != RC_OK )
{
trace_new( TL_ERROR, "Hamaro can't stop tick timer!\n" );
error_log( ERROR_WARNING | RC_SDM_SYSERR );
}
API_GetViterbiRate( &NIMs[unit], &coderate );
local_tuning[unit].tune.nim_satellite_tune.fec = xlat_fec_out( coderate );
trace_new( TL_FUNC, "Switching to CONNECTED state for unit %d\n", unit );
trace_new( TL_VERBOSE, "There were %d acquisition failures\n", DEMOD_SCAN_COUNTDOWN-acq_failure_countdown[unit] );
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_SCAN_COMPLETE;
callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
}
}
/* Either we got an acquisition interrupt, but the new acquisition state is
neither locked and tracking nor fade, or we got an acquisition failure;
count down to determine status. */
else
{
/* If not completely through, reset the interrupt and keep going. */
if ( acq_failure_countdown[unit] )
{
--acq_failure_countdown[unit];
}
/* Enough is enough; try something else or give up completely. */
else
{
/* Send a control message to the Hamaro demod task to signal the timeout. */
msg[0] = unit;
msg[1] = msg[2] = 0;
msg[3] = HAMARO_TIMEOUT;
return_code = qu_send( hamaro_message_q, msg );
if (return_code != RC_OK)
{
trace_new( TL_ERROR, "Hamaro can't send message in hamaro_scanning_state!\n" );
error_log( ERROR_WARNING | RC_SDM_QFULL );
global_timeout_flag |= (unit == 0) ? 1 : 2;
}
}
}
}
/*****************************************************************************/
/* FUNCTION: hamaro_fade_state */
/* */
/* PARAMETERS: unit - the unit to process in the FADE state. */
/* pending - the mask of currently pending interrupts. */
/* old - the previous acquisition state. */
/* new - the new (current) acquisition state. */
/* */
/* DESCRIPTION: This function implements the processing required on receipt */
/* of an interrupt in the FADE state. */
/* */
/* RETURNS: Nothing. */
/* */
/* CONTEXT: Will be run in task context. */
/* */
/*****************************************************************************/
static void hamaro_fade_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
DEMOD_CALLBACK_DATA parm;
trace_new( TL_FUNC, "FADE state processing for unit %d\n", unit );
/* If we got an acquisition interrupt, and the new acquisition state is
locked and tracking, then we will transition to the connected state. */
if ( new == ACQ_LOCKED_AND_TRACKING )
{
local_state[unit] = CONNECTED;
trace_new( TL_FUNC, "Switching to CONNECTED state for unit %d\n", unit );
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_DRIVER_REACQUIRED_SIGNAL;
callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
}
}
}
/*****************************************************************************/
/* FUNCTION: hamaro_timeout_msg */
/* */
/* PARAMETERS: unit - the unit that experienced the timeout. */
/* */
/* DESCRIPTION: This function implements the processing required on receipt */
/* of a TIMEOUT message. */
/* */
/* RETURNS: Nothing. */
/* */
/* CONTEXT: Will be run in task context. */
/* */
/*****************************************************************************/
static void hamaro_timeout_msg( u_int32 unit )
{
DEMOD_CALLBACK_DATA parm;
int more_scanning = 1;
CHANOBJ chan;
BOOL APIresult;
int rc;
int api_error;
CMPLXNO esno;
MSTATUS status;
trace_new( TL_FUNC, "New Hamaro timeout message for unit %d\n", unit );
switch( local_state[unit] )
{
case CONNECTING:
local_state[unit] = CONT_CONNECTING;
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_FAILED;
callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
}
break;
case SCANNING:
/* Since we timed out in SCANNING, check to see if there are more
settings to try before we declare failure. */
if ( ++scan_parms[unit].current_symbol_rate >= local_scan[unit].scan.satellite.num_symrates )
{
scan_parms[unit].current_symbol_rate = 0;
scan_parms[unit].current_frequency += local_scan[unit].scan.satellite.hop_value;
if ( scan_parms[unit].current_frequency > local_scan[unit].scan.satellite.end_frequency )
{
scan_parms[unit].current_frequency = local_scan[unit].scan.satellite.start_frequency;
if ( ++scan_parms[unit].current_polarity >= local_scan[unit].scan.satellite.num_pols )
{
local_state[unit] = DISCONNECTED;
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_SCAN_NO_SIGNAL;
callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
}
more_scanning = 0;
}
}
}
/* More to try, so set up the next tuning operation and let fly. */
if ( more_scanning )
{
local_scan[unit].current.tune.nim_satellite_tune.symbol_rate = local_symrates[unit][scan_parms[unit].current_symbol_rate];
local_scan[unit].current.tune.nim_satellite_tune.frequency = scan_parms[unit].current_frequency;
local_scan[unit].current.tune.nim_satellite_tune.polarisation = local_polarizations[unit][scan_parms[unit].current_polarity];
local_tuning[unit] = local_scan[unit].current;
cnxt_set_lnb( &NIMs[unit], &(local_scan[unit].current), &chan.frequency );
chan.modtype = MOD_QPSK;
chan.coderate = xlat_fec_in( local_scan[unit].current.tune.nim_satellite_tune.fec );
chan.symbrate = local_scan[unit].current.tune.nim_satellite_tune.symbol_rate;
chan.specinv = SPEC_INV_ON_BOTH; /* Fix me! wjj */
//chan.samplerate = SAMPLE_FREQ_NOM;
chan.viterbicoderates = local_viterbis[unit];
/* Make sure all interrupts (including acq_fail) are reset, then
call API_ChangeChannel to accomplish the tuning. */
API_AcqBegin( &NIMs[unit] );
acq_failure_countdown[unit] = DEMOD_SCAN_COUNTDOWN;
APIresult = API_ChangeChannel( &NIMs[unit], &chan );
if ( APIresult )
{
trace_new( TL_VERBOSE, "API_ChangeChannel succeeded for unit %d\n", unit );
/* Start the demod monitoring signal quality. */
if ( !API_GetChannelEsNo( &NIMs[0], ESNOMODE_SNAPSHOT, &esno, &status ) )
{
trace_new( TL_ERROR, "API_GetChannelEsNo failed\n" );
trace_new( TL_ERROR, "File: %s, line: %d\n", API_GetErrorFilename(&NIMs[0]), API_GetErrorLineNumber(&NIMs[0]) );
api_error = API_GetLastError( &NIMs[0] );
trace_new( TL_ERROR, "Error %d, %s\n", api_error, API_GetErrorMessage(&NIMs[0], (APIERRNO)api_error) );
}
rc = tick_set( hHamaroTick[unit], HAMARO_SCANNING_TIMEOUT, TRUE );
if ( rc != RC_OK )
{
trace_new( TL_ERROR, "Hamaro can't set tick timer for scan continue!\n" );
error_log( ERROR_FATAL | RC_SDM_SYSERR );
}
else
{
rc = tick_start( hHamaroTick[unit] );
if ( rc != RC_OK )
{
trace_new( TL_ERROR, "Hamaro can't start tick timer for scan continue!\n" );
error_log( ERROR_FATAL | RC_SDM_SYSERR );
}
}
}
else
{
trace_new( TL_ERROR, "API_ChangeChannel failed for unit %d\n", unit );
trace_new( TL_ERROR, "File: %s, line: %d\n", API_GetErrorFilename(&NIMs[unit]), API_GetErrorLineNumber(&NIMs[unit]) );
api_error = API_GetLastError( &NIMs[unit] );
trace_new( TL_ERROR, "Error %d, %s\n", api_error, API_GetErrorMessage(&NIMs[unit], (APIERRNO)api_error) );
if ( callbacks[unit] )
{
parm.parm.type = DEMOD_FAILED;
callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
}
}
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -