Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
46 lines
2.1 KiB
C++
46 lines
2.1 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
#pragma once
|
|
#include "config_export.h"
|
|
#include <QSet>
|
|
#include <QMap>
|
|
// Decode intent only. No raw QML payload is ever passed to a device transport.
|
|
static bool qmlReadCode(int code) {
|
|
return QList<int>{0,4,14,17,31,32,33,65,96}.contains(code);
|
|
}
|
|
// Identification is outside the upstream limited-mode list. Configuration
|
|
// admission belongs to the exact schema already qualified by the engine.
|
|
static bool qmlReadSupported(Commands *commands, int code) {
|
|
return qmlReadCode(code) && (code==0||code==14||code==17||
|
|
commands->getLimitedCompatibilityCommands().contains(code));
|
|
}
|
|
static QJsonObject qmlReadIntent(const QByteArray &raw) {
|
|
if(raw.isEmpty())return {};
|
|
const int code=quint8(raw[0]);
|
|
if(!qmlReadCode(code)||raw.size()!=(code==65?3:1))return {};
|
|
QJsonObject out{{"command",code}};
|
|
if(code==65)out.insert("mask",(quint8(raw[1])<<8)|quint8(raw[2]));
|
|
return out;
|
|
}
|
|
static void validateQmlRead(const QJsonObject &intent) {
|
|
const auto value=intent.value("command");const int code=value.toInt(-1);
|
|
require(value.isDouble()&&value.toDouble()==code&&qmlReadCode(code),"QML read is not admitted");
|
|
require(intent.size()==(code==65?2:1),"Invalid QML read shape");
|
|
if(code==65){const auto mask=intent.value("mask");require(mask.isDouble()&&mask.toDouble()==mask.toInt(-1)&&mask.toInt(-1)>=0&&mask.toInt(-1)<=65535,"Invalid IMU read mask");}
|
|
}
|
|
class QmlReadQueue {
|
|
public:
|
|
bool enabled;int blocked=0;QMap<int,QJsonObject> pending;QSet<int> blockedCodes;
|
|
explicit QmlReadQueue(bool live):enabled(live){}
|
|
void capture(const QByteArray &raw) {
|
|
auto intent=qmlReadIntent(raw);
|
|
if(!enabled||intent.isEmpty()) {
|
|
if(blocked<1000000)++blocked;
|
|
if(blockedCodes.size()<32&&!raw.isEmpty())blockedCodes.insert(quint8(raw[0]));
|
|
return;
|
|
}
|
|
pending.insert(intent.value("command").toInt(),intent);
|
|
}
|
|
QJsonArray take() {QJsonArray out;for(const auto &intent:pending)out.append(intent);pending.clear();return out;}
|
|
QJsonArray rejected() const {QJsonArray out;for(int code:blockedCodes)out.append(code);return out;}
|
|
};
|