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 22537 : unsigned char isPolluted(uint64_t t0, uint64_t t1, uint64_t tbad0, uint64_t tbad1) 39 : { 40 : unsigned char polluted; 41 : 42 22537 : polluted = MATRIX_IS_NOT_POLLUTED; 43 : 44 83879 : if (((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range 45 20484 : || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range 46 20429 : || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range 47 20429 : || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range 48 : { 49 2108 : polluted = MATRIX_IS_POLLUTED; 50 : } 51 : 52 22537 : 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 8215 : 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 8215 : t0 = (((uint64_t)coarseTime) << SHIFT_2_BYTES) + (uint64_t)fineTime; 79 8215 : t1 = t0; 80 8215 : tc = t0; 81 : 82 8215 : switch (channel) 83 : { 84 : case CHANNELF0: 85 6992 : t1 = t0 + ACQUISITION_DURATION_F0; 86 6992 : tc = t0 + HALF_ACQUISITION_DURATION_F0; 87 6992 : break; 88 : case CHANNELF1: 89 1152 : t1 = t0 + ACQUISITION_DURATION_F1; 90 1152 : tc = t0 + HALF_ACQUISITION_DURATION_F1; 91 1152 : break; 92 : case CHANNELF2: 93 71 : t1 = t0 + ACQUISITION_DURATION_F2; 94 71 : tc = t0 + HALF_ACQUISITION_DURATION_F2; 95 : break; 96 : default: 97 : break; 98 : } 99 : 100 : // compute the acquitionTime range 101 8215 : modulusInFineTime = filterPar.modulus_in_finetime; 102 8215 : offsetInFineTime = filterPar.offset_in_finetime; 103 8215 : shiftInFineTime = filterPar.shift_in_finetime; 104 8215 : tbadInFineTime = filterPar.tbad_in_finetime; 105 : 106 8215 : pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001] 107 : 108 8215 : if ((tbadInFineTime == 0) || (pasFilteringIsEnabled == 0)) 109 : { 110 0 : ret = MATRIX_IS_NOT_POLLUTED; 111 : } 112 : else 113 : { 114 : // INTERSECTION TEST #1 115 8215 : uint64_t timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime; 116 8215 : uint64_t tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime; 117 8215 : uint64_t tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime; 118 8215 : ret = isPolluted(t0, t1, tbad0, tbad1); 119 : 120 : // INTERSECTION TEST #2 121 8215 : if (ret == MATRIX_IS_NOT_POLLUTED) 122 : { 123 8215 : timecodeReference = (tc - (tc % modulusInFineTime)); 124 8215 : tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime; 125 8215 : tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime; 126 8215 : ret = isPolluted(t0, t1, tbad0, tbad1); 127 : } 128 : 129 : // INTERSECTION TEST #3 130 8215 : if (ret == MATRIX_IS_NOT_POLLUTED) 131 : { 132 6107 : timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime; 133 6107 : tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime; 134 6107 : tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime; 135 6107 : ret = isPolluted(t0, t1, tbad0, tbad1); 136 : } 137 : } 138 : 139 8215 : return ret; 140 : }