replay: print colored text (#22771)

old-commit-hash: 09858f7f6f
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent 07ffd9c095
commit 526cfdd0fb
  1. 15
      selfdrive/ui/replay/main.cc
  2. 16
      selfdrive/ui/replay/replay.cc

@ -75,7 +75,22 @@ void keyboardThread(Replay *replay) {
} }
} }
void replayMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QByteArray localMsg = msg.toLocal8Bit();
if (type == QtDebugMsg) {
std::cout << "\033[38;5;248m" << localMsg.constData() << "\033[00m" << std::endl;
} else if (type == QtWarningMsg) {
std::cout << "\033[38;5;227m" << localMsg.constData() << "\033[00m" << std::endl;
} else if (type == QtCriticalMsg) {
std::cout << "\033[38;5;196m" << localMsg.constData() << "\033[00m" << std::endl;
} else {
std::cout << localMsg.constData() << std::endl;
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
qInstallMessageHandler(replayMessageOutput);
QApplication app(argc, argv); QApplication app(argc, argv);
std::signal(SIGINT, sigHandler); std::signal(SIGINT, sigHandler);
std::signal(SIGTERM, sigHandler); std::signal(SIGTERM, sigHandler);

@ -58,7 +58,7 @@ void Replay::stop() {
bool Replay::load() { bool Replay::load() {
if (!route_->load()) { if (!route_->load()) {
qDebug() << "failed to load route" << route_->name() << "from server"; qCritical() << "failed to load route" << route_->name() << "from server";
return false; return false;
} }
@ -68,10 +68,10 @@ bool Replay::load() {
} }
} }
if (segments_.empty()) { if (segments_.empty()) {
qDebug() << "no valid segments in route" << route_->name(); qCritical() << "no valid segments in route" << route_->name();
return false; return false;
} }
qDebug() << "load route" << route_->name() << "with" << segments_.size() << "valid segments"; qInfo() << "load route" << route_->name() << "with" << segments_.size() << "valid segments";
return true; return true;
} }
@ -100,7 +100,7 @@ void Replay::doSeek(int seconds, bool relative) {
seconds = std::max(0, seconds); seconds = std::max(0, seconds);
int seg = seconds / 60; int seg = seconds / 60;
if (segments_.find(seg) == segments_.end()) { if (segments_.find(seg) == segments_.end()) {
qInfo() << "can't seek to" << seconds << "s, segment" << seg << "is invalid"; qWarning() << "can't seek to" << seconds << "s, segment" << seg << "is invalid";
return true; return true;
} }
@ -114,7 +114,7 @@ void Replay::doSeek(int seconds, bool relative) {
void Replay::pause(bool pause) { void Replay::pause(bool pause) {
updateEvents([=]() { updateEvents([=]() {
qDebug() << (pause ? "paused..." : "resuming"); qInfo() << (pause ? "paused..." : "resuming");
if (pause) { if (pause) {
qInfo() << "at " << currentSeconds() << "s"; qInfo() << "at " << currentSeconds() << "s";
} }
@ -132,7 +132,7 @@ void Replay::setCurrentSegment(int n) {
void Replay::segmentLoadFinished(bool success) { void Replay::segmentLoadFinished(bool success) {
if (!success) { if (!success) {
Segment *seg = qobject_cast<Segment *>(sender()); Segment *seg = qobject_cast<Segment *>(sender());
qInfo() << "failed to load segment " << seg->seg_num << ", removing it from current replay list"; qWarning() << "failed to load segment " << seg->seg_num << ", removing it from current replay list";
segments_.erase(seg->seg_num); segments_.erase(seg->seg_num);
} }
queueSegment(); queueSegment();
@ -153,7 +153,7 @@ void Replay::queueSegment() {
auto &[n, seg] = *it; auto &[n, seg] = *it;
seg = std::make_unique<Segment>(n, route_->at(n), hasFlag(REPLAY_FLAG_DCAM), hasFlag(REPLAY_FLAG_ECAM), !hasFlag(REPLAY_FLAG_NO_FILE_CACHE)); seg = std::make_unique<Segment>(n, route_->at(n), hasFlag(REPLAY_FLAG_DCAM), hasFlag(REPLAY_FLAG_ECAM), !hasFlag(REPLAY_FLAG_NO_FILE_CACHE));
QObject::connect(seg.get(), &Segment::loadFinished, this, &Replay::segmentLoadFinished); QObject::connect(seg.get(), &Segment::loadFinished, this, &Replay::segmentLoadFinished);
qInfo() << "loading segment" << n << "..."; qDebug() << "loading segment" << n << "...";
} }
break; break;
} }
@ -220,7 +220,7 @@ void Replay::startStream(const Segment *cur_segment) {
auto bytes = (*it)->bytes(); auto bytes = (*it)->bytes();
Params().put("CarParams", (const char *)bytes.begin(), bytes.size()); Params().put("CarParams", (const char *)bytes.begin(), bytes.size());
} else { } else {
qInfo() << "failed to read CarParams from current segment"; qWarning() << "failed to read CarParams from current segment";
} }
// start camera server // start camera server

Loading…
Cancel
Save