Revert "Replace ifdefs with hardware abstraction layer (#20801)"

This reverts commit 9f2ad462f39f4c880f283b71bffbc9248a2b577d.

old-commit-hash: 3a95d3ccaa
commatwo_master
Willem Melching 4 years ago
parent f8608d2e7b
commit 39c18d4c5a
  1. 41
      selfdrive/boardd/boardd.cc
  2. 39
      selfdrive/camerad/cameras/camera_common.cc
  3. 11
      selfdrive/camerad/main.cc
  4. 45
      selfdrive/common/modeldata.h
  5. 11
      selfdrive/common/params.cc
  6. 6
      selfdrive/common/swaglog.cc
  7. 25
      selfdrive/hardware/base.h
  8. 1
      selfdrive/hardware/eon/hardware.h
  9. 2
      selfdrive/hardware/tici/hardware.h
  10. 5
      selfdrive/loggerd/logger.cc
  11. 10
      selfdrive/loggerd/logger.h
  12. 50
      selfdrive/loggerd/loggerd.cc
  13. 19
      selfdrive/modeld/modeld.cc
  14. 47
      selfdrive/modeld/models/dmonitoring.cc
  15. 16
      selfdrive/ui/main.cc
  16. 97
      selfdrive/ui/paint.cc
  17. 9
      selfdrive/ui/qt/api.cc
  18. 39
      selfdrive/ui/qt/offroad/settings.cc
  19. 10
      selfdrive/ui/qt/qt_window.h
  20. 7
      selfdrive/ui/qt/setup/setup.cc
  21. 5
      selfdrive/ui/qt/sidebar.cc
  22. 7
      selfdrive/ui/qt/widgets/input.cc
  23. 8
      selfdrive/ui/replay/replay.cc
  24. 28
      selfdrive/ui/ui.cc

@ -27,7 +27,6 @@
#include "common/timing.h"
#include "messaging.h"
#include "locationd/ublox_msg.h"
#include "selfdrive/hardware/hw.h"
#include "panda.h"
#include "pigeon.h"
@ -362,18 +361,18 @@ void panda_state_thread(bool spoofing_started) {
auto ps = msg.initEvent().initPandaState();
ps.setUptime(pandaState.uptime);
if (Hardware::TICI()) {
double read_time = millis_since_boot();
ps.setVoltage(std::stoi(util::read_file("/sys/class/hwmon/hwmon1/in1_input")));
ps.setCurrent(std::stoi(util::read_file("/sys/class/hwmon/hwmon1/curr1_input")));
read_time = millis_since_boot() - read_time;
if (read_time > 50) {
LOGW("reading hwmon took %lfms", read_time);
}
} else {
ps.setVoltage(pandaState.voltage);
ps.setCurrent(pandaState.current);
#ifdef QCOM2
double read_time = millis_since_boot();
ps.setVoltage(std::stoi(util::read_file("/sys/class/hwmon/hwmon1/in1_input")));
ps.setCurrent(std::stoi(util::read_file("/sys/class/hwmon/hwmon1/curr1_input")));
read_time = millis_since_boot() - read_time;
if (read_time > 50) {
LOGW("reading hwmon took %lfms", read_time);
}
#else
ps.setVoltage(pandaState.voltage);
ps.setCurrent(pandaState.current);
#endif
ps.setIgnitionLine(pandaState.ignition_line);
ps.setIgnitionCan(pandaState.ignition_can);
@ -418,14 +417,17 @@ void hardware_control_thread() {
uint16_t prev_fan_speed = 999;
uint16_t ir_pwr = 0;
uint16_t prev_ir_pwr = 999;
#if defined(QCOM) || defined(QCOM2)
bool prev_charging_disabled = false;
#endif
unsigned int cnt = 0;
while (!do_exit && panda->connected) {
cnt++;
sm.update(1000); // TODO: what happens if EINTR is sent while in sm.update?
if (!Hardware::PC() && sm.updated("deviceState")){
#if defined(QCOM) || defined(QCOM2)
if (sm.updated("deviceState")){
// Charging mode
bool charging_disabled = sm["deviceState"].getDeviceState().getChargingDisabled();
if (charging_disabled != prev_charging_disabled){
@ -439,6 +441,7 @@ void hardware_control_thread() {
prev_charging_disabled = charging_disabled;
}
}
#endif
// Other pandas don't have fan/IR to control
if (panda->hw_type != cereal::PandaState::PandaType::UNO && panda->hw_type != cereal::PandaState::PandaType::DOS) continue;
@ -488,7 +491,11 @@ void pigeon_thread() {
PubMaster pm({"ubloxRaw"});
bool ignition_last = false;
Pigeon *pigeon = Hardware::TICI() ? Pigeon::connect("/dev/ttyHS0") : Pigeon::connect(panda);
#ifdef QCOM2
Pigeon *pigeon = Pigeon::connect("/dev/ttyHS0");
#else
Pigeon *pigeon = Pigeon::connect(panda);
#endif
std::unordered_map<char, uint64_t> last_recv_time;
std::unordered_map<char, int64_t> cls_max_dt = {
@ -565,7 +572,11 @@ int main() {
err = set_realtime_priority(54);
LOG("set priority returns %d", err);
err = set_core_affinity(Hardware::TICI() ? 4 : 3);
#ifdef QCOM2
err = set_core_affinity(4);
#else
err = set_core_affinity(3);
#endif
LOG("set affinity returns %d", err);
while (!do_exit){

@ -24,7 +24,6 @@
#include "common/util.h"
#include "modeldata.h"
#include "imgproc/utils.h"
#include "selfdrive/hardware/hw.h"
static cl_program build_debayer_program(cl_device_id device_id, cl_context context, const CameraInfo *ci, const CameraBuf *b, const CameraState *s) {
char args[4096];
@ -36,8 +35,11 @@ static cl_program build_debayer_program(cl_device_id device_id, cl_context conte
ci->frame_width, ci->frame_height, ci->frame_stride,
b->rgb_width, b->rgb_height, b->rgb_stride,
ci->bayer_flip, ci->hdr, s->camera_num);
const char *cl_file = Hardware::TICI() ? "cameras/real_debayer.cl" : "cameras/debayer.cl";
return cl_program_from_file(context, device_id, cl_file, args);
#ifdef QCOM2
return cl_program_from_file(context, device_id, "cameras/real_debayer.cl", args);
#else
return cl_program_from_file(context, device_id, "cameras/debayer.cl", args);
#endif
}
void CameraBuf::init(cl_device_id device_id, cl_context context, CameraState *s, VisionIpcServer * v, int frame_cnt, VisionStreamType rgb_type, VisionStreamType yuv_type, release_cb release_callback) {
@ -62,12 +64,13 @@ void CameraBuf::init(cl_device_id device_id, cl_context context, CameraState *s,
rgb_width = ci->frame_width;
rgb_height = ci->frame_height;
#ifndef QCOM2
// debayering does a 2x downscale
if (Hardware::TICI() && ci->bayer) {
if (ci->bayer) {
rgb_width = ci->frame_width / 2;
rgb_height = ci->frame_height / 2;
}
#endif
yuv_transform = get_model_yuv_transform(ci->bayer);
vipc_server->create_buffers(rgb_type, UI_BUF_COUNT, true, rgb_width, rgb_height);
@ -347,27 +350,21 @@ static void driver_cam_auto_exposure(CameraState *c, SubMaster &sm) {
static const bool is_rhd = Params().getBool("IsRHD");
struct ExpRect {int x1, x2, x_skip, y1, y2, y_skip;};
const CameraBuf *b = &c->buf;
bool hist_ceil = false, hl_weighted = false;
int x_offset = 0, y_offset = 0;
int frame_width = b->rgb_width, frame_height = b->rgb_height;
#ifndef QCOM2
bool hist_ceil = false, hl_weighted = false;
int analog_gain = -1;
const int x_offset = 0, y_offset = 0;
const int frame_width = b->rgb_width, frame_height = b->rgb_height;
const ExpRect def_rect = {is_rhd ? 0 : b->rgb_width * 3 / 5, is_rhd ? b->rgb_width * 2 / 5 : b->rgb_width, 2,
b->rgb_height / 3, b->rgb_height, 1};
#else
int analog_gain = c->analog_gain;
bool hist_ceil = true, hl_weighted = true;
int analog_gain = (int)c->analog_gain;
const int x_offset = 630, y_offset = 156;
const int frame_width = 668, frame_height = frame_width / 1.33;
const ExpRect def_rect = {96, 1832, 2, 242, 1148, 4};
#endif
ExpRect def_rect;
if (!Hardware::TICI()) {
def_rect = {is_rhd ? 0 : b->rgb_width * 3 / 5, is_rhd ? b->rgb_width * 2 / 5 : b->rgb_width, 2,
b->rgb_height / 3, b->rgb_height, 1};
} else {
hist_ceil = hl_weighted = true;
x_offset = 630, y_offset = 156;
frame_width = 668, frame_height = frame_width / 1.33;
def_rect = {96, 1832, 2, 242, 1148, 4};
}
static ExpRect rect = def_rect;
// use driver face crop for AE
if (sm.updated("driverState")) {

@ -22,7 +22,6 @@
#include "common/swaglog.h"
#include "common/util.h"
#include "visionipc_server.h"
#include "selfdrive/hardware/hw.h"
ExitHandler do_exit;
@ -44,11 +43,11 @@ void party(cl_device_id device_id, cl_context context) {
int main(int argc, char *argv[]) {
set_realtime_priority(53);
if (Hardware::EON()) {
set_core_affinity(2);
} else if (Hardware::TICI()) {
set_core_affinity(6);
}
#if defined(QCOM)
set_core_affinity(2);
#elif defined(QCOM2)
set_core_affinity(6);
#endif
cl_device_id device_id = cl_get_device_id(CL_DEVICE_TYPE_DEFAULT);

@ -20,26 +20,39 @@ const double X_IDXS[TRAJECTORY_SIZE] = { 0. , 0.1875, 0.75 , 1.6875,
#ifdef __cplusplus
#include "common/mat.h"
#include "selfdrive/hardware/hw.h"
const mat3 fcam_intrinsic_matrix =
Hardware::TICI() ? (mat3){{2648.0, 0.0, 1928.0 / 2,
0.0, 2648.0, 1208.0 / 2,
0.0, 0.0, 1.0}}
: (mat3){{910., 0., 1164.0 / 2,
0., 910., 874.0 / 2,
0., 0., 1.}};
#ifdef QCOM2
const mat3 fcam_intrinsic_matrix = (mat3){{
2648.0, 0.0, 1928.0/2,
0.0, 2648.0, 1208.0/2,
0.0, 0.0, 1.0
}};
// without unwarp, focal length is for center portion only
const mat3 ecam_intrinsic_matrix =
Hardware::TICI() ? (mat3){{620.0, 0.0, 1928.0 / 2,
0.0, 620.0, 1208.0 / 2,
0.0, 0.0, 1.0}}
: (mat3){{0., 0., 0.,
0., 0., 0.,
0., 0., 0.}};
const mat3 ecam_intrinsic_matrix = (mat3){{
620.0, 0.0, 1928.0/2,
0.0, 620.0, 1208.0/2,
0.0, 0.0, 1.0
}};
#else
const mat3 fcam_intrinsic_matrix = (mat3){{
910., 0., 1164.0/2,
0., 910., 874.0/2,
0., 0., 1.
}};
const mat3 ecam_intrinsic_matrix = (mat3){{
0., 0., 0.,
0., 0., 0.,
0., 0., 0.
}};
#endif
static inline mat3 get_model_yuv_transform(bool bayer = true) {
float db_s = Hardware::TICI() ? 0.5 : 1.0; // debayering does a 2x downscale on TICI
#ifndef QCOM2
float db_s = 0.5; // debayering does a 2x downscale
#else
float db_s = 1.0;
#endif
const mat3 transform = (mat3){{
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,

@ -16,7 +16,7 @@
#include <unordered_map>
#include "common/util.h"
#include "common/swaglog.h"
#include "selfdrive/hardware/hw.h"
// keep trying if x gets interrupted by a signal
#define HANDLE_EINTR(x) \
({ \
@ -30,8 +30,13 @@
namespace {
const std::string default_params_path = !Hardware::PC() ? "/data/params" : util::getenv_default("HOME", "/.comma/params", "/data/params");
const std::string persistent_params_path = !Hardware::PC() ? "/persist/comma/params" : default_params_path;
#if defined(QCOM) || defined(QCOM2)
const std::string default_params_path = "/data/params";
const std::string persistent_params_path = "/persist/comma/params";
#else
const std::string default_params_path = util::getenv_default("HOME", "/.comma/params", "/data/params");
const std::string persistent_params_path = default_params_path;
#endif
volatile sig_atomic_t params_do_exit = 0;
void params_sig_handler(int signal) {

@ -13,7 +13,7 @@
#include "common/util.h"
#include "common/version.h"
#include "selfdrive/hardware/hw.h"
#include "swaglog.h"
class LogState {
@ -71,9 +71,9 @@ static void cloudlog_init() {
s.ctx_j["dirty"] = !getenv("CLEAN");
// device type
if (Hardware::EON()) {
if (util::file_exists("/EON")) {
cloudlog_bind_locked("device", "eon");
} else if (Hardware::TICI()) {
} else if (util::file_exists("/TICI")) {
cloudlog_bind_locked("device", "tici");
} else {
cloudlog_bind_locked("device", "pc");

@ -7,27 +7,16 @@
// no-op base hw class
class HardwareNone {
public:
enum Type {
typePC,
typeEON,
typeTICI
};
static constexpr float MAX_VOLUME = 0;
static constexpr float MIN_VOLUME = 0;
static std::string get_os_version() { return "openpilot for PC"; }
static void reboot() {}
static void poweroff() {}
static void set_brightness(int percent) {}
static void set_display_power(bool on) {}
static std::string get_os_version() { return "openpilot for PC"; };
static bool get_ssh_enabled() { return false; }
static void set_ssh_enabled(bool enabled) {}
static void reboot() {};
static void poweroff() {};
static void set_brightness(int percent) {};
static void set_display_power(bool on) {};
static Type type() { return typePC; }
static bool PC() { return type() == typePC; }
static bool EON() { return type() == typeEON; }
static bool TICI() { return type() == typeTICI; }
static bool get_ssh_enabled() { return false; };
static void set_ssh_enabled(bool enabled) {};
};

@ -15,7 +15,6 @@ public:
static constexpr float MAX_VOLUME = 1.0;
static constexpr float MIN_VOLUME = 0.5;
static Type type() { return typeEON; }
static std::string get_os_version() {
return "NEOS " + util::read_file("/VERSION");
};

@ -11,7 +11,7 @@ class HardwareTici : public HardwareNone {
public:
static constexpr float MAX_VOLUME = 0.5;
static constexpr float MIN_VOLUME = 0.4;
static Type type() { return typeTICI; }
static std::string get_os_version() {
return "AGNOS " + util::read_file("/VERSION");
};

@ -20,7 +20,6 @@
#include "common/params.h"
#include "common/version.h"
#include "messaging.h"
#include "selfdrive/hardware/hw.h"
#include "logger.h"
@ -54,9 +53,9 @@ kj::Array<capnp::word> logger_build_init_data() {
MessageBuilder msg;
auto init = msg.initEvent().initInitData();
if (Hardware::EON()) {
if (util::file_exists("/EON")) {
init.setDeviceType(cereal::InitData::DeviceType::NEO);
} else if (Hardware::TICI()) {
} else if (util::file_exists("/TICI")) {
init.setDeviceType(cereal::InitData::DeviceType::TICI);
} else {
init.setDeviceType(cereal::InitData::DeviceType::PC);

@ -8,11 +8,13 @@
#include <kj/array.h>
#include <capnp/serialize.h>
#include "common/util.h"
#include "selfdrive/hardware/hw.h"
const std::string LOG_ROOT =
Hardware::PC() ? util::getenv_default("HOME", "/.comma/media/0/realdata", "/data/media/0/realdata")
: "/data/media/0/realdata";
#if defined(QCOM) || defined(QCOM2)
const std::string LOG_ROOT = "/data/media/0/realdata";
#else
const std::string LOG_ROOT = util::getenv_default("HOME", "/.comma/media/0/realdata", "/data/media/0/realdata");
#endif
#define LOGGER_MAX_HANDLES 16
class BZFile {

@ -26,7 +26,7 @@
#include "logger.h"
#include "messaging.h"
#include "services.h"
#include "selfdrive/hardware/hw.h"
#include "visionipc.h"
#include "visionipc_client.h"
@ -42,9 +42,16 @@
namespace {
constexpr int MAIN_FPS = 20;
const int MAIN_BITRATE = Hardware::TICI() ? 10000000 : 5000000;
const int MAX_CAM_IDX = Hardware::TICI() ? LOG_CAMERA_ID_ECAMERA : LOG_CAMERA_ID_DCAMERA;
const int DCAM_BITRATE = Hardware::TICI() ? MAIN_BITRATE : 2500000;
#ifndef QCOM2
constexpr int MAIN_BITRATE = 5000000;
constexpr int MAX_CAM_IDX = LOG_CAMERA_ID_DCAMERA;
constexpr int DCAM_BITRATE = 2500000;
#else
constexpr int MAIN_BITRATE = 10000000;
constexpr int MAX_CAM_IDX = LOG_CAMERA_ID_ECAMERA;
constexpr int DCAM_BITRATE = MAIN_BITRATE;
#endif
#define NO_CAMERA_PATIENCE 500 // fall back to time-based rotation if all cameras are dead
@ -89,8 +96,11 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = {
.bitrate = 256000,
.is_h265 = false,
.downscale = true,
.frame_width = Hardware::TICI() ? 526 : 480,
.frame_height = Hardware::TICI() ? 330 : 360 // keep pixel count the same?
#ifndef QCOM2
.frame_width = 480, .frame_height = 360
#else
.frame_width = 526, .frame_height = 330 // keep pixel count the same?
#endif
},
};
@ -269,11 +279,11 @@ void encoder_thread(int cam_idx) {
eidx.setFrameId(extra.frame_id);
eidx.setTimestampSof(extra.timestamp_sof);
eidx.setTimestampEof(extra.timestamp_eof);
if (Hardware::TICI()) {
eidx.setType(cereal::EncodeIndex::Type::FULL_H_E_V_C);
} else {
eidx.setType(cam_idx == LOG_CAMERA_ID_DCAMERA ? cereal::EncodeIndex::Type::FRONT : cereal::EncodeIndex::Type::FULL_H_E_V_C);
}
#ifdef QCOM2
eidx.setType(cereal::EncodeIndex::Type::FULL_H_E_V_C);
#else
eidx.setType(cam_idx == LOG_CAMERA_ID_DCAMERA ? cereal::EncodeIndex::Type::FRONT : cereal::EncodeIndex::Type::FULL_H_E_V_C);
#endif
eidx.setEncodeId(cnt);
eidx.setSegmentNum(rotate_state.cur_seg);
eidx.setSegmentId(out_id);
@ -358,14 +368,18 @@ int main(int argc, char** argv) {
encoder_threads.push_back(std::thread(encoder_thread, LOG_CAMERA_ID_FCAMERA));
s.rotate_state[LOG_CAMERA_ID_FCAMERA].enabled = true;
if (!Hardware::PC() && Params().getBool("RecordFront")) {
#if defined(QCOM) || defined(QCOM2)
bool record_front = Params().getBool("RecordFront");
if (record_front) {
encoder_threads.push_back(std::thread(encoder_thread, LOG_CAMERA_ID_DCAMERA));
s.rotate_state[LOG_CAMERA_ID_DCAMERA].enabled = true;
}
if (Hardware::TICI()) {
encoder_threads.push_back(std::thread(encoder_thread, LOG_CAMERA_ID_ECAMERA));
s.rotate_state[LOG_CAMERA_ID_ECAMERA].enabled = true;
}
#ifdef QCOM2
encoder_threads.push_back(std::thread(encoder_thread, LOG_CAMERA_ID_ECAMERA));
s.rotate_state[LOG_CAMERA_ID_ECAMERA].enabled = true;
#endif
#endif
uint64_t msg_count = 0;
uint64_t bytes_count = 0;
@ -439,7 +453,9 @@ int main(int argc, char** argv) {
new_segment &= (((r.stream_frame_id >= r.last_rotate_frame_id + SEGMENT_LENGTH * MAIN_FPS) &&
(!r.should_rotate) && (r.initialized)) ||
(!r.enabled));
if (!Hardware::TICI()) break; // only look at fcamera frame id if not QCOM2
#ifndef QCOM2
break; // only look at fcamera frame id if not QCOM2
#endif
}
} else {
if (tms - last_rotate_tms > SEGMENT_LENGTH * 1000) {

@ -8,7 +8,7 @@
#include "common/clutil.h"
#include "common/util.h"
#include "common/params.h"
#include "selfdrive/hardware/hw.h"
#include "models/driving.h"
#include "messaging.h"
@ -133,12 +133,17 @@ void run_model(ModelState &model, VisionIpcClient &vipc_client) {
int main(int argc, char **argv) {
set_realtime_priority(54);
if (Hardware::EON()) {
set_core_affinity(2);
} else if (Hardware::TICI()) {
set_core_affinity(7);
}
bool wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false;
#ifdef QCOM
set_core_affinity(2);
#elif QCOM2
set_core_affinity(7);
#endif
bool wide_camera = false;
#ifdef QCOM2
wide_camera = Params().getBool("EnableWideCamera");
#endif
// start calibration thread
std::thread thread = std::thread(calibration_thread, wide_camera);

@ -1,11 +1,10 @@
#include <string.h>
#include <libyuv.h>
#include "selfdrive/hardware/hw.h"
#include "dmonitoring.h"
#include "common/mat.h"
#include "common/timing.h"
#include "common/params.h"
#include <libyuv.h>
#define MODEL_WIDTH 320
#define MODEL_HEIGHT 640
@ -18,8 +17,12 @@
#endif
void dmonitoring_init(DMonitoringModelState* s) {
const char *model_path = Hardware::PC() ? "../../models/dmonitoring_model.dlc"
: "../../models/dmonitoring_model_q.dlc";
#if defined(QCOM) || defined(QCOM2)
const char* model_path = "../../models/dmonitoring_model_q.dlc";
#else
const char* model_path = "../../models/dmonitoring_model.dlc";
#endif
int runtime = USE_DSP_RUNTIME;
s->m = new DefaultRunModel(model_path, &s->output[0], OUTPUT_SIZE, runtime);
s->is_rhd = Params().getBool("IsRHD");
@ -52,26 +55,24 @@ void crop_yuv(uint8_t *raw, int width, int height, uint8_t *y, uint8_t *u, uint8
}
DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_buf, int width, int height) {
Rect crop_rect;
if (Hardware::TICI()) {
const int full_width_tici = 1928;
const int full_height_tici = 1208;
const int adapt_width_tici = 668;
const int cropped_height = adapt_width_tici / 1.33;
crop_rect = {full_width_tici / 2 - adapt_width_tici / 2,
full_height_tici / 2 - cropped_height / 2 - 196,
cropped_height / 2,
cropped_height};
if (!s->is_rhd) {
crop_rect.x += adapt_width_tici - crop_rect.w + 32;
}
} else {
crop_rect = {0, 0, height / 2, height};
if (!s->is_rhd) {
crop_rect.x += width - crop_rect.w;
}
#ifndef QCOM2
Rect crop_rect = {0, 0, height / 2, height};
if (!s->is_rhd) {
crop_rect.x += width - crop_rect.w;
}
#else
const int full_width_tici = 1928;
const int full_height_tici = 1208;
const int adapt_width_tici = 668;
const int cropped_height = adapt_width_tici / 1.33;
Rect crop_rect = {full_width_tici / 2 - adapt_width_tici / 2,
full_height_tici / 2 - cropped_height / 2 - 196,
cropped_height / 2,
cropped_height};
if (!s->is_rhd) {
crop_rect.x += adapt_width_tici - crop_rect.w + 32;
}
#endif
int resized_width = MODEL_WIDTH;
int resized_height = MODEL_HEIGHT;

@ -3,7 +3,6 @@
#include "qt/window.h"
#include "qt/qt_window.h"
#include "selfdrive/hardware/hw.h"
int main(int argc, char *argv[]) {
QSurfaceFormat fmt;
@ -16,12 +15,15 @@ int main(int argc, char *argv[]) {
#endif
QSurfaceFormat::setDefaultFormat(fmt);
if (Hardware::EON()) {
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QSslConfiguration ssl = QSslConfiguration::defaultConfiguration();
ssl.setCaCertificates(QSslCertificate::fromPath("/usr/etc/tls/cert.pem"));
QSslConfiguration::setDefaultConfiguration(ssl);
}
#ifdef QCOM
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif
#ifdef QCOM
QSslConfiguration ssl = QSslConfiguration::defaultConfiguration();
ssl.setCaCertificates(QSslCertificate::fromPath("/usr/etc/tls/cert.pem", QSsl::Pem, QRegExp::Wildcard));
QSslConfiguration::setDefaultConfiguration(ssl);
#endif
QApplication a(argc, argv);
MainWindow w;

@ -19,12 +19,16 @@
#include "nanovg_gl.h"
#include "nanovg_gl_utils.h"
#include "paint.h"
#include "selfdrive/hardware/hw.h"
// TODO: this is also hardcoded in common/transformations/camera.py
// TODO: choose based on frame input size
const float y_offset = Hardware::TICI() ? 150.0 : 0.0;
const float zoom = Hardware::TICI() ? 2912.8 : 2138.5;
#ifdef QCOM2
const float y_offset = 150.0;
const float zoom = 2912.8;
#else
const float y_offset = 0.0;
const float zoom = 2138.5;
#endif
static void ui_draw_text(const UIState *s, float x, float y, const char *string, float size, NVGcolor color, const char *font_name) {
nvgFontFace(s->vg, font_name);
@ -125,11 +129,11 @@ static void draw_frame(UIState *s) {
if (s->last_frame) {
glBindTexture(GL_TEXTURE_2D, s->texture[s->last_frame->idx]->frame_tex);
if (!Hardware::EON()) {
// this is handled in ion on QCOM
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, s->last_frame->width, s->last_frame->height,
0, GL_RGB, GL_UNSIGNED_BYTE, s->last_frame->addr);
}
#ifndef QCOM
// this is handled in ion on QCOM
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, s->last_frame->width, s->last_frame->height,
0, GL_RGB, GL_UNSIGNED_BYTE, s->last_frame->addr);
#endif
}
glUseProgram(s->gl_shader->prog);
@ -242,9 +246,13 @@ static void ui_draw_driver_view(UIState *s) {
// blackout
const int blackout_x_r = valid_rect.right();
const Rect &blackout_rect = Hardware::TICI() ? s->viz_rect : rect;
const int blackout_w_r = blackout_rect.right() - valid_rect.right();
const int blackout_x_l = blackout_rect.x;
#ifndef QCOM2
const int blackout_w_r = rect.right() - valid_rect.right();
const int blackout_x_l = rect.x;
#else
const int blackout_w_r = s->viz_rect.right() - valid_rect.right();
const int blackout_x_l = s->viz_rect.x;
#endif
const int blackout_w_l = valid_rect.x - blackout_x_l;
ui_fill_rect(s->vg, {blackout_x_l, rect.y, blackout_w_l, rect.h}, COLOR_BLACK_ALPHA(144));
ui_fill_rect(s->vg, {blackout_x_r, rect.y, blackout_w_r, rect.h}, COLOR_BLACK_ALPHA(144));
@ -418,42 +426,41 @@ static const mat4 device_transform = {{
0.0, 0.0, 0.0, 1.0,
}};
static mat4 get_driver_view_transform() {
const float driver_view_ratio = 1.333;
mat4 transform;
if (Hardware::TICI()) {
// from dmonitoring.cc
const int full_width_tici = 1928;
const int full_height_tici = 1208;
const int adapt_width_tici = 668;
const int crop_x_offset = 32;
const int crop_y_offset = -196;
const float yscale = full_height_tici * driver_view_ratio / adapt_width_tici;
const float xscale = yscale*(1080-2*bdr_s)/(2160-2*bdr_s)*full_width_tici/full_height_tici;
transform = (mat4){{
xscale, 0.0, 0.0, xscale*crop_x_offset/full_width_tici*2,
0.0, yscale, 0.0, yscale*crop_y_offset/full_height_tici*2,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
} else {
// frame from 4/3 to 16/9 display
transform = (mat4){{
driver_view_ratio*(1080-2*bdr_s)/(1920-2*bdr_s), 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
}
return transform;
}
static const float driver_view_ratio = 1.333;
#ifndef QCOM2
// frame from 4/3 to 16/9 display
static const mat4 driver_view_transform = {{
driver_view_ratio*(1080-2*bdr_s)/(1920-2*bdr_s), 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
#else
// from dmonitoring.cc
static const int full_width_tici = 1928;
static const int full_height_tici = 1208;
static const int adapt_width_tici = 668;
static const int crop_x_offset = 32;
static const int crop_y_offset = -196;
static const float yscale = full_height_tici * driver_view_ratio / adapt_width_tici;
static const float xscale = yscale*(1080-2*bdr_s)/(2160-2*bdr_s)*full_width_tici/full_height_tici;
static const mat4 driver_view_transform = {{
xscale, 0.0, 0.0, xscale*crop_x_offset/full_width_tici*2,
0.0, yscale, 0.0, yscale*crop_y_offset/full_height_tici*2,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
}};
#endif
void ui_nvg_init(UIState *s) {
// init drawing
// on EON, we enable MSAA
s->vg = Hardware::EON() ? nvgCreate(0) : nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
#ifdef QCOM
// on QCOM, we enable MSAA
s->vg = nvgCreate(0);
#else
s->vg = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
#endif
assert(s->vg);
// init fonts
@ -547,7 +554,7 @@ void ui_nvg_init(UIState *s) {
0.0, 0.0, 0.0, 1.0,
}};
s->front_frame_mat = matmul(device_transform, get_driver_view_transform());
s->front_frame_mat = matmul(device_transform, driver_view_transform);
s->rear_frame_mat = matmul(device_transform, frame_transform);
// Apply transformation such that video pixel coordinates match video

@ -13,11 +13,12 @@
#include "api.h"
#include "common/params.h"
#include "common/util.h"
#include "selfdrive/hardware/hw.h"
const std::string private_key_path =
!Hardware::PC() ? util::getenv_default("HOME", "/.comma/persist/comma/id_rsa", "/persist/comma/id_rsa")
: "/persist/comma/id_rsa";
#if defined(QCOM) || defined(QCOM2)
const std::string private_key_path = "/persist/comma/id_rsa";
#else
const std::string private_key_path = util::getenv_default("HOME", "/.comma/persist/comma/id_rsa", "/persist/comma/id_rsa");
#endif
QByteArray CommaApi::rsa_sign(const QByteArray &data) {
auto file = QFile(private_key_path.c_str());

@ -49,13 +49,13 @@ TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) {
"../assets/offroad/icon_shell.png",
this));
if (Hardware::TICI()) {
toggles.append(new ParamControl("IsUploadRawEnabled",
"Upload Raw Logs",
"Upload full logs and full resolution video by default while on WiFi. If not enabled, individual logs can be marked for upload at my.comma.ai/useradmin.",
"../assets/offroad/icon_network.png",
this));
}
#ifndef QCOM2
toggles.append(new ParamControl("IsUploadRawEnabled",
"Upload Raw Logs",
"Upload full logs and full resolution video by default while on WiFi. If not enabled, individual logs can be marked for upload at my.comma.ai/useradmin.",
"../assets/offroad/icon_network.png",
this));
#endif
ParamControl *record_toggle = new ParamControl("RecordFront",
"Record and Upload Driver Camera",
@ -69,18 +69,19 @@ TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) {
"../assets/offroad/icon_road.png",
this));
if (Hardware::TICI()) {
toggles.append(new ParamControl("EnableWideCamera",
"Enable use of Wide Angle Camera",
"Use wide angle camera for driving and ui. Only takes effect after reboot.",
"../assets/offroad/icon_openpilot.png",
this));
toggles.append(new ParamControl("EnableLteOnroad",
"Enable LTE while onroad",
"",
"../assets/offroad/icon_network.png",
this));
}
#ifdef QCOM2
toggles.append(new ParamControl("EnableWideCamera",
"Enable use of Wide Angle Camera",
"Use wide angle camera for driving and ui. Only takes effect after reboot.",
"../assets/offroad/icon_openpilot.png",
this));
toggles.append(new ParamControl("EnableLteOnroad",
"Enable LTE while onroad",
"",
"../assets/offroad/icon_network.png",
this));
#endif
bool record_lock = Params().getBool("RecordFrontLock");
record_toggle->setEnabled(!record_lock);

@ -2,15 +2,19 @@
#include <QWidget>
#include <QApplication>
#include "selfdrive/hardware/hw.h"
#ifdef QCOM2
#include <qpa/qplatformnativeinterface.h>
#include <QPlatformSurfaceEvent>
#include <wayland-client-protocol.h>
#endif
const int vwp_w = Hardware::TICI() ? 2160 : 1920;
const int vwp_h = 1080;
#ifdef QCOM2
const int vwp_w = 2160, vwp_h = 1080;
#else
const int vwp_w = 1920, vwp_h = 1080;
#endif
inline void setMainWindow(QWidget *w) {
const float scale = getenv("SCALE") != NULL ? std::stof(getenv("SCALE")) : 1.0;

@ -10,7 +10,6 @@
#include "offroad/networking.h"
#include "widgets/input.h"
#include "qt_window.h"
#include "selfdrive/hardware/hw.h"
#define USER_AGENT "AGNOSSetup-0.1"
@ -142,9 +141,9 @@ QWidget * Setup::download_failed() {
QPushButton *reboot_btn = new QPushButton("Reboot");
nav_layout->addWidget(reboot_btn, 0, Qt::AlignBottom | Qt::AlignLeft);
QObject::connect(reboot_btn, &QPushButton::released, this, [=]() {
if (Hardware::TICI()) {
std::system("sudo reboot");
}
#ifdef QCOM2
std::system("sudo reboot");
#endif
});
QPushButton *restart_btn = new QPushButton("Start over");

@ -1,7 +1,6 @@
#include "common/util.h"
#include "sidebar.h"
#include "qt_window.h"
#include "selfdrive/hardware/hw.h"
StatusWidget::StatusWidget(bool has_substatus, QWidget *parent) : QFrame(parent) {
layout = new QVBoxLayout();
@ -179,9 +178,11 @@ void Sidebar::update(const UIState &s) {
panda_color = COLOR_DANGER;
panda_message = "NO\nPANDA";
}
else if (Hardware::TICI() && s.scene.started) {
#ifdef QCOM2
else if (s.scene.started) {
panda_color = s.scene.gpsOK ? COLOR_GOOD : COLOR_WARNING;
panda_message = QString("SAT CNT\n%1").arg(s.scene.satelliteCount);
}
#endif
panda->update(panda_message, panda_color);
}

@ -2,7 +2,6 @@
#include "input.h"
#include "qt_window.h"
#include "selfdrive/hardware/hw.h"
InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(parent) {
layout = new QVBoxLayout();
@ -173,8 +172,8 @@ bool ConfirmationDialog::confirm(const QString &prompt_text, QWidget *parent) {
int ConfirmationDialog::exec() {
// TODO: make this work without fullscreen
if (Hardware::TICI()) {
setMainWindow(this);
}
#ifdef QCOM2
setMainWindow(this);
#endif
return QDialog::exec();
}

@ -1,10 +1,14 @@
#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();
bool create_jwt = true;
#if !defined(QCOM) && !defined(QCOM2)
create_jwt = false;
#endif
http = new HttpRequest(this, "https://api.commadotai.com/v1/route/" + route + "/files", "", create_jwt);
QObject::connect(http, &HttpRequest::receivedResponse, this, &Replay::parseResponse);
}

@ -8,7 +8,7 @@
#include "common/swaglog.h"
#include "common/visionimg.h"
#include "common/watchdog.h"
#include "selfdrive/hardware/hw.h"
#include "hardware/hw.h"
#include "ui.h"
#include "paint.h"
#include "qt_window.h"
@ -192,10 +192,11 @@ static void update_state(UIState *s) {
}
if (sm.updated("sensorEvents")) {
for (auto sensor : sm["sensorEvents"].getSensorEvents()) {
if (!Hardware::TICI() && sensor.which() == cereal::SensorEventData::LIGHT) {
if (sensor.which() == cereal::SensorEventData::LIGHT) {
#ifndef QCOM2
scene.light_sensor = sensor.getLight();
}
if (!scene.started && sensor.which() == cereal::SensorEventData::ACCELERATION) {
#endif
} else if (!scene.started && sensor.which() == cereal::SensorEventData::ACCELERATION) {
auto accel = sensor.getAcceleration().getV();
if (accel.totalSize().wordCount){ // TODO: sometimes empty lists are received. Figure out why
scene.accel_sensor = accel[2];
@ -208,11 +209,13 @@ static void update_state(UIState *s) {
}
}
}
if (Hardware::TICI() && sm.updated("roadCameraState")) {
#ifdef QCOM2
if (sm.updated("roadCameraState")) {
auto camera_state = sm["roadCameraState"].getRoadCameraState();
float gain = camera_state.getGainFrac() * (camera_state.getGlobalGain() > 100 ? 2.5 : 1.0) / 10.0;
scene.light_sensor = std::clamp<float>((1023.0 / 1757.0) * (1757.0 - camera_state.getIntegLines()) * (1.0 - gain), 0.0, 1023.0);
}
#endif
scene.started = scene.deviceState.getStarted() || scene.driver_view;
}
@ -241,8 +244,10 @@ static void update_vision(UIState *s) {
VisionBuf * buf = s->vipc_client->recv();
if (buf != nullptr){
s->last_frame = buf;
} else if (!Hardware::PC()) {
} else {
#if defined(QCOM) || defined(QCOM2)
LOGE("visionIPC receive timeout");
#endif
}
}
}
@ -290,7 +295,11 @@ QUIState::QUIState(QObject *parent) : QObject(parent) {
ui_state.fb_h = vwp_h;
ui_state.scene.started = false;
ui_state.last_frame = nullptr;
ui_state.wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false;
ui_state.wide_camera = false;
#ifdef QCOM2
ui_state.wide_camera = Params().getBool("EnableWideCamera");
#endif
ui_state.vipc_client_rear = new VisionIpcClient("camerad", ui_state.wide_camera ? VISION_STREAM_RGB_WIDE : VISION_STREAM_RGB_BACK, true);
ui_state.vipc_client_front = new VisionIpcClient("camerad", VISION_STREAM_RGB_FRONT, true);
@ -350,9 +359,12 @@ void Device::setAwake(bool on, bool reset) {
void Device::updateBrightness(const UIState &s) {
float clipped_brightness = std::min(100.0f, (s.scene.light_sensor * brightness_m) + brightness_b);
if (Hardware::TICI() && !s.scene.started) {
#ifdef QCOM2
if (!s.scene.started) {
clipped_brightness = BACKLIGHT_OFFROAD;
}
#endif
int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {

Loading…
Cancel
Save