qpidctrl  0.7.1
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
QPTC10Simulator Class Reference

#include <qptc10simulator.h>

Inheritance diagram for QPTC10Simulator:
Inheritance graph

Public Member Functions

 QPTC10Simulator (QPTC10DeviceWPtr device)
 
virtual ~QPTC10Simulator ()
 
- Public Member Functions inherited from QPidSimulator
 QPidSimulator (QObject *parent=0)
 

Protected Member Functions

qint64 readData (char *data, qint64 maxlen)
 
qint64 writeData (const char *data, qint64 len)
 
qint64 readLineData (char *data, qint64 maxlen)
 
bool canReadLine () const
 
bool waitForReadyRead (int msecs)
 
void printMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 

Private Member Functions

void reply (QString rply)
 

Private Attributes

QPTC10DeviceWPtr m_Device
 
QStringList m_Replies
 
QString m_OutputLevel
 
QString m_Temperature
 
QString m_SetPoint
 
QString m_RampPoint
 
QString m_RampRate
 
QString m_CtrlMode
 
QString m_Enabled
 
QString m_LoopEnabled
 

Detailed Description

Definition at line 9 of file qptc10simulator.h.

Constructor & Destructor Documentation

QPTC10Simulator::QPTC10Simulator ( QPTC10DeviceWPtr  device)
explicit

Definition at line 8 of file qptc10simulator.cpp.

8  :
9  QPidSimulator(NULL),
10  m_Device(device),
11  m_OutputLevel("75"),
12  m_Temperature("23"),
13  m_SetPoint("42"),
14  m_RampPoint("42"),
15  m_RampRate("10"),
16  m_CtrlMode("Off"),
17  m_Enabled("Off"),
18  m_LoopEnabled("Off")
19 {
20 }
QPidSimulator(QObject *parent=0)
QPTC10DeviceWPtr m_Device
QPTC10Simulator::~QPTC10Simulator ( )
virtual

Definition at line 22 of file qptc10simulator.cpp.

23 {
24 }

Member Function Documentation

bool QPTC10Simulator::canReadLine ( ) const
protected

Definition at line 129 of file qptc10simulator.cpp.

References DEBUG_PTC10SIM, m_Replies, and printMessage().

130 {
131  if (qcepDebug(DEBUG_PTC10SIM)) {
132  printMessage(tr("QPTC10Simulator::canReadLine %1").arg(m_Replies.count()));
133  }
134 
135  return m_Replies.count();
136 }
QStringList m_Replies
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void QPTC10Simulator::printMessage ( QString  msg,
QDateTime  ts = QDateTime::currentDateTime() 
) const
protected

Definition at line 152 of file qptc10simulator.cpp.

References m_Device.

Referenced by canReadLine(), reply(), and writeData().

153 {
155 
156  if (dev) {
157  dev->printMessage(msg, ts);
158  }
159 }
QSharedPointer< QPTC10Device > QPTC10DevicePtr
QPTC10DeviceWPtr m_Device
qint64 QPTC10Simulator::readData ( char *  data,
qint64  maxlen 
)
protected

Definition at line 26 of file qptc10simulator.cpp.

References m_Replies.

Referenced by readLineData().

27 {
28  if (m_Replies.count() > 0) {
29  strncpy(data, qPrintable(m_Replies.takeFirst()), maxlen);
30 
31  return strlen(data);
32  } else {
33  return -1;
34  }
35 }
QStringList m_Replies
qint64 QPTC10Simulator::readLineData ( char *  data,
qint64  maxlen 
)
protected

Definition at line 37 of file qptc10simulator.cpp.

References readData().

38 {
39  return readData(data, maxlen);
40 }
qint64 readData(char *data, qint64 maxlen)
void QPTC10Simulator::reply ( QString  rply)
private

Definition at line 118 of file qptc10simulator.cpp.

References DEBUG_PTC10SIM, m_Replies, and printMessage().

Referenced by writeData().

119 {
120  if (qcepDebug(DEBUG_PTC10SIM)) {
121  printMessage(tr("QPTC10Simulator::reply %1").arg(rply));
122  }
123 
124  m_Replies.append(rply+"\n");
125 
126  emit readyRead();
127 }
QStringList m_Replies
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
bool QPTC10Simulator::waitForReadyRead ( int  msecs)
protected

Definition at line 138 of file qptc10simulator.cpp.

References m_Replies.

139 {
140  if (m_Replies.count()) {
141  return true;
142  } else {
143  QWaitCondition waitCondition;
144  QMutex mutex;
145 
146  waitCondition.wait(&mutex, msecs);
147 
148  return m_Replies.count();
149  }
150 }
QStringList m_Replies
qint64 QPTC10Simulator::writeData ( const char *  data,
qint64  len 
)
protected

Definition at line 42 of file qptc10simulator.cpp.

References DEBUG_PTC10SIM, m_Enabled, m_LoopEnabled, m_OutputLevel, m_RampPoint, m_RampRate, m_SetPoint, m_Temperature, printMessage(), and reply().

43 {
44  QString cmd(data);
45 
46  if (qcepDebug(DEBUG_PTC10SIM)) {
47  printMessage(tr("QPTC10Simulator::writeData %1, %2, %3").arg(data).arg(strlen(data)).arg(len));
48  }
49 
50  if (cmd == "\"Control.PID.Mode?\"\n") {
52  } else if (cmd == "\"Control.PID.Setpoint?\"\n") {
54  } else if (cmd == "\"Control.PID.RampT?\"\n") {
56  } else if (cmd == "\"Control.PID.Ramp?\"\n") {
58  } else if (cmd == "outputEnable?\n") {
60  } else if (cmd == "\"Control?\"\n") {
62  } else if (cmd == "\"TC?\"\n") {
64  } else if (cmd == "getOutput\n") {
65  reply(tr("%1, %2, 0, 0").arg(m_OutputLevel).arg(m_Temperature));
66  } else if (cmd == "getOutput.names\n") {
67  reply("Control, TC, Chan C, Chan D");
68  } else if (cmd == "getOutput.units\n") {
69  reply("%, degC, V, W");
70  } else if (cmd == "system.com.verbose medium\n") {
71  } else if (cmd == "\"TC.PID.Mode?\"\n") {
72  reply("Error: non-exist");
73  } else if (cmd == "\"Chan C.PID.Mode?\"\n") {
74  reply("Error: non-exist");
75  } else if (cmd == "\"Chan D.PID.Mode?\"\n") {
76  reply("Off");
77  } else {
78  QRegExp regex("\"Control\\.PID\\.Setpoint\"\\s+(\\S*)\\n");
79 
80  if (regex.exactMatch(cmd)) {
81  m_SetPoint = regex.capturedTexts()[1];
82 
83  return len;
84  } else {
85  QRegExp regex("\"Control\\.PID\\.Ramp\"\\s+(\\S*)\\n");
86 
87  if (regex.exactMatch(cmd)) {
88  m_RampRate = regex.capturedTexts()[1];
89 
90  return len;
91  } else {
92  QRegExp regex("\"Control\\.PID\\.Mode\"\\s+(\\S*)\\n");
93 
94  if (regex.exactMatch(cmd)) {
95  m_LoopEnabled = regex.capturedTexts()[1];
96 
97  return len;
98  } else {
99  QRegExp regex("outputEnable\\s+(\\S*)\\n");
100 
101  if (regex.exactMatch(cmd)) {
102  m_Enabled = regex.capturedTexts()[1];
103 
104  return len;
105  }
106  }
107  }
108  }
109 
110  printMessage(tr("Unrecognized PTC10 Command %1").arg(cmd));
111 
112  reply(tr("Error: %1").arg(cmd));
113  }
114 
115  return len;
116 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void reply(QString rply)

Member Data Documentation

QString QPTC10Simulator::m_CtrlMode
private

Definition at line 39 of file qptc10simulator.h.

QPTC10DeviceWPtr QPTC10Simulator::m_Device
private

Definition at line 32 of file qptc10simulator.h.

Referenced by printMessage().

QString QPTC10Simulator::m_Enabled
private

Definition at line 40 of file qptc10simulator.h.

Referenced by writeData().

QString QPTC10Simulator::m_LoopEnabled
private

Definition at line 41 of file qptc10simulator.h.

Referenced by writeData().

QString QPTC10Simulator::m_OutputLevel
private

Definition at line 34 of file qptc10simulator.h.

Referenced by writeData().

QString QPTC10Simulator::m_RampPoint
private

Definition at line 37 of file qptc10simulator.h.

Referenced by writeData().

QString QPTC10Simulator::m_RampRate
private

Definition at line 38 of file qptc10simulator.h.

Referenced by writeData().

QStringList QPTC10Simulator::m_Replies
private

Definition at line 33 of file qptc10simulator.h.

Referenced by canReadLine(), readData(), reply(), and waitForReadyRead().

QString QPTC10Simulator::m_SetPoint
private

Definition at line 36 of file qptc10simulator.h.

Referenced by writeData().

QString QPTC10Simulator::m_Temperature
private

Definition at line 35 of file qptc10simulator.h.

Referenced by writeData().


The documentation for this class was generated from the following files: