diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85e75396e..b5e638da3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -64,7 +64,7 @@ repos: - --linelength=240 # https://google.github.io/styleguide/cppguide.html # relevant rules are whitelisted, see all options with: cpplint --filter= - - --filter=-build,-legal,-readability,-runtime,-whitespace,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+readability/braces + - --filter=-build,-legal,-readability,-runtime,-whitespace,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/parens,+readability/braces - repo: local hooks: - id: test_translations diff --git a/common/gpio.cc b/common/gpio.cc index c1805b7bd..508836238 100644 --- a/common/gpio.cc +++ b/common/gpio.cc @@ -31,7 +31,7 @@ int gpio_init(int pin_nr, bool output) { char pin_dir_path[50]; int pin_dir_path_len = snprintf(pin_dir_path, sizeof(pin_dir_path), "/sys/class/gpio/gpio%d/direction", pin_nr); - if(pin_dir_path_len <= 0) { + if (pin_dir_path_len <= 0) { return -1; } const char *value = output ? "out" : "in"; @@ -42,7 +42,7 @@ int gpio_set(int pin_nr, bool high) { char pin_val_path[50]; int pin_val_path_len = snprintf(pin_val_path, sizeof(pin_val_path), "/sys/class/gpio/gpio%d/value", pin_nr); - if(pin_val_path_len <= 0) { + if (pin_val_path_len <= 0) { return -1; } return util::write_file(pin_val_path, (void*)(high ? "1" : "0"), 1); diff --git a/common/i2c.cc b/common/i2c.cc index ef788ac9e..fc72559ce 100644 --- a/common/i2c.cc +++ b/common/i2c.cc @@ -26,23 +26,23 @@ I2CBus::I2CBus(uint8_t bus_id) { snprintf(bus_name, 20, "/dev/i2c-%d", bus_id); i2c_fd = HANDLE_EINTR(open(bus_name, O_RDWR)); - if(i2c_fd < 0) { + if (i2c_fd < 0) { throw std::runtime_error("Failed to open I2C bus"); } } I2CBus::~I2CBus() { - if(i2c_fd >= 0) { close(i2c_fd); } + if (i2c_fd >= 0) { close(i2c_fd); } } int I2CBus::read_register(uint8_t device_address, uint register_address, uint8_t *buffer, uint8_t len) { int ret = 0; ret = HANDLE_EINTR(ioctl(i2c_fd, I2C_SLAVE, device_address)); - if(ret < 0) { goto fail; } + if (ret < 0) { goto fail; } ret = i2c_smbus_read_i2c_block_data(i2c_fd, register_address, len, buffer); - if((ret < 0) || (ret != len)) { goto fail; } + if ((ret < 0) || (ret != len)) { goto fail; } fail: return ret; @@ -52,10 +52,10 @@ int I2CBus::set_register(uint8_t device_address, uint register_address, uint8_t int ret = 0; ret = HANDLE_EINTR(ioctl(i2c_fd, I2C_SLAVE, device_address)); - if(ret < 0) { goto fail; } + if (ret < 0) { goto fail; } ret = i2c_smbus_write_byte_data(i2c_fd, register_address, data); - if(ret < 0) { goto fail; } + if (ret < 0) { goto fail; } fail: return ret; diff --git a/common/util.h b/common/util.h index 26bc15ba3..d6ab69824 100644 --- a/common/util.h +++ b/common/util.h @@ -171,7 +171,7 @@ private: template void update_max_atomic(std::atomic& max, T const& value) { T prev = max; - while(prev < value && !max.compare_exchange_weak(prev, value)) {} + while (prev < value && !max.compare_exchange_weak(prev, value)) {} } class LogState { diff --git a/selfdrive/boardd/panda_comms.cc b/selfdrive/boardd/panda_comms.cc index 120d2f67d..bc4e5f586 100644 --- a/selfdrive/boardd/panda_comms.cc +++ b/selfdrive/boardd/panda_comms.cc @@ -199,7 +199,7 @@ int PandaUsbHandle::bulk_write(unsigned char endpoint, unsigned char* data, int } else if (err != 0 || length != transferred) { handle_usb_issue(err, __func__); } - } while(err != 0 && connected); + } while (err != 0 && connected); return transferred; } @@ -226,7 +226,7 @@ int PandaUsbHandle::bulk_read(unsigned char endpoint, unsigned char* data, int l handle_usb_issue(err, __func__); } - } while(err != 0 && connected); + } while (err != 0 && connected); return transferred; } diff --git a/selfdrive/boardd/tests/test_boardd_usbprotocol.cc b/selfdrive/boardd/tests/test_boardd_usbprotocol.cc index 52cb11ec3..86476d05c 100644 --- a/selfdrive/boardd/tests/test_boardd_usbprotocol.cc +++ b/selfdrive/boardd/tests/test_boardd_usbprotocol.cc @@ -82,7 +82,7 @@ void PandaTest::test_can_recv(uint32_t rx_chunk_size) { this->receive_buffer_size = 0; uint32_t pos = 0; - while(pos < size) { + while (pos < size) { uint32_t chunk_size = std::min(rx_chunk_size, size - pos); memcpy(&this->receive_buffer[this->receive_buffer_size], &data[pos], chunk_size); this->receive_buffer_size += chunk_size; diff --git a/selfdrive/locationd/locationd.cc b/selfdrive/locationd/locationd.cc index d79b5c9c4..722ead7dd 100755 --- a/selfdrive/locationd/locationd.cc +++ b/selfdrive/locationd/locationd.cc @@ -359,7 +359,7 @@ void Localizer::handle_gps(double current_time, const cereal::GpsLocationData::R void Localizer::handle_gnss(double current_time, const cereal::GnssMeasurements::Reader& log) { - if(!log.getPositionECEF().getValid() || !log.getVelocityECEF().getValid()) { + if (!log.getPositionECEF().getValid() || !log.getVelocityECEF().getValid()) { this->determine_gps_mode(current_time); return; } diff --git a/selfdrive/modeld/models/commonmodel.cc b/selfdrive/modeld/models/commonmodel.cc index b7c9051c6..5e28e9b95 100644 --- a/selfdrive/modeld/models/commonmodel.cc +++ b/selfdrive/modeld/models/commonmodel.cc @@ -55,14 +55,14 @@ ModelFrame::~ModelFrame() { void softmax(const float* input, float* output, size_t len) { const float max_val = *std::max_element(input, input + len); float denominator = 0; - for(int i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { float const v_exp = expf(input[i] - max_val); denominator += v_exp; output[i] = v_exp; } const float inv_denominator = 1. / denominator; - for(int i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { output[i] *= inv_denominator; } } diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index fb42fcd4f..72137c4a9 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -264,7 +264,7 @@ void fill_plan(cereal::ModelDataV2::Builder &framed, const ModelOutputPlanPredic std::array acc_x, acc_y, acc_z; std::array rot_rate_x, rot_rate_y, rot_rate_z; - for(int i=0; igetInputDimensions(strList.at(0)); const auto &inputShape = *inputDims_opt; std::cout << "winkwink" << std::endl; @@ -167,7 +167,7 @@ void testrun(char* modelfile) { get_testframe(i,input); snpe->execute(input.get(), outputTensorMap); zdl::DlSystem::StringList tensorNames = outputTensorMap.getTensorNames(); - std::for_each( tensorNames.begin(), tensorNames.end(), [&](const char* name) { + std::for_each(tensorNames.begin(), tensorNames.end(), [&](const char* name) { std::ostringstream path; path << "/data/opt/Result_" << std::to_string(i) << ".raw"; auto tensorPtr = outputTensorMap.getTensor(name); diff --git a/selfdrive/modeld/thneed/serialize.cc b/selfdrive/modeld/thneed/serialize.cc index f789e5bf5..51e6d0869 100644 --- a/selfdrive/modeld/thneed/serialize.cc +++ b/selfdrive/modeld/thneed/serialize.cc @@ -75,8 +75,7 @@ void Thneed::load(const char *filename) { #endif if (clbuf == NULL) { printf("clError: %s create image %zux%zu rp %zu with buffer %p\n", cl_get_error_string(errcode), - desc.image_width, desc.image_height, desc.image_row_pitch, desc.buffer - ); + desc.image_width, desc.image_height, desc.image_row_pitch, desc.buffer); } assert(clbuf != NULL); } diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index b73772544..0e321d4e1 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -85,7 +85,7 @@ void HttpRequest::sendRequest(const QString &requestURL, const HttpRequest::Meth return; } QString token; - if(create_jwt) { + if (create_jwt) { token = CommaApi::create_jwt(); } else { QString token_json = QString::fromStdString(util::read_file(util::getenv("HOME") + "/.comma/auth.json")); diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 804bf037a..8b0f9c1f3 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -139,7 +139,7 @@ void TogglesPanel::updateToggles() { "

%6


" "%7") .arg(tr("openpilot defaults to driving in chill mode. Experimental mode enables alpha-level features that aren't ready for chill mode. Experimental features are listed below:")) - .arg(tr("End-to-End Longitudinal Control" )) + .arg(tr("End-to-End Longitudinal Control")) .arg(tr("Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would, including stopping for red lights and stop signs. " "Since the driving model decides the speed to drive, the set speed will only act as an upper bound. This is an alpha quality feature; " "mistakes should be expected.")) diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index 1e25d2d53..7bd168121 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -134,7 +134,7 @@ void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, co } -QWidget* topWidget (QWidget* widget) { +QWidget* topWidget(QWidget* widget) { while (widget->parentWidget() != nullptr) widget=widget->parentWidget(); return widget; } @@ -197,8 +197,7 @@ QColor interpColor(float xv, std::vector xp, std::vector fp) { (xv - xp[low]) * (fp[hi].red() - fp[low].red()) / (xp[hi] - xp[low]) + fp[low].red(), (xv - xp[low]) * (fp[hi].green() - fp[low].green()) / (xp[hi] - xp[low]) + fp[low].green(), (xv - xp[low]) * (fp[hi].blue() - fp[low].blue()) / (xp[hi] - xp[low]) + fp[low].blue(), - (xv - xp[low]) * (fp[hi].alpha() - fp[low].alpha()) / (xp[hi] - xp[low]) + fp[low].alpha() - ); + (xv - xp[low]) * (fp[hi].alpha() - fp[low].alpha()) / (xp[hi] - xp[low]) + fp[low].alpha()); } } diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index 1aa3bd69b..2aae97b86 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -23,7 +23,7 @@ void sigTermHandler(int s); QString timeAgo(const QDateTime &date); void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); void initApp(int argc, char *argv[], bool disable_hidpi = true); -QWidget* topWidget (QWidget* widget); +QWidget* topWidget(QWidget* widget); QPixmap loadPixmap(const QString &fileName, const QSize &size = {}, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio); QPixmap bootstrapPixmap(const QString &id); diff --git a/system/logcatd/logcatd_systemd.cc b/system/logcatd/logcatd_systemd.cc index 70467a9c1..721726ed2 100644 --- a/system/logcatd/logcatd_systemd.cc +++ b/system/logcatd/logcatd_systemd.cc @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) { // Wait for new message if we didn't receive anything if (err == 0) { err = sd_journal_wait(journal, 1000 * 1000); - assert (err >= 0); + assert(err >= 0); continue; // Try again } diff --git a/system/sensord/sensors/bmx055_magn.cc b/system/sensord/sensors/bmx055_magn.cc index 7716ce25c..950e60892 100644 --- a/system/sensord/sensors/bmx055_magn.cc +++ b/system/sensord/sensors/bmx055_magn.cc @@ -77,7 +77,7 @@ int BMX055_Magn::init() { // suspend -> sleep int ret = set_register(BMX055_MAGN_I2C_REG_PWR_0, 0x01); - if(ret < 0) { + if (ret < 0) { LOGE("Enabling power failed: %d", ret); goto fail; } @@ -90,21 +90,21 @@ int BMX055_Magn::init() { // Load magnetometer trim ret = read_register(BMX055_MAGN_I2C_REG_DIG_X1, trim_x1y1, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_X2, trim_x2y2, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_XY2, trim_xy1xy2, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_Z1_LSB, trim_z1, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_Z2_LSB, trim_z2, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_Z3_LSB, trim_z3, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_Z4_LSB, trim_z4, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; ret = read_register(BMX055_MAGN_I2C_REG_DIG_XYZ1_LSB, trim_xyz1, 2); - if(ret < 0) goto fail; + if (ret < 0) goto fail; // Read trim data trim_data.dig_x1 = trim_x1y1[0]; diff --git a/system/sensord/sensors/lsm6ds3_gyro.cc b/system/sensord/sensors/lsm6ds3_gyro.cc index 9bc43485a..e6bdc6c8a 100644 --- a/system/sensord/sensors/lsm6ds3_gyro.cc +++ b/system/sensord/sensors/lsm6ds3_gyro.cc @@ -128,7 +128,7 @@ int LSM6DS3_Gyro::init() { } ret = self_test(LSM6DS3_GYRO_POSITIVE_TEST); - if (ret < 0 ) { + if (ret < 0) { LOGE("LSM6DS3 gyro positive self-test failed!"); if (do_self_test) goto fail; } diff --git a/system/ubloxd/tests/test_glonass_kaitai.cc b/system/ubloxd/tests/test_glonass_kaitai.cc index 5ad274142..96f43742b 100644 --- a/system/ubloxd/tests/test_glonass_kaitai.cc +++ b/system/ubloxd/tests/test_glonass_kaitai.cc @@ -101,7 +101,7 @@ std::string generate_inp_data(string_data& data) { string_data.reserve(16); for (int i = 0; i < 128; i+=8) { std::string substr = inp_data.substr(i, 8); - string_data.push_back( (uint8_t)std::stoi(substr.c_str(), 0, 2)); + string_data.push_back((uint8_t)std::stoi(substr.c_str(), 0, 2)); } return string_data; diff --git a/system/ubloxd/ublox_msg.cc b/system/ubloxd/ublox_msg.cc index c0554773a..338b879dc 100644 --- a/system/ubloxd/ublox_msg.cc +++ b/system/ubloxd/ublox_msg.cc @@ -23,26 +23,26 @@ inline static bool bit_to_bool(uint8_t val, int shifts) { inline int UbloxMsgParser::needed_bytes() { // Msg header incomplete? - if(bytes_in_parse_buf < ublox::UBLOX_HEADER_SIZE) + if (bytes_in_parse_buf < ublox::UBLOX_HEADER_SIZE) return ublox::UBLOX_HEADER_SIZE + ublox::UBLOX_CHECKSUM_SIZE - bytes_in_parse_buf; uint16_t needed = UBLOX_MSG_SIZE(msg_parse_buf) + ublox::UBLOX_HEADER_SIZE + ublox::UBLOX_CHECKSUM_SIZE; // too much data - if(needed < (uint16_t)bytes_in_parse_buf) + if (needed < (uint16_t)bytes_in_parse_buf) return -1; return needed - (uint16_t)bytes_in_parse_buf; } inline bool UbloxMsgParser::valid_cheksum() { uint8_t ck_a = 0, ck_b = 0; - for(int i = 2; i < bytes_in_parse_buf - ublox::UBLOX_CHECKSUM_SIZE;i++) { + for (int i = 2; i < bytes_in_parse_buf - ublox::UBLOX_CHECKSUM_SIZE;i++) { ck_a = (ck_a + msg_parse_buf[i]) & 0xFF; ck_b = (ck_b + ck_a) & 0xFF; } - if(ck_a != msg_parse_buf[bytes_in_parse_buf - 2]) { + if (ck_a != msg_parse_buf[bytes_in_parse_buf - 2]) { LOGD("Checksum a mismatch: %02X, %02X", ck_a, msg_parse_buf[6]); return false; } - if(ck_b != msg_parse_buf[bytes_in_parse_buf - 1]) { + if (ck_b != msg_parse_buf[bytes_in_parse_buf - 1]) { LOGD("Checksum b mismatch: %02X, %02X", ck_b, msg_parse_buf[7]); return false; } @@ -55,13 +55,13 @@ inline bool UbloxMsgParser::valid() { } inline bool UbloxMsgParser::valid_so_far() { - if(bytes_in_parse_buf > 0 && msg_parse_buf[0] != ublox::PREAMBLE1) { + if (bytes_in_parse_buf > 0 && msg_parse_buf[0] != ublox::PREAMBLE1) { return false; } - if(bytes_in_parse_buf > 1 && msg_parse_buf[1] != ublox::PREAMBLE2) { + if (bytes_in_parse_buf > 1 && msg_parse_buf[1] != ublox::PREAMBLE2) { return false; } - if(needed_bytes() == 0 && !valid()) { + if (needed_bytes() == 0 && !valid()) { return false; } return true; @@ -70,8 +70,8 @@ inline bool UbloxMsgParser::valid_so_far() { bool UbloxMsgParser::add_data(float log_time, const uint8_t *incoming_data, uint32_t incoming_data_len, size_t &bytes_consumed) { last_log_time = log_time; int needed = needed_bytes(); - if(needed > 0) { - bytes_consumed = std::min((uint32_t)needed, incoming_data_len ); + if (needed > 0) { + bytes_consumed = std::min((uint32_t)needed, incoming_data_len); // Add data to buffer memcpy(msg_parse_buf + bytes_in_parse_buf, incoming_data, bytes_consumed); bytes_in_parse_buf += bytes_consumed; @@ -80,15 +80,15 @@ bool UbloxMsgParser::add_data(float log_time, const uint8_t *incoming_data, uint } // Validate msg format, detect invalid header and invalid checksum. - while(!valid_so_far() && bytes_in_parse_buf != 0) { + while (!valid_so_far() && bytes_in_parse_buf != 0) { // Corrupted msg, drop a byte. bytes_in_parse_buf -= 1; - if(bytes_in_parse_buf > 0) + if (bytes_in_parse_buf > 0) memmove(&msg_parse_buf[0], &msg_parse_buf[1], bytes_in_parse_buf); } // There is redundant data at the end of buffer, reset the buffer. - if(needed_bytes() == -1) { + if (needed_bytes() == -1) { bytes_in_parse_buf = 0; } return valid(); @@ -435,7 +435,7 @@ kj::Array UbloxMsgParser::gen_rxm_rawx(ubx_t::rxm_rawx_t *msg) { auto mb = mr.initMeasurements(msg->num_meas()); auto measurements = *msg->meas(); - for(int8_t i = 0; i < msg->num_meas(); i++) { + for (int8_t i = 0; i < msg->num_meas(); i++) { mb[i].setSvId(measurements[i]->sv_id()); mb[i].setPseudorange(measurements[i]->pr_mes()); mb[i].setCarrierCycles(measurements[i]->cp_mes()); @@ -470,7 +470,7 @@ kj::Array UbloxMsgParser::gen_nav_sat(ubx_t::nav_sat_t *msg) { auto svs = sr.initSvs(msg->num_svs()); auto svs_data = *msg->svs(); - for(int8_t i = 0; i < msg->num_svs(); i++) { + for (int8_t i = 0; i < msg->num_svs(); i++) { svs[i].setSvId(svs_data[i]->sv_id()); svs[i].setGnssId(svs_data[i]->gnss_id()); svs[i].setFlagsBitfield(svs_data[i]->flags()); diff --git a/system/ubloxd/ublox_msg.h b/system/ubloxd/ublox_msg.h index 4eafeac2c..d21760edc 100644 --- a/system/ubloxd/ublox_msg.h +++ b/system/ubloxd/ublox_msg.h @@ -52,7 +52,7 @@ namespace ublox { assert(msg.size() > 2); uint8_t ck_a = 0, ck_b = 0; - for(int i = 2; i < msg.size(); i++) { + for (int i = 2; i < msg.size(); i++) { ck_a = (ck_a + msg[i]) & 0xFF; ck_b = (ck_b + ck_a) & 0xFF; } diff --git a/system/ubloxd/ubloxd.cc b/system/ubloxd/ubloxd.cc index 1dae6dc86..668c1a7ec 100644 --- a/system/ubloxd/ubloxd.cc +++ b/system/ubloxd/ubloxd.cc @@ -41,9 +41,9 @@ int main() { size_t len = ubloxRaw.size(); size_t bytes_consumed = 0; - while(bytes_consumed < len && !do_exit) { + while (bytes_consumed < len && !do_exit) { size_t bytes_consumed_this_time = 0U; - if(parser.add_data(log_time, data + bytes_consumed, (uint32_t)(len - bytes_consumed), bytes_consumed_this_time)) { + if (parser.add_data(log_time, data + bytes_consumed, (uint32_t)(len - bytes_consumed), bytes_consumed_this_time)) { try { auto ublox_msg = parser.gen_msg(); diff --git a/tools/cabana/signalview.h b/tools/cabana/signalview.h index 5cab7f8fa..9d8571d0b 100644 --- a/tools/cabana/signalview.h +++ b/tools/cabana/signalview.h @@ -131,7 +131,7 @@ private: QAbstractItemView::dataChanged(topLeft, bottomRight, roles); } void leaveEvent(QEvent *event) override { - emit ((SignalView *)parentWidget())->highlight(nullptr); + emit static_cast(parentWidget())->highlight(nullptr); QTreeView::leaveEvent(event); } };