File indexing completed on 2024-09-08 11:04:10
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef OSCILLOSCOPEDATA_H 0012 #define OSCILLOSCOPEDATA_H 0013 0014 #include <QColor> 0015 #include <QObject> 0016 #include <stdint.h> 0017 #include <vector> 0018 0019 #define DATA_CHUNK_SIZE (8192 / sizeof(T)) 0020 0021 /* 0022 #define DATA_CHUNK_ARRAY_SIZE ((8192-sizeof(uint32_t))/sizeof(DataChunk<T>*)) 0023 0024 // Allow a minimum of 64 megabytes of stored data (67108864 bytes) 0025 /// \todo The maximum allowed amount of stored data should be configurable or 0026 /// more intelligent (e.g. taking into account the number of probes or the 0027 /// amount of physical memory on the system). 0028 #define DCARRAY_ARRAY_SIZE ((67108864/(8192*DATA_CHUNK_ARRAY_SIZE))+1) 0029 */ 0030 0031 /** max number of samples that a probe can hold */ 0032 #define MAX_PROBE_DATA_SIZE (1 * 1024 * 1024) 0033 // TODO ^ should be configurable 0034 0035 /** 0036 For use in LogicProbe: Every time the input changes state, the new input state 0037 is recorded in value, along with the simulator time that it occurs at. 0038 */ 0039 class LogicDataPoint 0040 { 0041 public: 0042 LogicDataPoint() 0043 : value(0) 0044 , time(0) 0045 { 0046 } 0047 LogicDataPoint(bool v, uint64_t t) 0048 : value(v) 0049 , time(t) 0050 { 0051 } 0052 0053 bool value : 1; 0054 uint64_t time : 63; 0055 }; 0056 0057 /** 0058 @author David Saxton 0059 */ 0060 class ProbeData : public QObject 0061 { 0062 Q_OBJECT 0063 public: 0064 ProbeData(int id); 0065 ~ProbeData() override; 0066 0067 /** 0068 * @returns unique id for oscilloscope, set on construction 0069 */ 0070 int id() const 0071 { 0072 return m_id; 0073 } 0074 /** 0075 * Set the proportion (0 = top, 1 = bottom) of the way down the 0076 * oscilloscope view that the probe output is drawn. If the proportion 0077 * is out of range ( <0, or >1), then the drawPosition is set to 0/1 0078 */ 0079 void setDrawPosition(float drawPosition) 0080 { 0081 m_drawPosition = drawPosition; 0082 } 0083 /** 0084 * Returns the draw position. Default is 0.5. 0085 * @see setDrawPosition 0086 */ 0087 float drawPosition() const 0088 { 0089 return m_drawPosition; 0090 } 0091 /** 0092 * Set the colour that is used to display the probe in the oscilloscope. 0093 * Default is black. 0094 */ 0095 void setColor(QColor color); 0096 /** 0097 * @returns the colour that is used to display the probe in the oscilloscope 0098 */ 0099 QColor color() const 0100 { 0101 return m_color; 0102 } 0103 // /** 0104 // * Will not record any data when paused 0105 // */ 0106 // void setPaused( bool isPaused) { b_isPaused = isPaused; } 0107 /** 0108 * Returns the time (in Simulator time) that this probe was created at, 0109 * or last reset. 0110 */ 0111 uint64_t resetTime() const 0112 { 0113 return m_resetTime; 0114 } 0115 /** 0116 * Erases all recorded data, and sets m_resetTime to the current 0117 * simulator time. 0118 */ 0119 virtual void eraseData() = 0; 0120 /** 0121 * Searches for and returns the position of the last DataPoint that was 0122 * added before or at the given Simulator time. If no DataPoints were 0123 * were recorded before the given time, then will return the one closest 0124 * to the given time. Will return 0 if no DataPoints have been recorded 0125 * yet. 0126 */ 0127 virtual uint64_t findPos(uint64_t time) const = 0; 0128 0129 signals: 0130 /** 0131 * Emitted when an attribute that affects how the probe is drawn in the 0132 * oscilloscope is changed. 0133 */ 0134 void displayAttributeChanged(); 0135 0136 protected: 0137 const int m_id; 0138 float m_drawPosition; 0139 uint64_t m_resetTime; 0140 QColor m_color; 0141 }; 0142 0143 /** 0144 @author David Saxton 0145 */ 0146 class LogicProbeData : public ProbeData 0147 { 0148 public: 0149 LogicProbeData(int id); 0150 ~LogicProbeData() override 0151 { 0152 delete m_data; 0153 } 0154 0155 /** 0156 * Appends the data point to the set of data. 0157 */ 0158 void addDataPoint(LogicDataPoint data); /* { 0159 m_data->push_back(data); 0160 } */ // 2016.05.06 - moved to cpp 0161 0162 void eraseData() override; 0163 uint64_t findPos(uint64_t time) const override; 0164 0165 bool isEmpty() const 0166 { 0167 return m_data->size() == 0; 0168 } 0169 0170 protected: 0171 std::vector<LogicDataPoint> *m_data; 0172 friend class OscilloscopeView; 0173 }; 0174 0175 /** 0176 @author David Saxton 0177 */ 0178 class FloatingProbeData : public ProbeData 0179 { 0180 public: 0181 enum Scaling { Linear, Logarithmic }; 0182 0183 FloatingProbeData(int id); 0184 0185 /** 0186 * Appends the data point to the set of data. 0187 */ 0188 void addDataPoint(float data); // { m_data->push_back(data); } // 2016.05.06 - moved to cpp 0189 /** 0190 * Converts the insert position to a Simulator time. 0191 */ 0192 uint64_t toTime(uint64_t at) const; 0193 /** 0194 * Sets the scaling to use in the oscilloscope display. 0195 */ 0196 void setScaling(Scaling scaling); 0197 /** 0198 * @return the scaling used for the oscilloscope display. 0199 */ 0200 Scaling scaling() const 0201 { 0202 return m_scaling; 0203 } 0204 /** 0205 * Sets the value to use as the upper absolute value in the display. 0206 */ 0207 void setUpperAbsValue(double upperAbsValue); 0208 /** 0209 * @return the upper absolute value to use in the display. 0210 */ 0211 double upperAbsValue() const 0212 { 0213 return m_upperAbsValue; 0214 } 0215 /** 0216 * Sets the value to use as the lower absolute value in the display 0217 * (this is only used with logarithmic scaling). 0218 */ 0219 void setLowerAbsValue(double lowerAbsValue); 0220 /** 0221 * @return the lower absolute value to use in the display (this is 0222 * only used with logarithmic scaling). 0223 */ 0224 double lowerAbsValue() const 0225 { 0226 return m_lowerAbsValue; 0227 } 0228 0229 void eraseData() override; 0230 uint64_t findPos(uint64_t time) const override; 0231 0232 bool isEmpty() const 0233 { 0234 return m_data->size() == 0; 0235 } 0236 0237 protected: 0238 Scaling m_scaling; 0239 double m_upperAbsValue; 0240 double m_lowerAbsValue; 0241 std::vector<float> *m_data; 0242 friend class OscilloscopeView; 0243 }; 0244 0245 #endif