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

Generated by: LCOV version 1.14