SEPIA
Software documentation for the APEX SEPIA receivers
powermeter.h
Go to the documentation of this file.
1 /* Copyright 2018 Michael Olberg <michael.olberg@chalmers.se> */
2 #ifndef POWERMETER_H
3 #define POWERMETER_H
4 
5 #include <QObject>
6 #include <QTcpSocket>
7 #include <QByteArray>
8 #include <QString>
9 
19 class PowerMeter : public QObject {
20  Q_OBJECT
21 
22  public:
26  static PowerMeter *instance()
27  {
28  if (pm_instance == 0) pm_instance = new PowerMeter();
29  return pm_instance;
30  }
31 
32  ~PowerMeter();
33 
34  void init();
35  float reading();
36  bool isConnected() { return m_connected; }
37 
38  signals:
39  // void error();
40  void connectionStatus(bool ok);
41  void newReading(float p);
42 
43  private:
44  static PowerMeter *pm_instance;
45  PowerMeter();
46 
47  void connectToServer();
48  void closeConnection();
49  int tcpSendReceive(QString command, bool interactive);
50  void dumpBuffer(QByteArray ba, bool in) const;
51 
52  void dumpBuffer(bool out, char* buf) const;
53 
54  double power;
55  QByteArray sendBuffer;
56  QByteArray recvBuffer;
57  QTcpSocket socket;
58  bool m_connected;
59 };
60 
61 #endif // POWERMETER_H
A class to control the power meter.
Definition: powermeter.h:19
void init()
Initialize instrument for power readings.
Definition: powermeter.cpp:86
bool isConnected()
Return connection status.
Definition: powermeter.h:36
float reading()
Get one reading from the selected gauge.
Definition: powermeter.cpp:104
static PowerMeter * instance()
Get a pointer to a class PowerMeter instance.
Definition: powermeter.h:26