LCOV - code coverage report
Current view: top level - src/mitigations - PAS_filtering.c (source / functions) Hit Total Coverage
Test: trace.info Lines: 43 43 100.0 %
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      403737 : unsigned char isPolluted(uint64_t t0, uint64_t t1, uint64_t tbad0, uint64_t tbad1)
      39             : {
      40             :     unsigned char polluted;
      41             : 
      42      403737 :     polluted = MATRIX_IS_NOT_POLLUTED;
      43             : 
      44     1502858 :     if (((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
      45      367017 :         || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
      46      366052 :         || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
      47      366052 :         || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
      48             :     {
      49       37684 :         polluted = MATRIX_IS_POLLUTED;
      50             :     }
      51             : 
      52      403737 :     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      338065 : 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      338065 :     t0 = (((uint64_t)coarseTime) << SHIFT_2_BYTES) + (uint64_t)fineTime;
      79      338065 :     t1 = t0;
      80      338065 :     tc = t0;
      81             : 
      82      338065 :     switch (channel)
      83             :     {
      84             :         case CHANNELF0:
      85      287849 :             t1 = t0 + ACQUISITION_DURATION_F0;
      86      287849 :             tc = t0 + HALF_ACQUISITION_DURATION_F0;
      87      287849 :             break;
      88             :         case CHANNELF1:
      89       47312 :             t1 = t0 + ACQUISITION_DURATION_F1;
      90       47312 :             tc = t0 + HALF_ACQUISITION_DURATION_F1;
      91       47312 :             break;
      92             :         case CHANNELF2:
      93        2904 :             t1 = t0 + ACQUISITION_DURATION_F2;
      94        2904 :             tc = t0 + HALF_ACQUISITION_DURATION_F2;
      95             :             break;
      96             :         default:
      97             :             break;
      98             :     }
      99             : 
     100             :     // compute the acquitionTime range
     101      338065 :     modulusInFineTime = filterPar.modulus_in_finetime;
     102      338065 :     offsetInFineTime = filterPar.offset_in_finetime;
     103      338065 :     shiftInFineTime = filterPar.shift_in_finetime;
     104      338065 :     tbadInFineTime = filterPar.tbad_in_finetime;
     105             : 
     106      338065 :     pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
     107             : 
     108      338065 :     if ((tbadInFineTime == 0) || (pasFilteringIsEnabled == 0))
     109             :     {
     110      190924 :         ret = MATRIX_IS_NOT_POLLUTED;
     111             :     }
     112             :     else
     113             :     {
     114             :         // INTERSECTION TEST #1
     115      147141 :         uint64_t timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime;
     116      147141 :         uint64_t tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     117      147141 :         uint64_t tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     118      147141 :         ret = isPolluted(t0, t1, tbad0, tbad1);
     119             : 
     120             :         // INTERSECTION TEST #2
     121      147141 :         if (ret == MATRIX_IS_NOT_POLLUTED)
     122             :         {
     123      147116 :             timecodeReference = (tc - (tc % modulusInFineTime));
     124      147116 :             tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     125      147116 :             tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     126      147116 :             ret = isPolluted(t0, t1, tbad0, tbad1);
     127             :         }
     128             : 
     129             :         // INTERSECTION TEST #3
     130      147165 :         if (ret == MATRIX_IS_NOT_POLLUTED)
     131             :         {
     132      109456 :             timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime;
     133      109456 :             tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
     134      109456 :             tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
     135      109456 :             ret = isPolluted(t0, t1, tbad0, tbad1);
     136             :         }
     137             :     }
     138             : 
     139      338088 :     return ret;
     140             : }

Generated by: LCOV version 1.14