LCOV - code coverage report
Current view: top level - src/mitigations - PAS_filtering.c (source / functions) Hit Total Coverage
Test: trace.info Lines: 42 43 97.7 %
Date: 2023-02-20 11:47:18 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*------------------------------------------------------------------------------
       2             : --  Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
       3             : --  This file is a part of the LFR FSW
       4             : --  Copyright (C) 2021, Plasma Physics Laboratory - CNRS
       5             : --
       6             : --  This program is free software; you can redistribute it and/or modify
       7             : --  it under the terms of the GNU General Public License as published by
       8             : --  the Free Software Foundation; either version 2 of the License, or
       9             : --  (at your option) any later version.
      10             : --
      11             : --  This program is distributed in the hope that it will be useful,
      12             : --  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : --  GNU General Public License for more details.
      15             : --
      16             : --  You should have received a copy of the GNU General Public License
      17             : --  along with this program; if not, write to the Free Software
      18             : --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      19             : -------------------------------------------------------------------------------*/
      20             : /*--                  Author : Alexis Jeandet
      21             : --                   Contact : Alexis Jeandet
      22             : --                      Mail : alexis.jeandet@lpp.polytechnique.fr
      23             : ----------------------------------------------------------------------------*/
      24             : #include "mitigations/PAS_filtering.h"
      25             : #include "fsw_globals.h"
      26             : #include "lfr_common_headers/fsw_params.h"
      27             : #include <stdint.h>
      28             : 
      29             : /**
      30             :  * @brief isPolluted returns MATRIX_IS_POLLUTED if there is any overlap between t0:t1 and
      31             :  * tbad0:tbad1 ranges
      32             :  * @param t0 Start acquisition time
      33             :  * @param t1 End of acquisition time
      34             :  * @param tbad0 Start time of poluting signal
      35             :  * @param tbad1 End time of poluting signal
      36             :  * @return
      37             :  */
      38      143428 : unsigned char isPolluted(uint64_t t0, uint64_t t1, uint64_t tbad0, uint64_t tbad1)
      39             : {
      40             :     unsigned char polluted;
      41             : 
      42      143428 :     polluted = MATRIX_IS_NOT_POLLUTED;
      43             : 
      44      533777 :     if (((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
      45      130347 :         || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
      46      130001 :         || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
      47      130001 :         || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
      48             :     {
      49       13427 :         polluted = MATRIX_IS_POLLUTED;
      50             :     }
      51             : 
      52      143428 :     return polluted;
      53             : }
      54             : 
      55             : /**
      56             :  * @brief acquisitionTimeIsValid checks if the given acquisition time is poluted by PAS
      57             :  * @param coarseTime Coarse acquisition time of the given SM
      58             :  * @param fineTime Fine acquisition time of the given ASM
      59             :  * @param channel Frequency channel to check, will impact SM time footprint
      60             :  * @return MATRIX_IS_POLLUTED if there is any time overlap between SM and PAS poluting signal
      61             :  */
      62       52285 : unsigned char acquisitionTimeIsValid(
      63             :     unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
      64             : {
      65             :     uint64_t t0;
      66             :     uint64_t t1;
      67             :     uint64_t tc;
      68             : 
      69             :     uint64_t modulusInFineTime;
      70             :     uint64_t offsetInFineTime;
      71             :     uint64_t shiftInFineTime;
      72             :     uint64_t tbadInFineTime;
      73             : 
      74             :     unsigned char pasFilteringIsEnabled;
      75             :     unsigned char ret;
      76             : 
      77             :     // compute acquisition time from caoarseTime and fineTime
      78       52285 :     t0 = (((uint64_t)coarseTime) << SHIFT_2_BYTES) + (uint64_t)fineTime;
      79       52285 :     t1 = t0;
      80       52285 :     tc = t0;
      81             : 
      82       52285 :     switch (channel)
      83             :     {
      84             :         case CHANNELF0:
      85       44432 :             t1 = t0 + ACQUISITION_DURATION_F0;
      86       44432 :             tc = t0 + HALF_ACQUISITION_DURATION_F0;
      87       44432 :             break;
      88             :         case CHANNELF1:
      89        7392 :             t1 = t0 + ACQUISITION_DURATION_F1;
      90        7392 :             tc = t0 + HALF_ACQUISITION_DURATION_F1;
      91        7392 :             break;
      92             :         case CHANNELF2:
      93         461 :             t1 = t0 + ACQUISITION_DURATION_F2;
      94         461 :             tc = t0 + HALF_ACQUISITION_DURATION_F2;
      95             :             break;
      96             :         default:
      97             :             break;
      98             :     }
      99             : 
     100             :     // compute the acquitionTime range
     101       52285 :     modulusInFineTime = filterPar.modulus_in_finetime;
     102       52285 :     offsetInFineTime = filterPar.offset_in_finetime;
     103       52285 :     shiftInFineTime = filterPar.shift_in_finetime;
     104       52285 :     tbadInFineTime = filterPar.tbad_in_finetime;
     105             : 
     106       52285 :     pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
     107             : 
     108       52285 :     if ((tbadInFineTime == 0) || (pasFilteringIsEnabled == 0))
     109             :     {
     110           0 :         ret = MATRIX_IS_NOT_POLLUTED;
     111             :     }
     112             :     else
     113             :     {
     114             :         // INTERSECTION TEST #1
     115       52285 :         uint64_t timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime;
     116       52285 :         uint64_t tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     117       52285 :         uint64_t tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     118       52285 :         ret = isPolluted(t0, t1, tbad0, tbad1);
     119             : 
     120             :         // INTERSECTION TEST #2
     121       52285 :         if (ret == MATRIX_IS_NOT_POLLUTED)
     122             :         {
     123       52285 :             timecodeReference = (tc - (tc % modulusInFineTime));
     124       52285 :             tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     125       52285 :             tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     126       52285 :             ret = isPolluted(t0, t1, tbad0, tbad1);
     127             :         }
     128             : 
     129             :         // INTERSECTION TEST #3
     130       52285 :         if (ret == MATRIX_IS_NOT_POLLUTED)
     131             :         {
     132       38858 :             timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime;
     133       38858 :             tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     134       38858 :             tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     135       38858 :             ret = isPolluted(t0, t1, tbad0, tbad1);
     136             :         }
     137             :     }
     138             : 
     139       52285 :     return ret;
     140             : }

Generated by: LCOV version 1.14