merge utilpp.h into util.h (#19710)
parent
5446a1c3dd
commit
595830135b
|
@ -4,7 +4,7 @@ from libcpp cimport bool
|
|||
cdef extern from "selfdrive/common/params.cc":
|
||||
pass
|
||||
|
||||
cdef extern from "selfdrive/common/util.c":
|
||||
cdef extern from "selfdrive/common/util.cc":
|
||||
pass
|
||||
|
||||
cdef extern from "selfdrive/common/params.h":
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "common/framebuffer.h"
|
||||
#include "common/touch.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#define USER_AGENT "NEOSUpdater-0.2"
|
||||
|
||||
|
|
|
@ -190,7 +190,8 @@ selfdrive/common/glutil.[c,h]
|
|||
selfdrive/common/touch.[c,h]
|
||||
selfdrive/common/swaglog.h
|
||||
selfdrive/common/swaglog.cc
|
||||
selfdrive/common/util.[c,h]
|
||||
selfdrive/common/util.cc
|
||||
selfdrive/common/util.h
|
||||
selfdrive/common/cqueue.[c,h]
|
||||
selfdrive/common/clutil.cc
|
||||
selfdrive/common/clutil.h
|
||||
|
@ -201,7 +202,6 @@ selfdrive/common/mutex.h
|
|||
selfdrive/common/modeldata.h
|
||||
selfdrive/common/mat.h
|
||||
selfdrive/common/timing.h
|
||||
selfdrive/common/utilpp.h
|
||||
|
||||
selfdrive/common/visionimg.cc
|
||||
selfdrive/common/visionimg.h
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "cereal/gen/cpp/car.capnp.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/timing.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "common/swaglog.h"
|
||||
#include "common/gpio.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "panda.h"
|
||||
|
||||
#ifdef QCOM2
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "common/swaglog.h"
|
||||
#include "common/gpio.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "pigeon.h"
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "imgproc/utils.h"
|
||||
|
||||
const int env_xmin = getenv("XMIN") ? atoi(getenv("XMIN")) : 0;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "messaging.hpp"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/swaglog.h"
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "msm_cam_sensor.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/params.h"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "visionbuf.h"
|
||||
|
||||
#include "common/mat.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "camera_common.h"
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <atomic>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "camera_qcom2.h"
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <pthread.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/clutil.h"
|
||||
#include "common/swaglog.h"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "visionipc_server.h"
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "messaging.hpp"
|
||||
#include "common/timing.h"
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ if SHARED:
|
|||
else:
|
||||
fxn = env.Library
|
||||
|
||||
common_libs = ['params.cc', 'swaglog.cc', 'cqueue.c', 'util.c', 'gpio.cc', 'i2c.cc']
|
||||
common_libs = ['params.cc', 'swaglog.cc', 'cqueue.c', 'util.cc', 'gpio.cc', 'i2c.cc']
|
||||
|
||||
_common = fxn('common', common_libs, LIBS="json11")
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "util.h"
|
||||
#include "utilpp.h"
|
||||
|
||||
namespace { // helper functions
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
|
||||
|
||||
#if defined(QCOM) || defined(QCOM2)
|
||||
|
|
|
@ -59,6 +59,6 @@ int main(int argc, const char* argv[]) {
|
|||
}
|
||||
|
||||
// BUILD:
|
||||
// $ gcc -I$HOME/one selfdrive/common/test_params.c selfdrive/common/params.c selfdrive/common/util.c -o ./test_params
|
||||
// $ gcc -I$HOME/one selfdrive/common/test_params.c selfdrive/common/params.c selfdrive/common/util.cc -o ./test_params
|
||||
// $ seq 0 100000 | xargs -P20 -I{} ./test_params write /data/params DongleId {} && sleep 0.1 &
|
||||
// $ while ./test_params read /data/params DongleId; do sleep 0.05; done
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
#ifndef COMMON_UTIL_H
|
||||
#define COMMON_UTIL_H
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
|
||||
#ifndef sighandler_t
|
||||
typedef void (*sighandler_t)(int sig);
|
||||
#endif
|
||||
|
||||
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
@ -22,10 +20,6 @@
|
|||
#undef ALIGN
|
||||
#define ALIGN(x, align) (((x) + (align)-1) & ~((align)-1))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Reads a file into a newly allocated buffer.
|
||||
//
|
||||
// Returns NULL on failure, otherwise the NULL-terminated file contents.
|
||||
|
@ -38,8 +32,98 @@ void set_thread_name(const char* name);
|
|||
int set_realtime_priority(int level);
|
||||
int set_core_affinity(int core);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
namespace util {
|
||||
|
||||
#endif
|
||||
inline bool starts_with(std::string s, std::string prefix) {
|
||||
return s.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
inline std::string string_format( const std::string& format, Args ... args ) {
|
||||
size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1;
|
||||
std::unique_ptr<char[]> buf( new char[ size ] );
|
||||
snprintf( buf.get(), size, format.c_str(), args ... );
|
||||
return std::string( buf.get(), buf.get() + size - 1 );
|
||||
}
|
||||
|
||||
inline std::string read_file(std::string fn) {
|
||||
std::ifstream t(fn);
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
inline std::string tohex(const uint8_t* buf, size_t buf_size) {
|
||||
std::unique_ptr<char[]> hexbuf(new char[buf_size*2+1]);
|
||||
for (size_t i=0; i < buf_size; i++) {
|
||||
sprintf(&hexbuf[i*2], "%02x", buf[i]);
|
||||
}
|
||||
hexbuf[buf_size*2] = 0;
|
||||
return std::string(hexbuf.get(), hexbuf.get() + buf_size*2);
|
||||
}
|
||||
|
||||
inline std::string base_name(std::string const & path) {
|
||||
size_t pos = path.find_last_of("/");
|
||||
if (pos == std::string::npos) return path;
|
||||
return path.substr(pos + 1);
|
||||
}
|
||||
|
||||
inline std::string dir_name(std::string const & path) {
|
||||
size_t pos = path.find_last_of("/");
|
||||
if (pos == std::string::npos) return "";
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
inline std::string readlink(std::string path) {
|
||||
char buff[4096];
|
||||
ssize_t len = ::readlink(path.c_str(), buff, sizeof(buff)-1);
|
||||
if (len != -1) {
|
||||
buff[len] = '\0';
|
||||
return std::string(buff);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
inline std::string getenv_default(const char* env_var, const char * suffix, const char* default_val) {
|
||||
const char* env_val = getenv(env_var);
|
||||
if (env_val != NULL){
|
||||
return std::string(env_val) + std::string(suffix);
|
||||
} else {
|
||||
return std::string(default_val);
|
||||
}
|
||||
}
|
||||
|
||||
inline void sleep_for(const int milliseconds) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||
}
|
||||
}
|
||||
|
||||
class ExitHandler {
|
||||
public:
|
||||
ExitHandler() {
|
||||
std::signal(SIGINT, (sighandler_t)set_do_exit);
|
||||
std::signal(SIGTERM, (sighandler_t)set_do_exit);
|
||||
};
|
||||
inline operator bool() { return do_exit; }
|
||||
inline ExitHandler& operator=(bool v) {
|
||||
do_exit = v;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
static void set_do_exit(int sig) { do_exit = true; }
|
||||
inline static std::atomic<bool> do_exit = false;
|
||||
};
|
||||
|
||||
struct unique_fd {
|
||||
unique_fd(int fd = -1) : fd_(fd) {}
|
||||
unique_fd& operator=(unique_fd&& uf) {
|
||||
fd_ = uf.fd_;
|
||||
uf.fd_ = -1;
|
||||
return *this;
|
||||
}
|
||||
~unique_fd() {
|
||||
if (fd_ != -1) close(fd_);
|
||||
}
|
||||
operator int() const { return fd_; }
|
||||
int fd_;
|
||||
};
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#ifndef sighandler_t
|
||||
typedef void (*sighandler_t)(int sig);
|
||||
#endif
|
||||
|
||||
namespace util {
|
||||
|
||||
inline bool starts_with(std::string s, std::string prefix) {
|
||||
return s.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
inline std::string string_format( const std::string& format, Args ... args ) {
|
||||
size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1;
|
||||
std::unique_ptr<char[]> buf( new char[ size ] );
|
||||
snprintf( buf.get(), size, format.c_str(), args ... );
|
||||
return std::string( buf.get(), buf.get() + size - 1 );
|
||||
}
|
||||
|
||||
inline std::string read_file(std::string fn) {
|
||||
std::ifstream t(fn);
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
inline std::string tohex(const uint8_t* buf, size_t buf_size) {
|
||||
std::unique_ptr<char[]> hexbuf(new char[buf_size*2+1]);
|
||||
for (size_t i=0; i < buf_size; i++) {
|
||||
sprintf(&hexbuf[i*2], "%02x", buf[i]);
|
||||
}
|
||||
hexbuf[buf_size*2] = 0;
|
||||
return std::string(hexbuf.get(), hexbuf.get() + buf_size*2);
|
||||
}
|
||||
|
||||
inline std::string base_name(std::string const & path) {
|
||||
size_t pos = path.find_last_of("/");
|
||||
if (pos == std::string::npos) return path;
|
||||
return path.substr(pos + 1);
|
||||
}
|
||||
|
||||
inline std::string dir_name(std::string const & path) {
|
||||
size_t pos = path.find_last_of("/");
|
||||
if (pos == std::string::npos) return "";
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
inline std::string readlink(std::string path) {
|
||||
char buff[4096];
|
||||
ssize_t len = ::readlink(path.c_str(), buff, sizeof(buff)-1);
|
||||
if (len != -1) {
|
||||
buff[len] = '\0';
|
||||
return std::string(buff);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
inline std::string getenv_default(const char* env_var, const char * suffix, const char* default_val) {
|
||||
const char* env_val = getenv(env_var);
|
||||
if (env_val != NULL){
|
||||
return std::string(env_val) + std::string(suffix);
|
||||
} else {
|
||||
return std::string(default_val);
|
||||
}
|
||||
}
|
||||
|
||||
inline void sleep_for(const int milliseconds) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||
}
|
||||
}
|
||||
|
||||
class ExitHandler {
|
||||
public:
|
||||
ExitHandler() {
|
||||
std::signal(SIGINT, (sighandler_t)set_do_exit);
|
||||
std::signal(SIGTERM, (sighandler_t)set_do_exit);
|
||||
};
|
||||
inline operator bool() { return do_exit; }
|
||||
inline ExitHandler& operator=(bool v) {
|
||||
do_exit = v;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
static void set_do_exit(int sig) { do_exit = true; }
|
||||
inline static std::atomic<bool> do_exit = false;
|
||||
};
|
||||
|
||||
struct unique_fd {
|
||||
unique_fd(int fd = -1) : fd_(fd) {}
|
||||
unique_fd& operator=(unique_fd&& uf) {
|
||||
fd_ = uf.fd_;
|
||||
uf.fd_ = -1;
|
||||
return *this;
|
||||
}
|
||||
~unique_fd() {
|
||||
if (fd_ != -1) close(fd_);
|
||||
}
|
||||
operator int() const { return fd_; }
|
||||
int fd_;
|
||||
};
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include "messaging.hpp"
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/timing.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <log/logprint.h>
|
||||
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "messaging.hpp"
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <systemd/sd-journal.h>
|
||||
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "messaging.hpp"
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "common/timing.h"
|
||||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "camerad/cameras/camera_common.h"
|
||||
#include "logger.h"
|
||||
|
|
|
@ -16,7 +16,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
#include "common/swaglog.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "raw_logger.h"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "common/visionipc.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "RawLogger.h"
|
||||
|
||||
int main() {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "visionbuf.h"
|
||||
#include "visionipc_client.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "models/dmonitoring.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "visionipc_client.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/clutil.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "models/driving.h"
|
||||
#include "messaging.hpp"
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/swaglog.h"
|
||||
#include <cassert>
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "common/timing.h"
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "messaging.hpp"
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "common/swaglog.h"
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "common/swaglog.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "bmx055_magn.hpp"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "messaging.hpp"
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "common/swaglog.h"
|
||||
|
||||
// ACCELEROMETER_UNCALIBRATED is only in Android O
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "messaging.hpp"
|
||||
#include "common/i2c.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
#include "common/swaglog.h"
|
||||
|
||||
#include "sensors/sensor.hpp"
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/params.h"
|
||||
#include "common/touch.h"
|
||||
#include "common/swaglog.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "widgets/offroad_alerts.hpp"
|
||||
|
||||
#include "common/params.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
|
||||
ParamsToggle::ParamsToggle(QString param, QString title, QString description, QString icon_path, QWidget *parent): QFrame(parent) , param(param) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "drive_stats.hpp"
|
||||
#include "common/params.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "common/util.h"
|
||||
|
||||
|
||||
constexpr double MILE_TO_KM = 1.60934;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "common/util.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/visionimg.h"
|
||||
#include "common/utilpp.h"
|
||||
#include "ui.hpp"
|
||||
#include "paint.hpp"
|
||||
|
||||
|
|
Loading…
Reference in New Issue