MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / evaluateTransmitFunction

Method evaluateTransmitFunction

app/src/UI/Widgets/Output/Base.cpp:158–189  ·  view source on GitHub ↗

* @brief Runs the JavaScript transmit(value) function and returns the result as a QByteArray. */

Source from the content-addressed store, hash-verified

156 * @brief Runs the JavaScript transmit(value) function and returns the result as a QByteArray.
157 */
158QByteArray Widgets::Output::Base::evaluateTransmitFunction(const QVariant& value)
159{
160 if (!m_hasFn)
161 return {};
162
163 auto jsValue = m_jsEngine.toScriptValue(value);
164 QJSValueList args = QJSValueList{jsValue};
165 auto result = m_watchdog.call(m_transmitFn, args);
166
167 if (m_watchdog.lastCallTimedOut()) [[unlikely]] {
168 Q_EMIT transmitError(tr("Transmit script timed out after %1 ms").arg(kTransmitWatchdogMs));
169 return {};
170 }
171
172 if (result.isError()) [[unlikely]] {
173 Q_EMIT transmitError(result.toString());
174 return {};
175 }
176
177 QByteArray data;
178 if (result.isString())
179 data = SerialStudio::encodeText(result.toString(), m_txEncoding);
180 else
181 data = result.toVariant().toByteArray();
182
183 if (data.size() > kMaxPayloadBytes) [[unlikely]] {
184 Q_EMIT transmitError(tr("Payload exceeds maximum size"));
185 return {};
186 }
187
188 return data;
189}
190
191//--------------------------------------------------------------------------------------------------
192// Protocol helper injection

Callers

nothing calls this directly

Calls 5

lastCallTimedOutMethod · 0.80
isErrorMethod · 0.80
toVariantMethod · 0.80
callMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected