mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-08 20:20:44 +00:00
Refactor class hierarchy for serial port XML recording.
This commit is contained in:
parent
1630051dd1
commit
7c98af3f86
@ -23,12 +23,12 @@ static QString hex(int i)
|
|||||||
// MARK: -
|
// MARK: -
|
||||||
// MARK: XML record/playback base classes
|
// MARK: XML record/playback base classes
|
||||||
|
|
||||||
class XmlRecord
|
class XmlRecorder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XmlRecord(class QFile * file);
|
XmlRecorder(class QFile * file);
|
||||||
XmlRecord(QString & string);
|
XmlRecorder(QString & string);
|
||||||
~XmlRecord();
|
~XmlRecorder();
|
||||||
inline QXmlStreamWriter & xml() { return *m_xml; }
|
inline QXmlStreamWriter & xml() { return *m_xml; }
|
||||||
protected:
|
protected:
|
||||||
QFile* m_file; // nullptr for non-file recordings
|
QFile* m_file; // nullptr for non-file recordings
|
||||||
@ -65,7 +65,7 @@ public:
|
|||||||
virtual ~XmlReplayEvent() = default;
|
virtual ~XmlReplayEvent() = default;
|
||||||
virtual const QString & tag() const = 0;
|
virtual const QString & tag() const = 0;
|
||||||
|
|
||||||
void record(XmlRecord* xml);
|
void record(XmlRecorder* xml);
|
||||||
friend QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const XmlReplayEvent & event);
|
friend QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const XmlReplayEvent & event);
|
||||||
friend QXmlStreamReader & operator>>(QXmlStreamReader & xml, XmlReplayEvent & event);
|
friend QXmlStreamReader & operator>>(QXmlStreamReader & xml, XmlReplayEvent & event);
|
||||||
|
|
||||||
@ -84,25 +84,25 @@ protected:
|
|||||||
QHash<QString,XmlReplayEvent::FactoryMethod> XmlReplayEvent::s_factories;
|
QHash<QString,XmlReplayEvent::FactoryMethod> XmlReplayEvent::s_factories;
|
||||||
|
|
||||||
|
|
||||||
XmlRecord::XmlRecord(QFile* stream)
|
XmlRecorder::XmlRecorder(QFile* stream)
|
||||||
: m_file(stream), m_xml(new QXmlStreamWriter(stream))
|
: m_file(stream), m_xml(new QXmlStreamWriter(stream))
|
||||||
{
|
{
|
||||||
prologue();
|
prologue();
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlRecord::XmlRecord(QString & string)
|
XmlRecorder::XmlRecorder(QString & string)
|
||||||
: m_file(nullptr), m_xml(new QXmlStreamWriter(&string))
|
: m_file(nullptr), m_xml(new QXmlStreamWriter(&string))
|
||||||
{
|
{
|
||||||
prologue();
|
prologue();
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlRecord::~XmlRecord()
|
XmlRecorder::~XmlRecorder()
|
||||||
{
|
{
|
||||||
epilogue();
|
epilogue();
|
||||||
delete m_xml;
|
delete m_xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRecord::prologue()
|
void XmlRecorder::prologue()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_xml);
|
Q_ASSERT(m_xml);
|
||||||
m_xml->setAutoFormatting(true);
|
m_xml->setAutoFormatting(true);
|
||||||
@ -112,7 +112,7 @@ void XmlRecord::prologue()
|
|||||||
m_xml->writeStartElement("events");
|
m_xml->writeStartElement("events");
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRecord::epilogue()
|
void XmlRecorder::epilogue()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_xml);
|
Q_ASSERT(m_xml);
|
||||||
m_xml->writeEndElement(); // close events
|
m_xml->writeEndElement(); // close events
|
||||||
@ -205,7 +205,7 @@ XmlReplayEvent::XmlReplayEvent()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlReplayEvent::record(XmlRecord* writer)
|
void XmlReplayEvent::record(XmlRecorder* writer)
|
||||||
{
|
{
|
||||||
// Do nothing if we're not recording.
|
// Do nothing if we're not recording.
|
||||||
if (writer != nullptr) {
|
if (writer != nullptr) {
|
||||||
@ -333,7 +333,7 @@ void DeviceConnectionManager::record(QFile* stream)
|
|||||||
delete m_record;
|
delete m_record;
|
||||||
}
|
}
|
||||||
if (stream) {
|
if (stream) {
|
||||||
m_record = new XmlRecord(stream);
|
m_record = new XmlRecorder(stream);
|
||||||
} else {
|
} else {
|
||||||
// nullptr turns off recording
|
// nullptr turns off recording
|
||||||
m_record = nullptr;
|
m_record = nullptr;
|
||||||
@ -345,7 +345,7 @@ void DeviceConnectionManager::record(QString & string)
|
|||||||
if (m_record) {
|
if (m_record) {
|
||||||
delete m_record;
|
delete m_record;
|
||||||
}
|
}
|
||||||
m_record = new XmlRecord(string);
|
m_record = new XmlRecorder(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceConnectionManager::replay(const QString & string)
|
void DeviceConnectionManager::replay(const QString & string)
|
||||||
@ -524,10 +524,10 @@ bool SerialPortInfo::operator==(const SerialPortInfo & other) const
|
|||||||
|
|
||||||
// TODO: log these to XML stream
|
// TODO: log these to XML stream
|
||||||
|
|
||||||
class SerialPortEvent
|
class ConnectionEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SerialPortEvent(const QString & tag)
|
ConnectionEvent(const QString & tag)
|
||||||
: m_tag(tag)
|
: m_tag(tag)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -540,22 +540,13 @@ public:
|
|||||||
{
|
{
|
||||||
set(name, QString::number(value));
|
set(name, QString::number(value));
|
||||||
}
|
}
|
||||||
void checkResult(bool ok, QSerialPort::SerialPortError error)
|
void setData(const char* data, qint64 length)
|
||||||
{
|
{
|
||||||
if (ok && error == QSerialPort::NoError) return;
|
QStringList bytes;
|
||||||
set("error", error);
|
for (qint64 i = 0; i < length; i++) {
|
||||||
if (ok) set("ok", ok); // we don't expect to see this, but we should know if it happens
|
bytes.append(QString("%1").arg((unsigned char) data[i], 2, 16, QChar('0')).toUpper());
|
||||||
}
|
|
||||||
void checkResult(qint64 len, QSerialPort::SerialPortError error)
|
|
||||||
{
|
|
||||||
if (len < 0 || error != QSerialPort::NoError) {
|
|
||||||
set("error", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void checkError(QSerialPort::SerialPortError error) {
|
|
||||||
if (error != QSerialPort::NoError) {
|
|
||||||
set("error", error);
|
|
||||||
}
|
}
|
||||||
|
m_data = bytes.join(QChar(' '));
|
||||||
}
|
}
|
||||||
inline bool ok() const { return m_values.contains("error") == false; }
|
inline bool ok() const { return m_values.contains("error") == false; }
|
||||||
operator QString() const;
|
operator QString() const;
|
||||||
@ -565,20 +556,20 @@ protected:
|
|||||||
QHash<QString,QString> m_values;
|
QHash<QString,QString> m_values;
|
||||||
QList<QString> m_keys;
|
QList<QString> m_keys;
|
||||||
QString m_data;
|
QString m_data;
|
||||||
friend QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const SerialPortEvent & event);
|
friend QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const ConnectionEvent & event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetValueEvent : public SerialPortEvent
|
class SetValueEvent : public ConnectionEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetValueEvent(const QString & name, int value)
|
SetValueEvent(const QString & name, int value)
|
||||||
: SerialPortEvent("set")
|
: ConnectionEvent("set")
|
||||||
{
|
{
|
||||||
set(name, value);
|
set(name, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SerialPortEvent::operator QString() const
|
ConnectionEvent::operator QString() const
|
||||||
{
|
{
|
||||||
QString out;
|
QString out;
|
||||||
QXmlStreamWriter xml(&out);
|
QXmlStreamWriter xml(&out);
|
||||||
@ -586,7 +577,7 @@ SerialPortEvent::operator QString() const
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const SerialPortEvent & event)
|
QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const ConnectionEvent & event)
|
||||||
{
|
{
|
||||||
xml.writeStartElement(event.m_tag);
|
xml.writeStartElement(event.m_tag);
|
||||||
for (auto key : event.m_keys) {
|
for (auto key : event.m_keys) {
|
||||||
@ -599,132 +590,125 @@ QXmlStreamWriter & operator<<(QXmlStreamWriter & xml, const SerialPortEvent & ev
|
|||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataTransferEvent : public SerialPortEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DataTransferEvent(const QString & tag)
|
|
||||||
: SerialPortEvent(tag)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void setData(const char* data, qint64 length)
|
|
||||||
{
|
|
||||||
QStringList bytes;
|
|
||||||
for (qint64 i = 0; i < length; i++) {
|
|
||||||
bytes.append(QString("%1").arg((unsigned char) data[i], 2, 16, QChar('0')).toUpper());
|
|
||||||
}
|
|
||||||
m_data = bytes.join(QChar(' '));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
SerialPortConnection::SerialPortConnection(const QString & name)
|
||||||
SerialPort::SerialPort()
|
: m_portName(name)
|
||||||
{
|
{
|
||||||
connect(&m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
connect(&m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialPort::~SerialPort()
|
// TODO: temporary method for legacy compatibility
|
||||||
|
SerialPortConnection::SerialPortConnection()
|
||||||
|
{
|
||||||
|
connect(&m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialPortConnection::~SerialPortConnection()
|
||||||
{
|
{
|
||||||
disconnect(&m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
disconnect(&m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialPort::setPortName(const QString &name)
|
// TODO: temporary method for legacy compatibility
|
||||||
|
void SerialPortConnection::setPortName(const QString &name)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_portName.isEmpty());
|
Q_ASSERT(m_portName.isEmpty());
|
||||||
m_portName = name;
|
m_portName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This will eventually be open(), the constructor will be given the name, and the mode will always be ReadWrite
|
// TODO: This will eventually be open(), the constructor will be given the name, and the mode will always be ReadWrite
|
||||||
bool SerialPort::open(QIODevice::OpenMode mode)
|
bool SerialPortConnection::open(QIODevice::OpenMode mode)
|
||||||
{
|
{
|
||||||
Q_ASSERT(mode == QSerialPort::ReadWrite);
|
Q_ASSERT(mode == QSerialPort::ReadWrite);
|
||||||
SerialPortEvent event("openConnection");
|
ConnectionEvent event("openConnection");
|
||||||
event.set("type", "serial");
|
event.set("type", "serial");
|
||||||
event.set("port", m_portName);
|
event.set("port", m_portName);
|
||||||
|
|
||||||
m_port.setPortName(m_portName);
|
m_port.setPortName(m_portName);
|
||||||
event.checkResult(m_port.open(mode), m_port.error());
|
checkResult(m_port.open(mode), event);
|
||||||
|
|
||||||
|
// TODO: send this event back to manager to log
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
|
bool SerialPortConnection::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
|
||||||
{
|
{
|
||||||
SetValueEvent event("baudRate", baudRate);
|
SetValueEvent event("baudRate", baudRate);
|
||||||
event.set("directions", directions);
|
event.set("directions", directions);
|
||||||
|
|
||||||
event.checkResult(m_port.setBaudRate(baudRate, directions), m_port.error());
|
checkResult(m_port.setBaudRate(baudRate, directions), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::setDataBits(QSerialPort::DataBits dataBits)
|
bool SerialPortConnection::setDataBits(QSerialPort::DataBits dataBits)
|
||||||
{
|
{
|
||||||
SetValueEvent event("setDataBits", dataBits);
|
SetValueEvent event("setDataBits", dataBits);
|
||||||
|
|
||||||
event.checkResult(m_port.setDataBits(dataBits), m_port.error());
|
checkResult(m_port.setDataBits(dataBits), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::setParity(QSerialPort::Parity parity)
|
bool SerialPortConnection::setParity(QSerialPort::Parity parity)
|
||||||
{
|
{
|
||||||
SetValueEvent event("setParity", parity);
|
SetValueEvent event("setParity", parity);
|
||||||
|
|
||||||
event.checkResult(m_port.setParity(parity), m_port.error());
|
checkResult(m_port.setParity(parity), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::setStopBits(QSerialPort::StopBits stopBits)
|
bool SerialPortConnection::setStopBits(QSerialPort::StopBits stopBits)
|
||||||
{
|
{
|
||||||
SetValueEvent event("setStopBits", stopBits);
|
SetValueEvent event("setStopBits", stopBits);
|
||||||
|
|
||||||
event.checkResult(m_port.setStopBits(stopBits), m_port.error());
|
checkResult(m_port.setStopBits(stopBits), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::setFlowControl(QSerialPort::FlowControl flowControl)
|
bool SerialPortConnection::setFlowControl(QSerialPort::FlowControl flowControl)
|
||||||
{
|
{
|
||||||
SetValueEvent event("setFlowControl", flowControl);
|
SetValueEvent event("setFlowControl", flowControl);
|
||||||
|
|
||||||
event.checkResult(m_port.setFlowControl(flowControl), m_port.error());
|
checkResult(m_port.setFlowControl(flowControl), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::clear(QSerialPort::Directions directions)
|
bool SerialPortConnection::clear(QSerialPort::Directions directions)
|
||||||
{
|
{
|
||||||
SerialPortEvent event("clear");
|
ConnectionEvent event("clear");
|
||||||
event.set("directions", directions);
|
event.set("directions", directions);
|
||||||
|
|
||||||
event.checkResult(m_port.clear(directions), m_port.error());
|
checkResult(m_port.clear(directions), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SerialPort::bytesAvailable() const
|
qint64 SerialPortConnection::bytesAvailable() const
|
||||||
{
|
{
|
||||||
SerialPortEvent event("get");
|
ConnectionEvent event("get");
|
||||||
|
|
||||||
qint64 result = m_port.bytesAvailable();
|
qint64 result = m_port.bytesAvailable();
|
||||||
event.set("bytesAvailable", result);
|
event.set("bytesAvailable", result);
|
||||||
event.checkResult(result, m_port.error());
|
checkResult(result, event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SerialPort::read(char *data, qint64 maxSize)
|
qint64 SerialPortConnection::read(char *data, qint64 maxSize)
|
||||||
{
|
{
|
||||||
DataTransferEvent event("rx");
|
ConnectionEvent event("rx");
|
||||||
|
|
||||||
qint64 len = m_port.read(data, maxSize);
|
qint64 len = m_port.read(data, maxSize);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
@ -734,15 +718,15 @@ qint64 SerialPort::read(char *data, qint64 maxSize)
|
|||||||
if (len != maxSize) {
|
if (len != maxSize) {
|
||||||
event.set("req", maxSize);
|
event.set("req", maxSize);
|
||||||
}
|
}
|
||||||
event.checkResult(len, m_port.error());
|
checkResult(len, event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SerialPort::write(const char *data, qint64 maxSize)
|
qint64 SerialPortConnection::write(const char *data, qint64 maxSize)
|
||||||
{
|
{
|
||||||
DataTransferEvent event("tx");
|
ConnectionEvent event("tx");
|
||||||
|
|
||||||
event.setData(data, maxSize);
|
event.setData(data, maxSize);
|
||||||
qint64 len = m_port.write(data, maxSize);
|
qint64 len = m_port.write(data, maxSize);
|
||||||
@ -750,25 +734,25 @@ qint64 SerialPort::write(const char *data, qint64 maxSize)
|
|||||||
if (len != maxSize) {
|
if (len != maxSize) {
|
||||||
event.set("req", maxSize);
|
event.set("req", maxSize);
|
||||||
}
|
}
|
||||||
event.checkResult(len, m_port.error());
|
checkResult(len, event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialPort::flush()
|
bool SerialPortConnection::flush()
|
||||||
{
|
{
|
||||||
SerialPortEvent event("flush");
|
ConnectionEvent event("flush");
|
||||||
|
|
||||||
event.checkResult(m_port.flush(), m_port.error());
|
checkResult(m_port.flush(), event);
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
|
|
||||||
return event.ok();
|
return event.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialPort::close()
|
void SerialPortConnection::close()
|
||||||
{
|
{
|
||||||
SerialPortEvent event("closeConnection");
|
ConnectionEvent event("closeConnection");
|
||||||
event.set("type", "serial");
|
event.set("type", "serial");
|
||||||
event.set("port", m_portName);
|
event.set("port", m_portName);
|
||||||
|
|
||||||
@ -779,14 +763,14 @@ void SerialPort::close()
|
|||||||
// the older replays will still work as expected.
|
// the older replays will still work as expected.
|
||||||
|
|
||||||
m_port.close();
|
m_port.close();
|
||||||
event.checkError(m_port.error());
|
checkError(event);
|
||||||
|
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialPort::onReadyRead()
|
void SerialPortConnection::onReadyRead()
|
||||||
{
|
{
|
||||||
SerialPortEvent event("readyRead");
|
ConnectionEvent event("readyRead");
|
||||||
|
|
||||||
// TODO: Most of the playback API reponds to the caller. How do we replay port-driven events?
|
// TODO: Most of the playback API reponds to the caller. How do we replay port-driven events?
|
||||||
qDebug().noquote() << event;
|
qDebug().noquote() << event;
|
||||||
@ -794,3 +778,26 @@ void SerialPort::onReadyRead()
|
|||||||
emit readyRead();
|
emit readyRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SerialPortConnection::checkResult(bool ok, ConnectionEvent & event) const
|
||||||
|
{
|
||||||
|
QSerialPort::SerialPortError error = m_port.error();
|
||||||
|
if (ok && error == QSerialPort::NoError) return;
|
||||||
|
event.set("error", error);
|
||||||
|
if (ok) event.set("ok", ok); // we don't expect to see this, but we should know if it happens
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialPortConnection::checkResult(qint64 len, ConnectionEvent & event) const
|
||||||
|
{
|
||||||
|
QSerialPort::SerialPortError error = m_port.error();
|
||||||
|
if (len < 0 || error != QSerialPort::NoError) {
|
||||||
|
event.set("error", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialPortConnection::checkError(ConnectionEvent & event) const
|
||||||
|
{
|
||||||
|
QSerialPort::SerialPortError error = m_port.error();
|
||||||
|
if (error != QSerialPort::NoError) {
|
||||||
|
event.set("error", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,7 +26,7 @@ class DeviceConnectionManager : public QObject
|
|||||||
private:
|
private:
|
||||||
DeviceConnectionManager();
|
DeviceConnectionManager();
|
||||||
|
|
||||||
class XmlRecord* m_record;
|
class XmlRecorder* m_record;
|
||||||
class XmlReplay* m_replay;
|
class XmlReplay* m_replay;
|
||||||
|
|
||||||
QList<class SerialPortInfo> replayAvailablePorts();
|
QList<class SerialPortInfo> replayAvailablePorts();
|
||||||
@ -49,16 +49,24 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DeviceConnection : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: This class may eventually be internal to a DeviceConnection class,
|
// TODO: This class may eventually be internal to a DeviceConnection class,
|
||||||
// but for now it is used to provide support for recording and playback of
|
// but for now it is used to provide support for recording and playback of
|
||||||
// serial port connections before refactoring.
|
// serial port connections before refactoring.
|
||||||
class SerialPort : public QObject
|
class SerialPortConnection : public DeviceConnection
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSerialPort m_port;
|
QSerialPort m_port;
|
||||||
QString m_portName;
|
QString m_portName;
|
||||||
|
void checkResult(bool ok, class ConnectionEvent & event) const;
|
||||||
|
void checkResult(qint64 len, class ConnectionEvent & event) const;
|
||||||
|
void checkError(class ConnectionEvent & event) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onReadyRead();
|
void onReadyRead();
|
||||||
@ -67,10 +75,13 @@ signals:
|
|||||||
void readyRead();
|
void readyRead();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerialPort();
|
// TODO: temporary methods for legacy compatibility
|
||||||
virtual ~SerialPort();
|
SerialPortConnection();
|
||||||
|
|
||||||
void setPortName(const QString &name);
|
void setPortName(const QString &name);
|
||||||
|
|
||||||
|
SerialPortConnection(const QString &name);
|
||||||
|
virtual ~SerialPortConnection();
|
||||||
|
|
||||||
bool open(QIODevice::OpenMode mode);
|
bool open(QIODevice::OpenMode mode);
|
||||||
bool setBaudRate(qint32 baudRate, QSerialPort::Directions directions = QSerialPort::AllDirections);
|
bool setBaudRate(qint32 baudRate, QSerialPort::Directions directions = QSerialPort::AllDirections);
|
||||||
bool setDataBits(QSerialPort::DataBits dataBits);
|
bool setDataBits(QSerialPort::DataBits dataBits);
|
||||||
@ -86,6 +97,11 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: temporary class for legacy compatibility
|
||||||
|
class SerialPort : public SerialPortConnection
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: This class's functionality will eventually be internal to a
|
// TODO: This class's functionality will eventually be internal to a
|
||||||
// DeviceConnection class, but for now it is needed to support recording
|
// DeviceConnection class, but for now it is needed to support recording
|
||||||
// and playback of serial port scanning before refactoring.
|
// and playback of serial port scanning before refactoring.
|
||||||
|
Loading…
Reference in New Issue
Block a user