Tezzeret  1
Tezzeret
GmMfamFilter.hpp
1 #ifndef GM_MFAM_FILTER_HPP_
2 #define GM_MFAM_FILTER_HPP_
3 
4 #ifndef GEO_MFAM_FULL_FILTER
5 #error GmMfamFilter.hpp should only be included if the feature is enabled.
6 #endif
7 
8 #include <stdint.h>
9 #include <geotypes.hpp>
10 
11 #ifndef GMMFAMDATA_HPP_
12 #include <GmMfamData.hpp>
13 #endif
14 
15 
16 namespace Geometrics {
17 
18 class MfamLokiInterpolator;
19 
20 #if GEO_MFAM_FULL_FILTER == GEO_TRUE
21 
22 
23  /******************************************************************************
24  * Filter names. There are as many as 12 filters active at one point, for the
25  * mag data and for the aux fields. They're all active at the same point, all
26  * in sync, all emit results at the same time, etc., etc., so they can all
27  * share some common structure and data. Each of those filters must have its
28  * own accumulators, of course. These filter names are indexes into various
29  * structures.
30  ***************************************************************************** */
31  #define MFAM_MAG1_FILTER 0
32  #define MFAM_MAG2_FILTER 1
33  #define MFAM_COUNT_STAGE_1_FILTERS (MFAM_MAG2_FILTER + 1)
34  #define MFAM_GYRO_X_FILTER 2
35  #define MFAM_GYRO_Y_FILTER 3
36  #define MFAM_GYRO_Z_FILTER 4
37  #define MFAM_COMPASS_X_FILTER 5
38  #define MFAM_COMPASS_Y_FILTER 6
39  #define MFAM_COMPASS_Z_FILTER 7
40  #define MFAM_ACCEL_X_FILTER 8
41  #define MFAM_ACCEL_Y_FILTER 9
42  #define MFAM_ACCEL_Z_FILTER 10
43  #define MFAM_TEMP_FILTER 11
44  #define MFAM_COUNT_STAGE_2_FILTERS (MFAM_TEMP_FILTER + 1)
45 
46 
47  //#define MFAM_FILTER_1000_TO_100_HALF_LENGTH 25
48  /******************************************************************************
49  * GmFilterDef describes the filter structure, per individual filter. It is
50  * not the description of the group of filters.
51  *******************************************************************************/
52  struct GmFilterDef {
53  public:
54  uint32_t mStartHz, // e.g. 1000
55  mStageStartHz, // e.g. 1000 or 100
56  mStageTargetHz, // e.g. 100
57  mTargetHz, // After all stages.
58  mStage, // 1, 2
59  mCountHalfTaps, // e.g. 249
60  // mSizeTaps,
61  fidStepSize; // e.g. 4 or 8, for single or double,
62  const double *mHalfTaps;
63  };
64 
65  /*******************************************************************
66  * GmMfamFullFilter is the group of filters - mag values, aux
67  * values, GPS and other values, etc. It includes accumulators for
68  * each of those values, all of which operate in lock step with
69  * each other. All of the individual filters in a GmMfamFullFilter
70  * share the same GmFilterDef.
71  *********************************************************************/
73  public:
75  virtual ~GmMfamFullFilter ();
76  void Initialize ();
77  bool ClearFilters ();
78  bool StartFilter ();
79  bool IsAvailable (uint32_t startRate,
80  uint32_t targetRate);
81 
82  /**************************************************************
83  * Choose the filter def from among the available filters,
84  * and do some setup calculations.
85  ***************************************************************/
86  bool SelectFilter (uint32_t startRate,
87  uint32_t targetRate,
88  uint32_t stage,
89  bool onlyMagValues);
90  void SetNextStage (GmMfamFullFilter *nextStage);
91 
92  /**************************************************************
93  * Add values to all of the filters in this group (newValues is
94  * a structure with many values). Return values that verify
95  * that the filter worked properly, and also specifying whether
96  * this action resulted in filter values being emitted.
97  **************************************************************/
98  int AddValues (int fid,
99  uint64_t tezzeretCounter,
100  IndexedMfamFilteredPacket *newValues);
101  static GmFilterDef sFilterDefs[];
102 
103  static int FilterMfamData (IndexedMfamSpiPacketWithHeader *pimsphData,
104  IndexedMfamFilteredPacketWithHeader &newPacket,
105  GmMfamFullFilter *mfamStageOneFilter,
106  GmMfamFullFilter *mfamStageTwoFilter,
107  MfamLokiInterpolator *lokiInterpolator,
108  ti_sysbios_knl_Semaphore_Handle decimationSemaphore,
109  bool &recordEmitted);
110 
111  // static GmFilterDef *sCurrentDef;
112 
113  private:
114 
115  double *MakeAccumulators (int count);
116  bool MakeCenterRecords ();
117  bool MakeValueIndexes ();
118  void CleanAccumulators (int accumulatorIndex);
119 
120 
121  int mCountAccumulatorsPerFilter,
122  mStep, // How far apart are accumulators?
123  mLastValueIndex, // how many taps, minus one.
124  mModulusOfFirstValue, // How do we know what is first value?
125  mCenterCounterOffset,
126  mFirstFilter; // Which accumulator is most full
127  bool //mStarted,
128  mOnlyMagValues;
129  double *mAccumulators;
130  GmMfamFullFilter *mNextStage;
131  public:
132  GmFilterDef *mDef;
133  uint64_t *mCenterRecordCounters;
134  int *mValueIndexes,
135  mLastCompleteAccumulator; // Which just emitted a value?
136  IndexedMfamFilteredPacket *mCenterRecords;
137 
138 
139  };
140 
142  {
143  public:
144  IndexedMfamFilteredPacket mStashedRecord,
145  mFilterRecords[10];
146  void Initialize ();
147  void AddRecord (IndexedMfamFilteredPacket *newRecord, int index);
148  void InterpolateAccelValues (int index);
149  void InterpolateGyroValues (int index);
150  void InterpolateCompassValues (int index);
151  void InterpolateAuxValues(int index);
152 
153 
154 
155  };
156 #endif
157 
158  #define RAW_FREQUENCY_DATA_BUFFER_COUNT (200)
159 
160  #if GEO_MFAM_FREQUENCY_MEASURE == GEO_TRUE
162  public:
163  GmMfamFrequencyDetector (int sampleRate, int samplesMeasured, double frequencyToMeasure);
164  void Initialize ();
165  int SetDownsampleRate (int downsampleRate);
166  int AddValue (double newValue);
167  double CalculateFrequencyResponse ();
168  void ResetCache ();
169 
170  private:
171  int mDownsampleRate;
172  int mSampleRate;
173  int mSamplesMeasured;
174  int mBinNumber;
175  double mFrequencyToMeasure;
176  double mRealWeight, mImaginaryWeight;
177  };
178  #endif
179 
180 }
181 #endif
Definition: GmMfamFilter.hpp:161
Definition: GmMfamFilter.hpp:72
Definition: GmMfamFilter.hpp:142
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47
Definition: GmMfamFilter.hpp:52
Definition: GmMfamData.hpp:242
Definition: GmMfamData.hpp:267