1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*
* Remote Laboratory Component Analyzer Part
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2014 - 2015 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#ifndef REMOTELAB_COMPANALYZERPART_H
#define REMOTELAB_COMPANALYZERPART_H
#include <ntqthread.h>
#include <ntqeventloop.h>
#include <tqvariant.h>
#include <tqvaluevector.h>
#include <tdeparts/browserextension.h>
#include <tdeparts/statusbarextension.h>
#include <tdeparts/part.h>
#include <kurl.h>
#include <tqtrla.h>
#include <sevensegment.h>
#define MAXTRACES 255
class TDEAboutData;
using KParts::StatusBarExtension;
class TraceWidget;
class TQSocket;
class TQTimer;
class TQMutex;
class TQRectF;
class CompAnalyzerBase;
namespace RemoteLab
{
typedef enum CompAnalyzerEventType {
NoEvent = 0,
Initialize = 1,
TxRxSyncPoint = 2,
StateChanged = 3,
ExtendedErrorReceived = 4,
ConfigurationDataReceived = 5,
ChangeMeasurementSource = 6,
GetMeasurement = 7,
GetMaximumFrequency = 8,
GetMinimumFrequency = 9,
SetFrequency = 10,
MeasurementsReceived = 11,
SweepMeasurementsReceived = 12,
StartSweep = 13,
AbortSweep = 14,
OtherEvent = 15
} CompAnalyzerEventType;
typedef enum CompAnalyzerStartupState {
StartSelectInstrument = 0,
StartGetMaximumFrequency = 1,
StartGetMinimumFrequency = 2,
StartDone = 3
} CompAnalyzerStartupState;
typedef enum CompAnalyzerPartState {
Idle = 0,
Initializing = 1,
FreeRunning = 2,
FrequencySweepWrite = 3,
FrequencySweepRead = 4,
CommunicationFailure = 5
} CompAnalyzerPartState;
typedef struct CompAnalyzerMeasurement {
TQ_UINT32 status;
TQ_UINT32 parameter;
TQ_UINT32 type;
double value;
double frequency;
} CompAnalyzerMeasurement;
typedef TQPair<CompAnalyzerEventType, TQVariant> CompAnalyzerEvent;
typedef TQValueVector<CompAnalyzerEvent> CompAnalyzerEventQueue;
typedef TQValueList<CompAnalyzerMeasurement> CompAnalyzerMeasurementList;
typedef TQPair<unsigned int,TQString> AllowedMeasurementInfo;
typedef TQValueList<AllowedMeasurementInfo> AllowedMeasurementInfoList;
typedef struct CompAnalyzerInstrumentLimits {
TQValueList<AllowedMeasurementInfoList> allowedMeasurements;
double maxFrequency;
double minFrequency;
} CompAnalyzerInstrumentLimits;
#ifndef QT_NO_DATASTREAM
Q_EXPORT TQDataStream &operator<<(TQDataStream &, const CompAnalyzerMeasurement &);
Q_EXPORT TQDataStream &operator>>(TQDataStream &, CompAnalyzerMeasurement &);
#endif
class CompAnalyzerWorker : public TQObject
{
TQ_OBJECT
public:
CompAnalyzerWorker();
~CompAnalyzerWorker();
signals:
void outboundQueueUpdated();
public slots:
void run();
void wake();
void dataReceived();
public:
void resetInboundQueue();
void appendItemToInboundQueue(CompAnalyzerEvent item, bool syncPoint=false);
bool itemTypeInInboundQueue(CompAnalyzerEventType type);
bool syncPointActive();
void lockOutboundQueue();
void unlockOutboundQueue();
CompAnalyzerEventQueue* outboundQueue();
CompAnalyzerPartState currentState();
CompAnalyzerInstrumentLimits getInstrumentLimits();
void setNewParameterSourceList(TQValueList<TQ_UINT32>);
void setSweepStartFrequency(double hz);
void setSweepEndFrequency(double hz);
void setSweepStepFrequency(double hz);
double sweepStartFrequency();
double sweepEndFrequency();
double sweepStepFrequency();
unsigned int sweepStepNumber();
private:
CompAnalyzerEventType nextInboundQueueEvent();
void clearInboundQueueSyncPoint();
void eraseNextInboundQueueEvent(bool clearSyncPoint=false);
void setCurrentState(CompAnalyzerPartState state);
public:
TDEKerberosClientSocket* m_socket;
TQMutex* m_instrumentMutex;
private:
CompAnalyzerEventQueue m_outboundQueue;
CompAnalyzerEventQueue m_inboundQueue;
TQMutex* m_outboundQueueMutex;
TQMutex* m_inboundQueueMutex;
TQMutex* m_networkDataMutex;
TQMutex* m_currentStateMutex;
TQMutex* m_sweepStepMutex;
CompAnalyzerPartState m_currentState;
CompAnalyzerStartupState m_startupState;
CompAnalyzerEventType m_lastNetworkTransmissionEvent;
bool m_newData;
TQValueList<TQ_UINT32> m_sourceList;
CompAnalyzerInstrumentLimits m_instrumentLimits;
double m_sweepStart;
double m_sweepEnd;
double m_sweepStep;
double m_sweepCurrentFrequency;
TQ_UINT32 m_sweepStepNumber;
};
class CompAnalyzerPart : public KParts::RemoteInstrumentPart
{
Q_OBJECT
public:
CompAnalyzerPart( QWidget *, const char *, TQObject *, const char *, const TQStringList&);
~CompAnalyzerPart();
virtual bool openFile() { return false; } // pure virtual in the base class
virtual bool closeURL();
static TDEAboutData *createAboutData();
signals:
void wakeWorkerThread();
public slots:
virtual bool openURL(const KURL &url);
void processOutboundQueue();
void updateZoomWidgetLimits(const TQRectF& zoomRect);
private slots:
void postInit();
void processLockouts();
void connectionFinishedCallback();
void disconnectFromServerCallback();
void connectionStatusChangedCallback();
void setTickerMessage(TQString message);
void networkTick();
void networkTimeout();
void parameterASourceChanged(int);
void parameterBSourceChanged(int);
void frequencyInputChanged(double);
void startSweepClicked();
void stopSweepClicked();
void processAutosave();
void saveWaveforms();
void saveWaveforms(TQString fileName);
void recallWaveforms();
void updateGraticule();
private:
TQString parameterMeasurementUnits(TQ_UINT32 parameter);
TQString parameterNameToMeasurementUnits(TQString name, unsigned int parameter_index);
void requestNetworkOperation(CompAnalyzerEvent item, bool syncPoint=false);
void patWatchDog();
private:
int m_commHandlerState;
int m_commHandlerMode;
int m_commHandlerCommandState;
TQTimer* m_updateTimeoutTimer;
bool m_connectionActiveAndValid;
bool m_instrumentSettingsValid;
unsigned char m_tickerState;
CompAnalyzerBase* m_base;
TQMutex* m_instrumentMutex;
TQString m_TextToSend;
TQValueList<AllowedMeasurementInfoList> m_parameterSourceValues;
TraceWidget* m_traceWidget;
TQGridLayout* m_traceControlWidgetGrid;
SensorList m_sensorList;
TQ_INT16 m_maxNumberOfTraces;
TQ_INT16 m_hdivs;
TQ_INT16 m_vdivs;
TQ_INT32 m_samplesInTrace[MAXTRACES+1];
bool m_channelActive[MAXTRACES+1];
TQString m_traceUnits[MAXTRACES+1];
CompAnalyzerWorker* m_worker;
TQEventLoopThread* m_workerThread;
};
}
#endif
|