mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-05 13:32:05 +08:00
484eed0acf
* refactor livestream into devicestream * add panda stream * unused * whitespace * move logging to base class * add cmdline args * Update selfdrive/boardd/boardd.cc --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 2a981f553162ff41dd50ed6921b90ac512efa3d2
28 lines
829 B
C++
28 lines
829 B
C++
#include "tools/cabana/streams/devicestream.h"
|
|
|
|
DeviceStream::DeviceStream(QObject *parent, QString address) : zmq_address(address), LiveStream(parent) {
|
|
}
|
|
|
|
void DeviceStream::streamThread() {
|
|
if (!zmq_address.isEmpty()) {
|
|
setenv("ZMQ", "1", 1);
|
|
}
|
|
|
|
std::unique_ptr<Context> context(Context::create());
|
|
std::string address = zmq_address.isEmpty() ? "127.0.0.1" : zmq_address.toStdString();
|
|
std::unique_ptr<SubSocket> sock(SubSocket::create(context.get(), "can", address));
|
|
assert(sock != NULL);
|
|
sock->setTimeout(50);
|
|
// run as fast as messages come in
|
|
while (!QThread::currentThread()->isInterruptionRequested()) {
|
|
Message *msg = sock->receive(true);
|
|
if (!msg) {
|
|
QThread::msleep(50);
|
|
continue;
|
|
}
|
|
|
|
std::lock_guard lk(lock);
|
|
handleEvent(messages.emplace_back(msg).event);
|
|
}
|
|
}
|