replay: add nice arg parser (#22264)

* replay: add nice arg parser

* demo

* cleanup
pull/22266/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent f5aa3a30c9
commit f49e7629ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      selfdrive/ui/replay/main.cc
  2. 8
      selfdrive/ui/replay/replay.cc
  3. 2
      selfdrive/ui/replay/replay.h

@ -3,8 +3,11 @@
#include <termios.h> #include <termios.h>
#include <QApplication> #include <QApplication>
#include <QCommandLineParser>
#include <QThread> #include <QThread>
const QString DEMO_ROUTE = "3533c53bb29502d1|2019-12-10--01-13-27";
int getch() { int getch() {
int ch; int ch;
struct termios oldt; struct termios oldt;
@ -58,18 +61,28 @@ void keyboardThread(Replay *replay) {
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
QApplication a(argc, argv); QApplication a(argc, argv);
QString route(argv[1]); QCommandLineParser parser;
if (route == "") { parser.setApplicationDescription("Mock openpilot components by publishing logged messages.");
printf("Usage: ./replay \"route\"\n"); parser.addHelpOption();
printf(" For a public demo route, use '3533c53bb29502d1|2019-12-10--01-13-27'\n"); parser.addPositionalArgument("route", "the drive to replay. find your drives at connect.comma.ai");
return 1; parser.addOption({{"a", "allow"}, "whitelist of services to send", "allow"});
parser.addOption({{"b", "block"}, "blacklist of services to send", "block"});
parser.addOption({"demo", "use a demo route instead of providing your own"});
parser.process(a);
const QStringList args = parser.positionalArguments();
if (args.empty() && !parser.isSet("demo")) {
parser.showHelp();
} }
Replay *replay = new Replay(route); const QString route = args.empty() ? DEMO_ROUTE : args.first();
Replay *replay = new Replay(route, parser.value("allow").split(","), parser.value("block").split(","));
replay->start(); replay->start();
// start keyboard control thread
QThread *t = QThread::create(keyboardThread, replay); QThread *t = QThread::create(keyboardThread, replay);
QObject::connect(t, &QThread::finished, t, &QThread::deleteLater); QObject::connect(t, &QThread::finished, t, &QThread::deleteLater);
t->start(); t->start();
return a.exec(); return a.exec();
} }

@ -8,13 +8,7 @@
#include "selfdrive/common/timing.h" #include "selfdrive/common/timing.h"
#include "selfdrive/hardware/hw.h" #include "selfdrive/hardware/hw.h"
Replay::Replay(QString route, SubMaster *sm_, QObject *parent) : sm(sm_), QObject(parent) { Replay::Replay(QString route, QStringList allow, QStringList block, SubMaster *sm_, QObject *parent) : sm(sm_), QObject(parent) {
QStringList block = QString(getenv("BLOCK")).split(",");
qDebug() << "blocklist" << block;
QStringList allow = QString(getenv("ALLOW")).split(",");
qDebug() << "allowlist" << allow;
std::vector<const char*> s; std::vector<const char*> s;
for (const auto &it : services) { for (const auto &it : services) {
if ((allow[0].size() == 0 || allow.contains(it.name)) && if ((allow[0].size() == 0 || allow.contains(it.name)) &&

@ -20,7 +20,7 @@ class Replay : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Replay(QString route, SubMaster *sm = nullptr, QObject *parent = 0); Replay(QString route, QStringList allow, QStringList block, SubMaster *sm = nullptr, QObject *parent = 0);
void start(); void start();
void addSegment(int n); void addSegment(int n);

Loading…
Cancel
Save