Skip to content

Commit

Permalink
boardd: move main() to main.cc for test cases (commaai#23564)
Browse files Browse the repository at this point in the history
* move main() to main.cc

* move includes back
  • Loading branch information
deanlee authored Jan 18, 2022
1 parent f76328b commit 498d54b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
2 changes: 2 additions & 0 deletions release/files_common
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ selfdrive/boardd/.gitignore
selfdrive/boardd/SConscript
selfdrive/boardd/__init__.py
selfdrive/boardd/boardd.cc
selfdrive/boardd/boardd.h
selfdrive/boardd/main.cc
selfdrive/boardd/boardd.py
selfdrive/boardd/boardd_api_impl.pyx
selfdrive/boardd/can_list_to_can_capnp.cc
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/boardd/SConscript
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Import('env', 'envCython', 'common', 'cereal', 'messaging')

libs = ['usb-1.0', common, cereal, messaging, 'pthread', 'zmq', 'capnp', 'kj']
env.Program('boardd', ['boardd.cc', 'panda.cc', 'pigeon.cc'], LIBS=libs)
env.Program('boardd', ['main.cc', 'boardd.cc', 'panda.cc', 'pigeon.cc'], LIBS=libs)
env.Library('libcan_list_to_can_capnp', ['can_list_to_can_capnp.cc'])

envCython.Program('boardd_api_impl.so', 'boardd_api_impl.pyx', LIBS=["can_list_to_can_capnp", 'capnp', 'kj'] + envCython["LIBS"])
Expand Down
20 changes: 5 additions & 15 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "selfdrive/boardd/boardd.h"

#include <sched.h>
#include <sys/cdefs.h>
#include <sys/resource.h>
Expand Down Expand Up @@ -27,7 +29,6 @@
#include "selfdrive/common/util.h"
#include "selfdrive/hardware/hw.h"

#include "selfdrive/boardd/panda.h"
#include "selfdrive/boardd/pigeon.h"

// -- Multi-panda conventions --
Expand Down Expand Up @@ -590,22 +591,11 @@ void pigeon_thread(Panda *panda) {
}
}

int main(int argc, char *argv[]) {
LOGW("starting boardd");

if (!Hardware::PC()) {
int err;
err = util::set_realtime_priority(54);
assert(err == 0);
err = util::set_core_affinity({Hardware::TICI() ? 4 : 3});
assert(err == 0);
}
void boardd_main_thread(std::vector<std::string> serials) {
if (serials.size() == 0) serials.push_back("");

LOGW("attempting to connect");
PubMaster pm({"pandaStates", "peripheralState"});

std::vector<std::string> serials(argv + 1, argv + argc);
if (serials.size() == 0) serials.push_back("");
LOGW("attempting to connect");

// connect to all provided serials
std::vector<Panda *> pandas;
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/boardd/boardd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "selfdrive/boardd/panda.h"

bool safety_setter_thread(std::vector<Panda *> pandas);
void boardd_main_thread(std::vector<std::string> serials);
22 changes: 22 additions & 0 deletions selfdrive/boardd/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <cassert>

#include "selfdrive/boardd/boardd.h"
#include "selfdrive/common/swaglog.h"
#include "selfdrive/common/util.h"
#include "selfdrive/hardware/hw.h"

int main(int argc, char *argv[]) {
LOGW("starting boardd");

if (!Hardware::PC()) {
int err;
err = util::set_realtime_priority(54);
assert(err == 0);
err = util::set_core_affinity({Hardware::TICI() ? 4 : 3});
assert(err == 0);
}

std::vector<std::string> serials(argv + 1, argv + argc);
boardd_main_thread(serials);
return 0;
}

0 comments on commit 498d54b

Please sign in to comment.