mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-15 14:51:14 -08:00
example 'meshtastic': fix USB mode (desktop) to work with all of: HELTEC, LILYGO, RAK
This commit is contained in:
parent
de804d20f9
commit
b8b34b36c4
3 changed files with 36 additions and 32 deletions
|
|
@ -14,6 +14,9 @@ USB_ME::USB_ME(Connection* _con) : con(_con) {
|
|||
}
|
||||
});
|
||||
setBaudRate(Baud115200);
|
||||
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, this, &USB_ME::done);
|
||||
}
|
||||
|
||||
void USB_ME::connectToRadio() {
|
||||
|
|
@ -26,10 +29,10 @@ void USB_ME::connectToRadio() {
|
|||
}
|
||||
|
||||
const auto infos = QSerialPortInfo::availablePorts();
|
||||
// tested with RAK 4631, LILYGO T-Beam
|
||||
// tested with HELTEC V3, LILYGO T-Beam, RAK 4631
|
||||
const QStringList supported = { "RAK", "UART", "USB" };
|
||||
for (auto info : infos) {
|
||||
QString name(info.description() + " " + info.manufacturer());
|
||||
QString name(info.manufacturer() + " | " + info.description());
|
||||
QString port(info.portName());
|
||||
if (port.startsWith("tty") &&
|
||||
(port.contains("ACM", Qt::CaseInsensitive) || // Linux
|
||||
|
|
@ -37,7 +40,10 @@ void USB_ME::connectToRadio() {
|
|||
for (auto s : supported) {
|
||||
if (name.contains(s, Qt::CaseInsensitive)) {
|
||||
setPortName(info.portName());
|
||||
qDebug() << "USB:" << port << name;
|
||||
qDebug() << "USB:" << port
|
||||
<< "VID" << info.vendorIdentifier()
|
||||
<< "PID" << info.productIdentifier()
|
||||
<< "name" << name;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,41 +76,22 @@ void USB_ME::write2(const QByteArray& data) {
|
|||
}
|
||||
|
||||
void USB_ME::read2() {
|
||||
const QByteArray HEADER = QByteArray::fromHex("94c3");
|
||||
QByteArray data(readAll());
|
||||
|
||||
if (data.startsWith(HEADER)) { // skip evtl. debug log
|
||||
// split on every new header
|
||||
const int LEN = 4;
|
||||
int end = 0;
|
||||
int start = LEN;
|
||||
while ((end = data.indexOf(HEADER, start)) != -1) {
|
||||
received(data.mid(start, end - start));
|
||||
start = end + LEN;
|
||||
}
|
||||
received(data.mid(start));
|
||||
|
||||
static QTimer* timer = nullptr;
|
||||
if (timer == nullptr) {
|
||||
timer = new QTimer;
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, this, &USB_ME::done);
|
||||
}
|
||||
timer->start(1000); // assume receiving done after pause of 1 sec
|
||||
}
|
||||
packets << readAll();
|
||||
timer.start(1000); // assume receiving done after pause of 1 sec
|
||||
}
|
||||
|
||||
void USB_ME::received(const QByteArray& data) {
|
||||
if (con->backgroundMode) {
|
||||
con->saveBytes(data);
|
||||
} else {
|
||||
con->receivedFromRadio(QVariant(QVariantList() << data));
|
||||
if (!data.isEmpty()) {
|
||||
if (con->backgroundMode) {
|
||||
con->saveBytes(data);
|
||||
} else {
|
||||
con->receivedFromRadio(QVariant(QVariantList() << data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void USB_ME::done() {
|
||||
if (!con->backgroundMode) {
|
||||
con->receivingDone();
|
||||
static bool startup = true;
|
||||
if (startup) {
|
||||
con->sendSavedBytes(); // for eventual, saved but not sent packets
|
||||
|
|
@ -112,5 +99,19 @@ void USB_ME::done() {
|
|||
startup = false;
|
||||
}
|
||||
}
|
||||
|
||||
const QByteArray HEADER = QByteArray::fromHex("94c3");
|
||||
const int LEN = 4;
|
||||
QByteArray data(packets.join());
|
||||
packets.clear();
|
||||
int start = 0;
|
||||
while ((start = data.indexOf(HEADER, start)) != -1) {
|
||||
int i_len = start + 2;
|
||||
int len = (data.at(i_len) << 8) + data.at(i_len + 1);
|
||||
received(data.mid(start + LEN, len));
|
||||
start += LEN + len;
|
||||
}
|
||||
|
||||
con->receivingDone();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue