# HG changeset patch # User paul # Date 2016-05-24 14:10:34 # Node ID a907a62ed869eaa0449d274e387f3594c3c9d8dd # Parent 3e4133f0e255deffa3086d30246de7f91f5bd40d PAS filtering implemented diff --git a/.hgsubstate b/.hgsubstate --- a/.hgsubstate +++ b/.hgsubstate @@ -1,2 +1,2 @@ 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters -dad8371a5549f3395f975fddc33098b05fd829f4 header/lfr_common_headers +2450d4935652a4d0370245cc7fc60a4c51e6fc9b header/lfr_common_headers diff --git a/FSW-qt/fsw-qt.pro b/FSW-qt/fsw-qt.pro --- a/FSW-qt/fsw-qt.pro +++ b/FSW-qt/fsw-qt.pro @@ -10,7 +10,7 @@ TEMPLATE = app # debug_tch # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\ # debug_watchdog -CONFIG += console verbose lpp_dpu_destid +CONFIG += console verbose lpp_dpu_destid cpu_usage_report CONFIG -= qt include(./sparc.pri) diff --git a/header/processing/fsw_processing.h b/header/processing/fsw_processing.h --- a/header/processing/fsw_processing.h +++ b/header/processing/fsw_processing.h @@ -80,6 +80,8 @@ typedef struct asm_msg unsigned int fineTimeNORM; unsigned int coarseTimeSBM; unsigned int fineTimeSBM; + unsigned int numberOfSMInASMNORM; + unsigned int numberOfSMInASMSBM; } asm_msg; extern unsigned char thisIsAnASMRestart; @@ -87,6 +89,7 @@ extern unsigned char thisIsAnASMRestart; extern volatile int sm_f0[ ]; extern volatile int sm_f1[ ]; extern volatile int sm_f2[ ]; +extern unsigned int acquisitionDurations[]; // parameters extern struct param_local_str param_local; @@ -145,12 +148,7 @@ extern rtems_status_code get_message_que static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, ring_node *ring_node_tab[], unsigned int nbAverageNORM, unsigned int nbAverageSBM, - asm_msg *msgForMATR ); - -static inline void SM_average_debug(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, - ring_node *ring_node_tab[], - unsigned int nbAverageNORM, unsigned int nbAverageSBM, - asm_msg *msgForMATR ); + asm_msg *msgForMATR , unsigned char channel); void ASM_patch( float *inputASM, float *outputASM ); @@ -165,24 +163,52 @@ static inline void ASM_compress_reorgani static inline void ASM_convert(volatile float *input_matrix, char *output_matrix); +unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel); + void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, ring_node *ring_node_tab[], unsigned int nbAverageNORM, unsigned int nbAverageSBM, - asm_msg *msgForMATR ) + asm_msg *msgForMATR, unsigned char channel ) { float sum; unsigned int i; + unsigned int k; + unsigned char incomingSMIsValid[8]; + unsigned int numberOfValidSM; + unsigned char isValid; + //************** + // PAS FILTERING + // check acquisitionTime of the incoming data + numberOfValidSM = 0; + for (k=0; k<8; k++) + { + isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel ); + incomingSMIsValid[k] = isValid; + numberOfValidSM = numberOfValidSM + isValid; + } + + //************************ + // AVERAGE SPECTRAL MATRIX for(i=0; ibuffer_address) ) [ i ] - + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ]; +// sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] +// + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ]; + + sum = ( (incomingSMIsValid[0] == 1) ? ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[1] == 1) ? ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[2] == 1) ? ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[3] == 1) ? ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[4] == 1) ? ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[5] == 1) ? ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[6] == 1) ? ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] : 0.0 ) + + ( (incomingSMIsValid[7] == 1) ? ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ] : 0.0 ); if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) ) { @@ -214,25 +240,28 @@ void SM_average( float *averaged_spec_ma // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM) } } -} -void SM_average_debug( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, - ring_node *ring_node_tab[], - unsigned int nbAverageNORM, unsigned int nbAverageSBM, - asm_msg *msgForMATR ) -{ - float sum; - unsigned int i; - - for(i=0; inumberOfSMInASMNORM = numberOfValidSM; + msgForMATR->numberOfSMInASMSBM = numberOfValidSM; + } + else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) ) { - sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]; - averaged_spec_mat_NORM[ i ] = sum; - averaged_spec_mat_SBM[ i ] = sum; - msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime; - msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime; - msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime; - msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime; + msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM; + msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM; + } + else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) ) + { + msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM; + msgForMATR->numberOfSMInASMSBM = numberOfValidSM; + } + else + { + msgForMATR->numberOfSMInASMNORM = numberOfValidSM; + msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM; } } @@ -255,7 +284,7 @@ void ASM_reorganize_and_divide( float *a asmComponent * NB_BINS_PER_SM + frequencyBin; averaged_spec_mat_reorganized[offsetASMReorganized ] = - averaged_spec_mat[ offsetASM ] / divider; + (divider != 0.0) ? averaged_spec_mat[ offsetASM ] / divider : 0.0; } } } diff --git a/python_scripts/EQM_setup.py b/python_scripts/EQM_setup.py deleted file mode 100644 --- a/python_scripts/EQM_setup.py +++ /dev/null @@ -1,31 +0,0 @@ -import time - -proxy.loadSysDriver("SpwPlugin","SpwPlugin0") -SpwPlugin0.selectBridge("STAR-Dundee Spw USB Brick") - -proxy.loadSysDriverToParent("dsu3plugin","SpwPlugin0") -proxy.loadSysDriverToParent("LFRControlPlugin","SpwPlugin0") - -availableBrickCount = SpwPlugin0.StarDundeeGetAvailableBrickCount() -print str(availableBrickCount) + " SpaceWire brick(s) found" - -SpwPlugin0.StarDundeeSelectBrick(1) -SpwPlugin0.StarDundeeSetBrickAsARouter(1) -SpwPlugin0.StarDundeeSelectLinkNumber( 1 ) -SpwPlugin0.connectBridge() - -#SpwPlugin0.TCPServerSetIP("127.0.0.1") -SpwPlugin0.TCPServerConnect() - -# OPEN SPACEWIRE SERVER -#LFRControlPlugin0.SetSpwServerIP(129,104,27,164) -LFRControlPlugin0.TCPServerConnect() - -# OPEN TM ECHO BRIDGE SERVER -LFRControlPlugin0.TMEchoBridgeOpenPort() - -# START SENDING TIMECODES AT 1 Hz -SpwPlugin0.StarDundeeStartTimecodes( 1 ) - -# it is possible to change the time code frequency -#RMAPPlugin0.changeTimecodeFrequency(2) diff --git a/python_scripts/LFRControlPlugin_reload_fsw.py b/python_scripts/LFRControlPlugin_reload_fsw.py deleted file mode 100644 --- a/python_scripts/LFRControlPlugin_reload_fsw.py +++ /dev/null @@ -1,14 +0,0 @@ -# LOAD FSW USING LINK 1 -SpwPlugin0.StarDundeeSelectLinkNumber( 1 ) - -dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw") -#dsu3plugin0.openFile("/opt/LFR/LFR-FSW/2.0.2.3/fsw") -dsu3plugin0.loadFile() - -dsu3plugin0.run() - -# START SENDING TIMECODES AT 1 Hz -#SpwPlugin0.StarDundeeStartTimecodes( 1 ) - -# it is possible to change the time code frequency -#RMAPPlugin0.changeTimecodeFrequency(2) diff --git a/src/fsw_globals.c b/src/fsw_globals.c --- a/src/fsw_globals.c +++ b/src/fsw_globals.c @@ -93,3 +93,4 @@ float cp_rpw_sc_rw4_f2; float sy_lfr_sc_rw_delta_f; fbins_masks_t fbins_masks; +unsigned int acquisitionDurations[3] = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2}; diff --git a/src/processing/avf0_prc0.c b/src/processing/avf0_prc0.c --- a/src/processing/avf0_prc0.c +++ b/src/processing/avf0_prc0.c @@ -98,7 +98,7 @@ rtems_task avf0_task( rtems_task_argumen current_ring_node_asm_burst_sbm_f0->matrix, ring_node_tab, nb_norm_bp1, nb_sbm_bp1, - &msgForPRC ); + &msgForPRC, 0 ); // 0 => frequency channel 0 // update nb_average nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0; @@ -195,6 +195,8 @@ rtems_task prc0_task( rtems_task_argumen bp_packet packet_sbm_bp1; bp_packet packet_sbm_bp2; ring_node *current_ring_node_to_send_asm_f0; + float nbSMInASMNORM; + float nbSMInASMSBM; // init the ring of the averaged spectral matrices which will be transmitted to the DPU init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM ); @@ -265,6 +267,9 @@ rtems_task prc0_task( rtems_task_argumen ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm ); ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm ); + nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; + nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM; + //**************** //**************** // BURST SBM1 SBM2 @@ -275,7 +280,7 @@ rtems_task prc0_task( rtems_task_argumen sid = getSID( incomingMsg->event ); // 1) compress the matrix for Basic Parameters calculation ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0, - nb_sm_before_f0.burst_sbm_bp1, + nbSMInASMSBM, NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0, ASM_F0_INDICE_START, CHANNELF0); // 2) compute the BP1 set @@ -313,7 +318,7 @@ rtems_task prc0_task( rtems_task_argumen { // 1) compress the matrix for Basic Parameters calculation ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0, - nb_sm_before_f0.norm_bp1, + nbSMInASMNORM, NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, ASM_F0_INDICE_START, CHANNELF0 ); // 2) compute the BP1 set @@ -346,7 +351,7 @@ rtems_task prc0_task( rtems_task_argumen // 1) reorganize the ASM and divide ASM_reorganize_and_divide( asm_f0_patched_norm, (float*) current_ring_node_to_send_asm_f0->buffer_address, - nb_sm_before_f0.norm_bp1 ); + nbSMInASMNORM ); current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM; current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM; current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0; diff --git a/src/processing/avf1_prc1.c b/src/processing/avf1_prc1.c --- a/src/processing/avf1_prc1.c +++ b/src/processing/avf1_prc1.c @@ -99,7 +99,7 @@ rtems_task avf1_task( rtems_task_argumen current_ring_node_asm_burst_sbm_f1->matrix, ring_node_tab, nb_norm_bp1, nb_sbm_bp1, - &msgForPRC ); + &msgForPRC, 1 ); // 1 => frequency channel 1 // update nb_average nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1; @@ -196,8 +196,8 @@ rtems_task prc1_task( rtems_task_argumen bp_packet packet_sbm_bp1; bp_packet packet_sbm_bp2; ring_node *current_ring_node_to_send_asm_f1; - - unsigned long long int localTime; + float nbSMInASMNORM; + float nbSMInASMSBM; // init the ring of the averaged spectral matrices which will be transmitted to the DPU init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM ); @@ -259,7 +259,9 @@ rtems_task prc1_task( rtems_task_argumen ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm ); ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm ); - localTime = getTimeAsUnsignedLongLongInt( ); + nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; + nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM; + //*********** //*********** // BURST SBM2 @@ -270,7 +272,7 @@ rtems_task prc1_task( rtems_task_argumen sid = getSID( incomingMsg->event ); // 1) compress the matrix for Basic Parameters calculation ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1, - nb_sm_before_f1.burst_sbm_bp1, + nbSMInASMSBM, NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1, ASM_F1_INDICE_START, CHANNELF1); // 2) compute the BP1 set @@ -308,7 +310,7 @@ rtems_task prc1_task( rtems_task_argumen { // 1) compress the matrix for Basic Parameters calculation ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1, - nb_sm_before_f1.norm_bp1, + nbSMInASMNORM, NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1, ASM_F1_INDICE_START, CHANNELF1 ); // 2) compute the BP1 set @@ -341,7 +343,7 @@ rtems_task prc1_task( rtems_task_argumen // 1) reorganize the ASM and divide ASM_reorganize_and_divide( asm_f1_patched_norm, (float*) current_ring_node_to_send_asm_f1->buffer_address, - nb_sm_before_f1.norm_bp1 ); + nbSMInASMNORM ); current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM; current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM; current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1; diff --git a/src/processing/avf2_prc2.c b/src/processing/avf2_prc2.c --- a/src/processing/avf2_prc2.c +++ b/src/processing/avf2_prc2.c @@ -143,6 +143,7 @@ rtems_task prc2_task( rtems_task_argumen bp_packet packet_norm_bp1; bp_packet packet_norm_bp2; ring_node *current_ring_node_to_send_asm_f2; + float nbSMInASMNORM; unsigned long long int localTime; @@ -182,14 +183,16 @@ rtems_task prc2_task( rtems_task_argumen localTime = getTimeAsUnsignedLongLongInt( ); + nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM; + //***** //***** // NORM //***** //***** - // 1) compress the matrix for Basic Parameters calculation + // 1) compress the matrix for Basic Parameters calculation ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2, - nb_sm_before_f2.norm_bp1, + nbSMInASMNORM, NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, ASM_F2_INDICE_START, CHANNELF2 ); // BP1_F2 @@ -258,19 +261,60 @@ void SM_average_f2( float *averaged_spec { float sum; unsigned int i; + unsigned char keepMatrix; + + // test acquisitionTime validity + keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, 2 ); for(i=0; ibuffer_address) ) [ i ]; - if ( (nbAverageNormF2 == 0) ) + if ( (nbAverageNormF2 == 0) ) // average initialization { - averaged_spec_mat_f2[ i ] = sum; + if (keepMatrix == 1) // keep the matrix and add it to the average + { + averaged_spec_mat_f2[ i ] = sum; + } + else // drop the matrix and initialize the average + { + averaged_spec_mat_f2[ i ] = 0.; + } msgForMATR->coarseTimeNORM = ring_node->coarseTime; msgForMATR->fineTimeNORM = ring_node->fineTime; } else { - averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); + if (keepMatrix == 1) // keep the matrix and add it to the average + { + averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); + } + else + { + // nothing to do, the matrix is not valid + } + } + } + + if (keepMatrix == 1) + { + if ( (nbAverageNormF2 == 0) ) + { + msgForMATR->numberOfSMInASMNORM = 1; + } + else + { + msgForMATR->numberOfSMInASMNORM++; + } + } + else + { + if ( (nbAverageNormF2 == 0) ) + { + msgForMATR->numberOfSMInASMNORM = 0; + } + else + { + // nothing to do } } } diff --git a/src/processing/fsw_processing.c b/src/processing/fsw_processing.c --- a/src/processing/fsw_processing.c +++ b/src/processing/fsw_processing.c @@ -666,7 +666,7 @@ void ASM_compress_reorganize_and_divide_ + averaged_spec_mat[ offsetASM + k ] * fBinMask ); } compressed_spec_mat[ offsetCompressed ] = - compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage); + (divider != 0.) ? compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage) : 0.0; } } @@ -704,6 +704,81 @@ int getFBinMask( int index, unsigned cha return fbin; } +unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel) +{ + u_int64_t acquisitionTime; + u_int64_t timecodeReference; + u_int64_t offsetInFineTime; + u_int64_t shiftInFineTime; + u_int64_t tBadInFineTime; + u_int64_t acquisitionTimeRangeMin; + u_int64_t acquisitionTimeRangeMax; + unsigned char pasFilteringIsEnabled; + unsigned char ret; + + pasFilteringIsEnabled = (parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01); // [0000 0001] + ret = 1; + + //*************************** + // + unsigned char sy_lfr_pas_filter_modulus = 4; + unsigned char sy_lfr_pas_filter_offset = 1; + float sy_lfr_pas_filter_shift = 0.5; + float sy_lfr_pas_filter_tbad = 1.0; + // + //**************************** + + // compute acquisition time from caoarseTime and fineTime + acquisitionTime = ( ((u_int64_t)coarseTime) << 16 ) + + (u_int64_t) fineTime; + + // compute the timecode reference + timecodeReference = (u_int64_t) (floor( ((double) coarseTime) / ((double) sy_lfr_pas_filter_modulus) ) + * ((double) sy_lfr_pas_filter_modulus)) * 65536; + + // compute the acquitionTime range + offsetInFineTime = ((double) sy_lfr_pas_filter_offset) * 65536; + shiftInFineTime = ((double) sy_lfr_pas_filter_shift) * 65536; + tBadInFineTime = ((double) sy_lfr_pas_filter_tbad) * 65536; + + acquisitionTimeRangeMin = + timecodeReference + + offsetInFineTime + + shiftInFineTime + - acquisitionDurations[channel]; + acquisitionTimeRangeMax = + timecodeReference + + offsetInFineTime + + shiftInFineTime + + tBadInFineTime; + + if ( (acquisitionTime >= acquisitionTimeRangeMin) + && (acquisitionTime <= acquisitionTimeRangeMax) + && (pasFilteringIsEnabled == 1) ) + { + ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored + } + else + { + ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging + } + +// printf("coarseTime = %x, fineTime = %x\n", +// coarseTime, +// fineTime); + +// printf("[ret = %d] *** acquisitionTime = %f, Reference = %f", +// ret, +// acquisitionTime / 65536., +// timecodeReference / 65536.); + +// printf(", Min = %f, Max = %f\n", +// acquisitionTimeRangeMin / 65536., +// acquisitionTimeRangeMax / 65536.); + + return ret; +} + void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm) { unsigned char bin;