openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.5 KiB

#include "replay.h"
#include "selfdrive/hardware/hw.h"
Replay::Replay(QString route_, int seek) : route(route_) {
unlogger = new Unlogger(&events, &events_lock, &frs, seek);
current_segment = 0;
bool create_jwt = !Hardware::PC();
http = new HttpRequest(this, "https://api.commadotai.com/v1/route/" + route + "/files", "", create_jwt);
QObject::connect(http, &HttpRequest::receivedResponse, this, &Replay::parseResponse);
}
void Replay::parseResponse(const QString &response){
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8());
if (doc.isNull()) {
qDebug() << "JSON Parse failed";
return;
}
camera_paths = doc["cameras"].toArray();
log_paths = doc["logs"].toArray();
// add first segment
addSegment(0);
}
void Replay::addSegment(int i){
if (lrs.find(i) != lrs.end()) {
return;
}
QThread* thread = new QThread;
QString log_fn = this->log_paths.at(i).toString();
lrs.insert(i, new LogReader(log_fn, &events, &events_lock, &unlogger->eidx));
lrs[i]->moveToThread(thread);
QObject::connect(thread, &QThread::started, lrs[i], &LogReader::process);
thread->start();
QString camera_fn = this->camera_paths.at(i).toString();
frs.insert(i, new FrameReader(qPrintable(camera_fn)));
}
void Replay::stream(SubMaster *sm){
QThread* thread = new QThread;
unlogger->moveToThread(thread);
QObject::connect(thread, &QThread::started, [=](){
unlogger->process(sm);
});
thread->start();
QObject::connect(unlogger, &Unlogger::loadSegment, [=](){
addSegment(++current_segment);
});
}