SEPIA
Software documentation for the APEX SEPIA receivers
scriptrunner.h
1 /* Copyright 2017 Michael Olberg <michael.olberg@chalmers.se> */
2 #ifndef SCRIPTRUNNER_H
3 #define SCRIPTRUNNER_H
4 
5 #include <QObject>
6 #include <QVector>
7 #include <QScriptable>
8 #include <QScriptEngine>
9 #include <QScriptContext>
10 #include <QScriptValue>
11 
12 class Cartridge;
13 class Channel;
14 
15 class PLL : public QObject, public QScriptable
16 {
17  Q_OBJECT
18  Q_PROPERTY(double corrVoltage READ corrVoltage)
19  Q_PROPERTY(double lockVoltage READ lockVoltage)
20  Q_PROPERTY(double referencePower READ refTotalPower)
21  Q_PROPERTY(double ifPower READ ifTotalPower)
22  Q_PROPERTY(double assemblyTemperature READ assemblyTemperature)
23  Q_PROPERTY(bool locked READ locked);
24 
25  public:
26  explicit PLL(Channel *parent = 0);
27  void setCartridge(Cartridge *band) { m_cart = band; }
28  Cartridge *cartridge() const { return m_cart; }
29  Q_INVOKABLE double corrVoltage();
30  Q_INVOKABLE double lockVoltage();
31  Q_INVOKABLE double refTotalPower();
32  Q_INVOKABLE double ifTotalPower();
33  Q_INVOKABLE double assemblyTemperature();
34  Q_INVOKABLE bool locked() const;
35 
36  public slots:
37  void setPllLoopBandwidth(bool flag);
38  void setNullPllIntegrator(bool flag);
39  void setPllSideband(bool lower);
40 
41  private:
42  Cartridge *m_cart;
43  int m_pol;
44  int m_sis;
45  int m_stage;
46 };
47 
48 class Multiplier : public QObject, public QScriptable
49 {
50  Q_OBJECT
51 
52  public:
53  explicit Multiplier(Channel *parent = 0); // AMC
54  void setCartridge(Cartridge *band) { m_cart = band; }
55  Cartridge *cartridge() const { return m_cart; }
56  Q_INVOKABLE double drainVoltage(int amc);
57  Q_INVOKABLE double drainCurrent(int amc);
58  Q_INVOKABLE double gateVoltage(int amc);
59  Q_INVOKABLE double monitor5V();
60  Q_INVOKABLE double multiDVoltage();
61 
62  public slots:
63  void setDrainVoltage(int amc, double mV);
64  // void setDrainCurrent(int amc, double mA);
65  // void setGateVoltage(int amc, double mV);
66 
67  private:
68  Cartridge *m_cart;
69 };
70 
71 class Amplifier : public QObject, public QScriptable
72 {
73  Q_OBJECT
74  Q_PROPERTY(double drainVoltage READ drainVoltage WRITE setDrainVoltage)
75  Q_PROPERTY(double drainCurrent READ drainCurrent WRITE setDrainCurrent)
76  Q_PROPERTY(double gateVoltage READ gateVoltage WRITE setGateVoltage)
77 
78  public:
79  explicit Amplifier(int pol, Channel *parent = 0); // PA
80  explicit Amplifier(int pol, int sis, int stage, Channel *parent = 0); // LNA
81  void setCartridge(Cartridge *band) { m_cart = band; }
82  Cartridge *cartridge() const { return m_cart; }
83  Q_INVOKABLE double drainVoltage();
84  Q_INVOKABLE double drainCurrent();
85  Q_INVOKABLE double gateVoltage();
86 
87  public slots:
88  void setDrainVoltage(double mV);
89  void setDrainCurrent(double mA);
90  void setGateVoltage(double mV);
91 
92  private:
93  Cartridge *m_cart;
94  int m_pol;
95  int m_sis;
96  int m_stage;
97 };
98 
99 class Element : public QObject, public QScriptable
100 {
101  Q_OBJECT
102  Q_PROPERTY(double bias READ bias WRITE setBias)
103  Q_PROPERTY(bool mode READ sisOpenLoop WRITE setSisOpenLoop)
104  Q_PROPERTY(double current READ current)
105  Q_PROPERTY(double coilCurrent READ coilCurrent WRITE setCoilCurrent)
106  Q_PROPERTY(double coilVoltage READ coilVoltage)
107  // Q_PROPERTY(double biasOffset READ biasOffset WRITE setBiasOffset)
108  // Q_PROPERTY(double currentOffset READ currentOffset WRITE setCurrentOffset)
109  Q_PROPERTY(double heaterCurrent READ heaterCurrent)
110  Q_PROPERTY(double mixerTemperature READ mixerTemperature)
111  // Q_PROPERTY(double PAdrainVoltage READ paDrainVoltage WRITE setPaDrainVoltage)
112  // Q_PROPERTY(double PAgateVoltage READ paGateVoltage WRITE setPaGateVoltage)
113  // Q_PROPERTY(double PAdrainCurrent READ paDrainCurrent)
114 
115  public:
116  Element(int pol, int sis, Channel *parent = 0);
117  void setCartridge(Cartridge *band) { m_cart = band; }
118  Cartridge *cartridge() const { return m_cart; }
119  Q_INVOKABLE double bias();
120  Q_INVOKABLE double current();
121  Q_INVOKABLE double coilCurrent();
122  Q_INVOKABLE double coilVoltage();
123  // Q_INVOKABLE double biasOffset() const;
124  // Q_INVOKABLE double currentOffset() const;
125  Q_INVOKABLE double heaterCurrent() const;
126  Q_INVOKABLE double mixerTemperature() const;
127  // Q_INVOKABLE double paGateVoltage() const;
128  // Q_INVOKABLE double paDrainVoltage() const;
129  // Q_INVOKABLE double paDrainCurrent() const;
130  Q_INVOKABLE QVector<double> biasTrace() const;
131  Q_INVOKABLE QVector<double> currentTrace() const;
132  Q_INVOKABLE QVector<double> powerTrace() const;
133  Q_INVOKABLE bool sisOpenLoop() const;
134 
135  public slots:
136  void setBias(double mV);
137  void setCoilCurrent(double mA);
138  // void setBiasOffset(double mV);
139  // void setCurrentOffset(double mA);
140  void setSisOpenLoop(bool flag);
141  void setLNAenable(bool flag);
142  // void setPaGateVoltage(double mV);
143  // void setPaDrainVoltage(double mV);
144  void toggleHeater();
145  void setHeaterState(bool flag);
146  void tune(double bias1, double bias2, double Igoal, double maxPower);
147  void demagnetize();
148  void deflux();
149  void scan(double from, double to, int steps, bool withPower=false);
150  void saveTrace();
151  void plotTrace(QVector<double> x, QVector<double> y,
152  const QString &xlab, const QString &ylab);
153 
154  private:
155  Cartridge *m_cart;
156  int m_pol;
157  int m_sis;
158 };
159 
160 class Oscillator : public QObject, public QScriptable
161 {
162  Q_OBJECT
163  Q_PROPERTY(int YIG READ getYIG WRITE updateYIG);
164  Q_PROPERTY(double synthGHz READ synthFreq WRITE setSynthFreq);
165  Q_PROPERTY(double synthdBm READ synthLevel WRITE setSynthLevel);
166  Q_PROPERTY(bool lockLatch READ lockLatch);
167 
168  public:
169  explicit Oscillator(Channel *parent = 0);
170  void setCartridge(Cartridge *band) { m_cart = band; }
171  Cartridge *cartridge() const { return m_cart; }
172  Q_INVOKABLE int getYIG() const;
173  Q_INVOKABLE double synthFreq() const;
174  Q_INVOKABLE double synthLevel() const;
175  Q_INVOKABLE bool lockLatch() const;
176 
177  public slots:
178  void updateYIG(int value);
179  void tune(double ghz, int harmonic);
180  void setSynthFreq(double ghz);
181  void setSynthLevel(double dBm);
182  void setSynthPower(bool on);
183  void clearLatch();
184 
185  private:
186  Cartridge *m_cart;
187 };
188 
189 class Channel : public QObject, public QScriptable
190 {
191  Q_OBJECT
192 
193  public:
194  enum Pol { POL0 = 0, POL1 = 1 };
195  Q_ENUM(Pol)
196  enum Sis { SIS1 = 1, SIS2 = 2 };
197  Q_ENUM(Sis)
198  enum Stage { STAGE1 = 1, STAGE2 = 2, STAGE3 = 3 };
199  Q_ENUM(Stage)
200  enum Amc { AMCA = 1, AMCB = 2, AMCE = 3 };
201  Q_ENUM(Amc)
202 
203  explicit Channel(Cartridge *band, QObject *parent = 0);
204  Cartridge *band() const { return m_cart; }
205 
206  static bool validPolarization(int p);
207  static bool validElement(int s);
208  static bool validStage(int s);
209  static bool validAmc(int a);
210  Q_INVOKABLE double getValue(const QString &keyword);
211 
212  public slots:
213  static QScriptValue multiplier(QScriptContext *context, QScriptEngine *engine);
214  static QScriptValue amplifier(QScriptContext *context, QScriptEngine *engine);
215  static QScriptValue element(QScriptContext *context, QScriptEngine *engine);
216  // static QScriptValue mixer(QScriptContext *context, QScriptEngine *engine);
217  static QScriptValue oscillator(QScriptContext *context, QScriptEngine *engine);
218  static QScriptValue phaselock(QScriptContext *context, QScriptEngine *engine);
219  void initialize();
220  void resetBiases();
221  void resetCoilCurrents();
222  void cryoControl(bool flag);
223 
224  private:
225  Cartridge *m_cart;
226 };
227 
228 class ScriptRunner : public QObject
229 {
230  Q_OBJECT
231  public:
232  explicit ScriptRunner(const QString &scriptname, Cartridge *cartridge, QObject *parent = 0);
233  ~ScriptRunner();
234 
235  signals:
236  void done();
237 
238  public slots:
239  void run();
240  void report(const QString &txt);
241 
242  signals:
243  void console(const QString &txt);
244 
245  private:
246  QScriptEngine engine;
247  QString m_script;
248 };
249 
250 #endif // SCRIPTRUNNER_H
LNA stage 3.
Definition: constants.h:38
polarization POL1
Definition: constants.h:11
LNA stage 1.
Definition: constants.h:36
Element
An enumeration for the two mixer elements in each polarization.
Definition: constants.h:17
element SIS1
Definition: constants.h:18
A virtual class representing a cartridge.
Definition: cartridge.h:267
element SIS2
Definition: constants.h:19
polarization POL0
Definition: constants.h:10
LNA stage 2.
Definition: constants.h:37
Channel
An enumeration for the three SEPIA channels (cartridges).
Definition: constants.h:66