Changeset View
Changeset View
Standalone View
Standalone View
src/core/seriallayer.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 77 | { | |||
---|---|---|---|---|---|
82 | // Proper line endings are added when the command is pushed. | 82 | // Proper line endings are added when the command is pushed. | ||
83 | d->_rawData = d->_rawData.replace(_return, QByteArray()); | 83 | d->_rawData = d->_rawData.replace(_return, QByteArray()); | ||
84 | 84 | | |||
85 | QList<QByteArray> tempList = d->_rawData.split(_newLine.at(0)); | 85 | QList<QByteArray> tempList = d->_rawData.split(_newLine.at(0)); | ||
86 | for (auto i = tempList.begin(); i != tempList.end(); ++i) { | 86 | for (auto i = tempList.begin(); i != tempList.end(); ++i) { | ||
87 | // Get finished line to _byteCommands | 87 | // Get finished line to _byteCommands | ||
88 | if (i < tempList.end() - 1) { | 88 | if (i < tempList.end() - 1) { | ||
89 | d->_rByteCommands.append(*i); | 89 | d->_rByteCommands.append(*i); | ||
90 | emit(receivedCommand(*i)); | 90 | emit receivedCommand(*i); | ||
91 | } else { | 91 | } else { | ||
92 | d->_rawData.clear(); | 92 | d->_rawData.clear(); | ||
93 | d->_rawData.append(*i); | 93 | d->_rawData.append(*i); | ||
94 | } | 94 | } | ||
95 | } | 95 | } | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | void SerialLayer::pushCommand(const QByteArray &comm, const QByteArray &term) | 98 | void SerialLayer::pushCommand(const QByteArray &comm, const QByteArray &term) | ||
99 | { | 99 | { | ||
100 | if (!isOpen()) { | 100 | if (!isOpen()) { | ||
101 | qCDebug(SERIAL_LAYER) << "Serial not connected !"; | 101 | qCDebug(SERIAL_LAYER) << "Serial not connected !"; | ||
102 | return; | 102 | return; | ||
103 | } | 103 | } | ||
104 | QByteArray tmp = comm + term; | 104 | QByteArray tmp = comm + term; | ||
105 | write(tmp); | 105 | write(tmp); | ||
106 | emit(pushedCommand(tmp)); | 106 | emit pushedCommand(tmp); | ||
107 | 107 | | |||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | void SerialLayer::pushCommand(const QByteArray &comm) | 110 | void SerialLayer::pushCommand(const QByteArray &comm) | ||
111 | { | 111 | { | ||
112 | pushCommand(comm, _newLineReturn); | 112 | pushCommand(comm, _newLineReturn); | ||
113 | } | 113 | } | ||
114 | 114 | | |||
Show All 11 Lines | |||||
126 | void SerialLayer::push() | 126 | void SerialLayer::push() | ||
127 | { | 127 | { | ||
128 | if (!isOpen()) { | 128 | if (!isOpen()) { | ||
129 | qCDebug(SERIAL_LAYER) << "Serial not connected !"; | 129 | qCDebug(SERIAL_LAYER) << "Serial not connected !"; | ||
130 | return; | 130 | return; | ||
131 | } | 131 | } | ||
132 | for (const auto &comm : d->_sByteCommands) { | 132 | for (const auto &comm : d->_sByteCommands) { | ||
133 | write(comm); | 133 | write(comm); | ||
134 | emit(pushedCommand(comm)); | 134 | emit pushedCommand(comm); | ||
135 | } | 135 | } | ||
136 | d->_sByteCommands.clear(); | 136 | d->_sByteCommands.clear(); | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | bool SerialLayer::commandAvailable() const | 139 | bool SerialLayer::commandAvailable() const | ||
140 | { | 140 | { | ||
141 | return !d->_rByteCommands.isEmpty(); | 141 | return !d->_rByteCommands.isEmpty(); | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | QStringList SerialLayer::validBaudRates() const | 144 | QStringList SerialLayer::validBaudRates() const | ||
145 | { | 145 | { | ||
146 | return _validBaudRates; | 146 | return _validBaudRates; | ||
147 | } | 147 | } |