From 2015e47c58115e37d8a5b65b892b5cf0aa53a5dd Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:50:54 -0800 Subject: [PATCH 01/12] create yml workflow to lint code --- .github/workflows/linter.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..fecb72c --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,17 @@ +name: lint-code + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.18.1 + with: + source: '.' + exclude: './third_party ./external' + extensions: 'h,cpp' + clangFormatVersion: 18 + style: chromium \ No newline at end of file From 1cadc94e74b8a48755675f987be86a4286a72909 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:55:38 -0800 Subject: [PATCH 02/12] chatgpt linter lol --- .github/workflows/cpp-linter.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/cpp-linter.yml diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml new file mode 100644 index 0000000..586d6dd --- /dev/null +++ b/.github/workflows/cpp-linter.yml @@ -0,0 +1,30 @@ +name: C++ Lint + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + name: Lint C++ Code + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Install clang-format and cppcheck + run: sudo apt-get install -y clang-format cppcheck + + - name: Run clang-format + run: | + find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs clang-format -i + git diff --exit-code || (echo "Code is not formatted. Run clang-format locally." && exit 1) + + - name: Run cppcheck + run: | + cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet . From f05b1b77f32fd218f7a47bd66fa0bd0642130fbc Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:58:01 -0800 Subject: [PATCH 03/12] more chatgpt code --- .github/workflows/cpp-linter.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 586d6dd..e6ac87a 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -1,4 +1,4 @@ -name: C++ Lint +name: C++ Lint and Auto-Fix on: push: @@ -8,6 +8,9 @@ on: branches: - main +permissions: + contents: write # Required for pushing auto-fix commits + jobs: lint: name: Lint C++ Code @@ -16,14 +19,19 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure we have full commit history for pushing changes - name: Install clang-format and cppcheck run: sudo apt-get install -y clang-format cppcheck - - name: Run clang-format + - name: Run clang-format and fix issues run: | find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs clang-format -i - git diff --exit-code || (echo "Code is not formatted. Run clang-format locally." && exit 1) + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add . + git diff --cached --quiet || (git commit -m "Auto-format C++ code using clang-format" && git push) - name: Run cppcheck run: | From 067105b2d8a1bc8fa554fcddc33ada1db5fc5212 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:59:13 -0800 Subject: [PATCH 04/12] fix for chatgpt code --- .github/workflows/cpp-linter.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index e6ac87a..b0ee02c 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -20,7 +20,8 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Ensure we have full commit history for pushing changes + ref: ${{ github.head_ref }} # Checkout the correct branch + fetch-depth: 0 # Ensure full commit history for pushing changes - name: Install clang-format and cppcheck run: sudo apt-get install -y clang-format cppcheck @@ -30,8 +31,15 @@ jobs: find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs clang-format -i git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + # Ensure we are on the correct branch + git checkout ${{ github.head_ref }} + git add . - git diff --cached --quiet || (git commit -m "Auto-format C++ code using clang-format" && git push) + if ! git diff --cached --quiet; then + git commit -m "Auto-format C++ code using clang-format" + git push origin ${{ github.head_ref }} + fi - name: Run cppcheck run: | From 0af0d0f863dd2f2b96852b36f57f370c75f85304 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 8 Feb 2025 02:59:37 +0000 Subject: [PATCH 05/12] Auto-format C++ code using clang-format --- src/BooleanValueSender.h | 4 +- src/DoubleArraySender.h | 4 +- src/DoubleValueSender.h | 4 +- src/IntegerArraySender.h | 4 +- src/IntegerValueSender.h | 4 +- src/NetworkTablesConfig.h | 4 +- src/NetworkTablesUtil.cpp | 10 ++-- src/NetworkTablesUtil.h | 11 ++-- src/apriltag_gpu.h | 19 +++---- src/cameraexception.h | 4 +- src/cuda_frc971.h | 32 +++++------ src/gpu_image.h | 5 +- src/json_test.cpp | 5 +- src/labeling_allegretti_2019_BKE.h | 2 +- src/line_fit_filter.h | 10 ++-- src/points.h | 88 +++++++++++++++--------------- src/threshold.h | 4 +- src/transform_output_iterator.h | 18 +++--- src/video_processor.h | 20 +++---- src/ws_test.cpp | 20 +++---- 20 files changed, 132 insertions(+), 140 deletions(-) diff --git a/src/BooleanValueSender.h b/src/BooleanValueSender.h index 099bb5b..62d6f4a 100644 --- a/src/BooleanValueSender.h +++ b/src/BooleanValueSender.h @@ -8,11 +8,11 @@ #include "networktables/NetworkTableInstance.h" class BooleanValueSender { - private: +private: nt::NetworkTableInstance inst_; nt::BooleanPublisher publisher_; - public: +public: // Constructor declaration BooleanValueSender(std::string key); diff --git a/src/DoubleArraySender.h b/src/DoubleArraySender.h index 69c5552..7258b34 100644 --- a/src/DoubleArraySender.h +++ b/src/DoubleArraySender.h @@ -9,11 +9,11 @@ #include "networktables/NetworkTableInstance.h" class DoubleArraySender { - private: +private: nt::NetworkTableInstance inst_; nt::DoubleArrayPublisher publisher_; - public: +public: // Constructor declaration DoubleArraySender(std::string key); diff --git a/src/DoubleValueSender.h b/src/DoubleValueSender.h index 5fb901b..8e8c6a9 100644 --- a/src/DoubleValueSender.h +++ b/src/DoubleValueSender.h @@ -8,11 +8,11 @@ #include "networktables/NetworkTableInstance.h" class DoubleValueSender { - private: +private: nt::NetworkTableInstance inst_; nt::DoublePublisher publisher_; - public: +public: // Constructor declaration DoubleValueSender(std::string key); diff --git a/src/IntegerArraySender.h b/src/IntegerArraySender.h index 895ffb2..bfabcf7 100644 --- a/src/IntegerArraySender.h +++ b/src/IntegerArraySender.h @@ -10,11 +10,11 @@ #include "networktables/NetworkTableInstance.h" class IntegerArraySender { - private: +private: nt::NetworkTableInstance inst_; nt::IntegerArrayPublisher publisher_; - public: +public: // Constructor declaration IntegerArraySender(std::string key); diff --git a/src/IntegerValueSender.h b/src/IntegerValueSender.h index c884b3e..d1c27ad 100644 --- a/src/IntegerValueSender.h +++ b/src/IntegerValueSender.h @@ -8,11 +8,11 @@ #include "networktables/NetworkTableInstance.h" class IntegerValueSender { - private: +private: nt::NetworkTableInstance inst_; nt::IntegerPublisher publisher_; - public: +public: // Constructor declaration IntegerValueSender(std::string key); diff --git a/src/NetworkTablesConfig.h b/src/NetworkTablesConfig.h index 95805b0..4b15dcf 100644 --- a/src/NetworkTablesConfig.h +++ b/src/NetworkTablesConfig.h @@ -1,7 +1,7 @@ #ifndef NETWORK_TABLES_CONFIG_H_ #define NETWORK_TABLES_CONFIG_H_ -inline const char* TABLE_ADDRESS = "10.7.66.2"; -inline const char* TABLE_NAME = "/SmartDashboard"; +inline const char *TABLE_ADDRESS = "10.7.66.2"; +inline const char *TABLE_NAME = "/SmartDashboard"; #endif diff --git a/src/NetworkTablesUtil.cpp b/src/NetworkTablesUtil.cpp index 455a845..a2ba1d5 100644 --- a/src/NetworkTablesUtil.cpp +++ b/src/NetworkTablesUtil.cpp @@ -3,11 +3,9 @@ #include "NetworkTablesConfig.h" NetworkTablesUtil::NetworkTablesUtil() { -// inst_ = nt::NetworkTableInstance::GetDefault(); -// inst_.SetServer(TABLE_ADDRESS); -// inst_.StartClient4(TABLE_ADDRESS); + // inst_ = nt::NetworkTableInstance::GetDefault(); + // inst_.SetServer(TABLE_ADDRESS); + // inst_.StartClient4(TABLE_ADDRESS); } -double NetworkTablesUtil::getTime() { - return wpi::GetSystemTime(); -} +double NetworkTablesUtil::getTime() { return wpi::GetSystemTime(); } diff --git a/src/NetworkTablesUtil.h b/src/NetworkTablesUtil.h index 1ba1068..0914e39 100644 --- a/src/NetworkTablesUtil.h +++ b/src/NetworkTablesUtil.h @@ -1,16 +1,15 @@ #ifndef NETWORKTABLESUTIL_H #define NETWORKTABLESUTIL_H - -//#include "networktables/NetworkTable.h" -//#include "networktables/NetworkTableInstance.h" +// #include "networktables/NetworkTable.h" +// #include "networktables/NetworkTableInstance.h" #include "wpi/timestamp.h" class NetworkTablesUtil { - //private: - //nt::NetworkTableInstance inst_; + // private: + // nt::NetworkTableInstance inst_; - public: +public: // Constructor declaration NetworkTablesUtil(); diff --git a/src/apriltag_gpu.h b/src/apriltag_gpu.h index ac5a093..3a3f00d 100644 --- a/src/apriltag_gpu.h +++ b/src/apriltag_gpu.h @@ -15,7 +15,7 @@ namespace frc971::apriltag { // Class to find the blob index of a point in a point vector. class BlobExtentsIndexFinder { - public: +public: BlobExtentsIndexFinder(const MinMaxExtents *extents_device, size_t num_extents) : extents_device_(extents_device), num_extents_(num_extents) {} @@ -45,7 +45,7 @@ class BlobExtentsIndexFinder { return extents_device_[index]; } - private: +private: const MinMaxExtents *extents_device_; size_t num_extents_; @@ -75,7 +75,7 @@ struct DistCoeffs { // GPU based april tag detector. class GpuDetector { - public: +public: // The number of blobs we will consider when counting april tags. static constexpr size_t kMaxBlobs = IndexPoint::kMaxBlobs; @@ -138,8 +138,8 @@ class GpuDetector { return extents_device_.Copy(NumQuads()); } - std::vector> CopySelectedExtents() - const { + std::vector> + CopySelectedExtents() const { return selected_extents_device_.Copy(NumQuads()); } @@ -199,7 +199,7 @@ class GpuDetector { static bool UnDistort(double *u, double *v, const CameraMatrix *camera_matrix, const DistCoeffs *distortion_coefficients); - private: +private: void UpdateFitQuads(); void AdjustPixelCenters(); @@ -209,8 +209,7 @@ class GpuDetector { static void QuadDecodeTask(void *_u); // Creates a GPU image wrapped around the provided memory. - template - GpuImage ToGpuImage(GpuMemory &memory) { + template GpuImage ToGpuImage(GpuMemory &memory) { if (memory.size() == width_ * height_) { return GpuImage{ .data = memory.get(), @@ -359,6 +358,6 @@ class GpuDetector { zarray_t *detections_ = nullptr; }; -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_ORIN_APRILTAG_H_ +#endif // FRC971_ORIN_APRILTAG_H_ diff --git a/src/cameraexception.h b/src/cameraexception.h index efb66e9..76e64d5 100644 --- a/src/cameraexception.h +++ b/src/cameraexception.h @@ -2,8 +2,8 @@ #define CAMERAEXCEPTION_H_ class CameraException : public std::exception { - public: - const char* what() const noexcept override { +public: + const char *what() const noexcept override { return "Error: No camera detected."; } }; diff --git a/src/cuda_frc971.h b/src/cuda_frc971.h index 7873760..dd98f92 100644 --- a/src/cuda_frc971.h +++ b/src/cuda_frc971.h @@ -11,9 +11,9 @@ // CHECKs that a cuda method returned success. // TODO(austin): This will not handle if and else statements quite right, fix if // we care. -#define CHECK_CUDA(condition) \ - if (auto c = condition) \ - LOG(FATAL) << "Check failed: " #condition " (" << cudaGetErrorString(c) \ +#define CHECK_CUDA(condition) \ + if (auto c = condition) \ + LOG(FATAL) << "Check failed: " #condition " (" << cudaGetErrorString(c) \ << ") " namespace frc971::apriltag { @@ -21,7 +21,7 @@ namespace frc971::apriltag { // Class to manage the lifetime of a Cuda stream. This is used to provide // relative ordering between kernels on the same stream. class CudaStream { - public: +public: CudaStream() { CHECK_CUDA(cudaStreamCreate(&stream_)); } CudaStream(const CudaStream &) = delete; @@ -32,14 +32,14 @@ class CudaStream { // Returns the stream. cudaStream_t get() { return stream_; } - private: +private: cudaStream_t stream_; }; // Class to manage the lifetime of a Cuda Event. Cuda events are used for // timing events on a stream. class CudaEvent { - public: +public: CudaEvent() { CHECK_CUDA(cudaEventCreate(&event_)); } CudaEvent(const CudaEvent &) = delete; @@ -64,15 +64,14 @@ class CudaEvent { // Waits until the event has been triggered. void Synchronize() { CHECK_CUDA(cudaEventSynchronize(event_)); } - private: +private: cudaEvent_t event_; }; // Class to manage the lifetime of page locked host memory for fast copies back // to host memory. -template -class HostMemory { - public: +template class HostMemory { +public: // Allocates a block of memory for holding up to size objects of type T. HostMemory(size_t size) { T *memory; @@ -100,14 +99,13 @@ class HostMemory { memcpy(other, span_.data(), sizeof(T) * size()); } - private: +private: std::span span_; }; // Class to manage the lifetime of device memory. -template -class GpuMemory { - public: +template class GpuMemory { +public: // Allocates a block of memory for holding up to size objects of type T in // device memory. GpuMemory(size_t size) : size_(size) { @@ -190,7 +188,7 @@ class GpuMemory { // it. std::vector Copy() const { return Copy(size_); } - private: +private: T *memory_; const size_t size_; }; @@ -203,6 +201,6 @@ void CheckAndSynchronize(std::string_view message = ""); void MaybeCheckAndSynchronize(); void MaybeCheckAndSynchronize(std::string_view message); -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_ORIN_CUDA_H_ +#endif // FRC971_ORIN_CUDA_H_ diff --git a/src/gpu_image.h b/src/gpu_image.h index 732b256..64def29 100644 --- a/src/gpu_image.h +++ b/src/gpu_image.h @@ -1,8 +1,7 @@ #ifndef FRC971_ORIN_GPU_IMAGE_H_ #define FRC971_ORIN_GPU_IMAGE_H_ -template -struct GpuImage { +template struct GpuImage { typedef T type; T *data; size_t rows; @@ -11,4 +10,4 @@ struct GpuImage { size_t step; }; -#endif // FRC971_ORIN_GPU_IMAGE_H_ +#endif // FRC971_ORIN_GPU_IMAGE_H_ diff --git a/src/json_test.cpp b/src/json_test.cpp index 0802c42..93c01de 100644 --- a/src/json_test.cpp +++ b/src/json_test.cpp @@ -5,9 +5,8 @@ #include using json = nlohmann::json; int main(void) { - std::ifstream f( - "/home/nvidia/code/OrinVisionSystem/cameracalibration/" - "calibrationmatrix.json"); + std::ifstream f("/home/nvidia/code/OrinVisionSystem/cameracalibration/" + "calibrationmatrix.json"); json data = json::parse(f); std::cout << "Matrix: " << std::endl; for (int i = 0; i < 3; ++i) { diff --git a/src/labeling_allegretti_2019_BKE.h b/src/labeling_allegretti_2019_BKE.h index d139c9d..99bebe4 100644 --- a/src/labeling_allegretti_2019_BKE.h +++ b/src/labeling_allegretti_2019_BKE.h @@ -10,4 +10,4 @@ void LabelImage(const GpuImage input, GpuImage output, GpuImage union_markers_size_device, cudaStream_t stream); -#endif // FRC971_ORIN_LABELING_ALLEGRETTI_2019_BKE_H_ +#endif // FRC971_ORIN_LABELING_ALLEGRETTI_2019_BKE_H_ diff --git a/src/line_fit_filter.h b/src/line_fit_filter.h index ce33d3b..e9410a6 100644 --- a/src/line_fit_filter.h +++ b/src/line_fit_filter.h @@ -90,7 +90,7 @@ struct LineFitMoments { int64_t Mxx; int64_t Myy; int64_t Mxy; - int N; // how many points are included in the set? + int N; // how many points are included in the set? }; std::ostream &operator<<(std::ostream &os, @@ -113,8 +113,8 @@ struct PeakExtents { struct PeakDecomposer { static constexpr size_t kBitsInKey = 16 + 32; - __host__ __device__ ::cuda::std::tuple operator()( - Peak &key) const { + __host__ __device__ ::cuda::std::tuple + operator()(Peak &key) const { return {key.blob_index, key.error}; } }; @@ -159,6 +159,6 @@ __host__ __device__ std::tuple Unrank(uint i); // The max number of work elements for a max maxes of 10. constexpr size_t MaxRankedIndex() { return 210; } -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_ORIN_LINE_FIT_FILTER_H_ +#endif // FRC971_ORIN_LINE_FIT_FILTER_H_ diff --git a/src/points.h b/src/points.h index 745e151..a6194da 100644 --- a/src/points.h +++ b/src/points.h @@ -82,14 +82,14 @@ struct QuadBoundaryPoint { // Returns the change in x derived from the search direction. __forceinline__ __host__ __device__ int32_t dx() const { switch (key & 0x3) { - case 0: - return 1; - case 1: - return 1; - case 2: - return 0; - case 3: - return -1; + case 0: + return 1; + case 1: + return 1; + case 2: + return 0; + case 3: + return -1; } return 0; } @@ -97,12 +97,12 @@ struct QuadBoundaryPoint { // Returns the change in y derived from the search direction. __forceinline__ __host__ __device__ int32_t dy() const { switch (key & 0x3) { - case 0: - return 0; - case 1: - case 2: - case 3: - return 1; + case 0: + return 0; + case 1: + case 2: + case 3: + return 1; } return 0; } @@ -125,8 +125,8 @@ struct QuadBoundaryPoint { } // Returns the black to white or white to black bit. - __forceinline__ __host__ __device__ void set_black_to_white( - bool black_to_white) { + __forceinline__ __host__ __device__ void + set_black_to_white(bool black_to_white) { key = (key & 0xfffffffffffffff7ull) | (static_cast(black_to_white) << 3); } @@ -135,16 +135,16 @@ struct QuadBoundaryPoint { } // Various operators to make it easy to compare points. - __forceinline__ __host__ __device__ bool operator!=( - const QuadBoundaryPoint other) const { + __forceinline__ __host__ __device__ bool + operator!=(const QuadBoundaryPoint other) const { return other.key != key; } - __forceinline__ __host__ __device__ bool operator==( - const QuadBoundaryPoint other) const { + __forceinline__ __host__ __device__ bool + operator==(const QuadBoundaryPoint other) const { return other.key == key; } - __forceinline__ __host__ __device__ bool operator<( - const QuadBoundaryPoint other) const { + __forceinline__ __host__ __device__ bool + operator<(const QuadBoundaryPoint other) const { return key < other.key; } @@ -223,26 +223,26 @@ struct IndexPoint { __forceinline__ __host__ __device__ int32_t dx() const { switch (key & 0x3) { - case 0: - return 1; - case 1: - return 1; - case 2: - return 0; - case 3: - return -1; + case 0: + return 1; + case 1: + return 1; + case 2: + return 0; + case 3: + return -1; } return 0; } __forceinline__ __host__ __device__ int32_t dy() const { switch (key & 0x3) { - case 0: - return 0; - case 1: - case 2: - case 3: - return 1; + case 0: + return 0; + case 1: + case 2: + case 3: + return 1; } return 0; } @@ -265,8 +265,8 @@ struct IndexPoint { return key & 0xffffff; } - __forceinline__ __host__ __device__ void set_black_to_white( - bool black_to_white) { + __forceinline__ __host__ __device__ void + set_black_to_white(bool black_to_white) { key = (key & 0xfffffffffffffff7ull) | (static_cast(black_to_white) << 3); } @@ -282,20 +282,20 @@ std::ostream &operator<<(std::ostream &os, const IndexPoint &point); // Decomposer for sorting which just returns the key. struct QuadBoundaryPointDecomposer { - __host__ __device__ ::cuda::std::tuple operator()( - QuadBoundaryPoint &key) const { + __host__ __device__ ::cuda::std::tuple + operator()(QuadBoundaryPoint &key) const { return {key.key}; } }; // Decomposer for sorting which just returns the key. struct QuadIndexPointDecomposer { - __host__ __device__ ::cuda::std::tuple operator()( - IndexPoint &key) const { + __host__ __device__ ::cuda::std::tuple + operator()(IndexPoint &key) const { return {key.key}; } }; -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_ORIN_POINTS_H_ +#endif // FRC971_ORIN_POINTS_H_ diff --git a/src/threshold.h b/src/threshold.h index 56f2314..4eb5f30 100644 --- a/src/threshold.h +++ b/src/threshold.h @@ -15,6 +15,6 @@ void CudaToGreyscaleAndDecimateHalide( uint8_t *thresholded_image, size_t width, size_t height, size_t min_white_black_diff, CudaStream *stream); -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_ORIN_THRESHOLD_H_ +#endif // FRC971_ORIN_THRESHOLD_H_ diff --git a/src/transform_output_iterator.h b/src/transform_output_iterator.h index cdda637..ca3c39e 100644 --- a/src/transform_output_iterator.h +++ b/src/transform_output_iterator.h @@ -7,7 +7,7 @@ namespace frc971::apriltag { template class TransformOutputIterator { - private: +private: // proxy object to be able to convert when assigning value struct Reference { OutputType *ptr; @@ -20,7 +20,7 @@ class TransformOutputIterator { } }; - public: +public: // typedefs may not be neeeded for iterator to work but is here to maintain // similarity to cub's CacheModifiedOutputIterator typedef TransformOutputIterator self_type; @@ -69,22 +69,22 @@ class TransformOutputIterator { } // equal to - __host__ __device__ __forceinline__ bool operator==( - const TransformOutputIterator &rhs) const { + __host__ __device__ __forceinline__ bool + operator==(const TransformOutputIterator &rhs) const { return ptr == rhs.ptr; } // not equal to - __host__ __device__ __forceinline__ bool operator!=( - const TransformOutputIterator &rhs) const { + __host__ __device__ __forceinline__ bool + operator!=(const TransformOutputIterator &rhs) const { return ptr != rhs.ptr; } - private: +private: const ConversionOp convert_op; OutputType *ptr; }; -} // namespace frc971::apriltag +} // namespace frc971::apriltag -#endif // FRC971_TRANSFORM_OUTPUT_ITERATOR_ +#endif // FRC971_TRANSFORM_OUTPUT_ITERATOR_ diff --git a/src/video_processor.h b/src/video_processor.h index c022665..1897082 100644 --- a/src/video_processor.h +++ b/src/video_processor.h @@ -11,10 +11,10 @@ using namespace std; using namespace cv; class VideoProcessor { - public: - VideoProcessor(const int camera_index, const std::string& tag_family_name, - const frc971::apriltag::CameraMatrix& camera_matrix, - const frc971::apriltag::DistCoeffs& distortion_coefficients, +public: + VideoProcessor(const int camera_index, const std::string &tag_family_name, + const frc971::apriltag::CameraMatrix &camera_matrix, + const frc971::apriltag::DistCoeffs &distortion_coefficients, int nthreads = 4); ~VideoProcessor(); @@ -22,14 +22,14 @@ class VideoProcessor { bool initialize(); bool process(); - private: - const std::string& tag_family_name_; +private: + const std::string &tag_family_name_; int camera_index_; - const frc971::apriltag::CameraMatrix& camera_matrix_; - const frc971::apriltag::DistCoeffs& distortion_coefficients_; + const frc971::apriltag::CameraMatrix &camera_matrix_; + const frc971::apriltag::DistCoeffs &distortion_coefficients_; int nthreads_; - apriltag_family_t* tf_; - apriltag_detector_t* td_; + apriltag_family_t *tf_; + apriltag_detector_t *td_; std::unique_ptr cap_; std::unique_ptr gpu_detector_; bool initialized_; diff --git a/src/ws_test.cpp b/src/ws_test.cpp index f9c8a59..13def02 100644 --- a/src/ws_test.cpp +++ b/src/ws_test.cpp @@ -48,19 +48,19 @@ using namespace cv; using namespace seasocks; class MyHandler : public WebSocket::Handler { - public: - explicit MyHandler(Server* server) : _server(server) {} +public: + explicit MyHandler(Server *server) : _server(server) {} - void onConnect(WebSocket* connection) override { + void onConnect(WebSocket *connection) override { _connections.insert(connection); std::cout << "Connected: " << connection->getRequestUri() << " : " << formatAddress(connection->getRemoteAddress()) << "\nCredentials: " << *(connection->credentials()) << "\n"; } - void onData(WebSocket* connection, const char* data) override {} + void onData(WebSocket *connection, const char *data) override {} - void sendImage(const cv::Mat& image) { + void sendImage(const cv::Mat &image) { for (auto c : _connections) { std::vector buf; cv::imencode(".jpg", image, buf); @@ -68,15 +68,15 @@ class MyHandler : public WebSocket::Handler { } } - void onDisconnect(WebSocket* connection) override { + void onDisconnect(WebSocket *connection) override { _connections.erase(connection); std::cout << "Disconnected: " << connection->getRequestUri() << " : " << formatAddress(connection->getRemoteAddress()) << "\n"; } - private: - std::set _connections; - Server* _server; +private: + std::set _connections; + Server *_server; }; void send_data(std::shared_ptr handler) { @@ -87,7 +87,7 @@ void send_data(std::shared_ptr handler) { } } -int main(int /*argc*/, const char* /*argv*/[]) { +int main(int /*argc*/, const char * /*argv*/[]) { auto logger = std::make_shared(Logger::Level::Debug); Server server(logger); From 937a5d9c3657693cda7ed453424ffc383deb04f1 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:01:19 -0800 Subject: [PATCH 06/12] suppresses some things --- .github/workflows/cpp-linter.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index b0ee02c..148e64d 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -43,4 +43,7 @@ jobs: - name: Run cppcheck run: | - cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet . + cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ + --suppress=missingInclude \ + --suppress=unusedFunction \ + --suppress=unmatchedSuppression From ab510e72e22629b10d680857751a4958ecab1191 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:04:19 -0800 Subject: [PATCH 07/12] fix --- .github/workflows/cpp-linter.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 148e64d..43bcae7 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -41,9 +41,16 @@ jobs: git push origin ${{ github.head_ref }} fi - - name: Run cppcheck - run: | - cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ - --suppress=missingInclude \ - --suppress=unusedFunction \ - --suppress=unmatchedSuppression + - name: Run cppcheck + run: | + FILES=$(find . -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \)) + if [ -z "$FILES" ]; then + echo "No C or C++ source files found. Skipping cppcheck." + exit 0 + fi + + cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ + --suppress=missingInclude \ + --suppress=unusedFunction \ + --suppress=unmatchedSuppression $FILES + From 0b6d5ac989a7d53e5340ecb1421b56d8fba26508 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:06:46 -0800 Subject: [PATCH 08/12] fix probably --- .github/workflows/cpp-linter.yml | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 43bcae7..72ab960 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -28,7 +28,13 @@ jobs: - name: Run clang-format and fix issues run: | - find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs clang-format -i + FILES=$(find . -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \) | tr '\n' ' ') + if [ -z "$FILES" ]; then + echo "No C++ source files found. Skipping clang-format." + exit 0 + fi + + clang-format -i $FILES git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' @@ -41,16 +47,16 @@ jobs: git push origin ${{ github.head_ref }} fi - - name: Run cppcheck - run: | - FILES=$(find . -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \)) - if [ -z "$FILES" ]; then - echo "No C or C++ source files found. Skipping cppcheck." - exit 0 - fi - - cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ - --suppress=missingInclude \ - --suppress=unusedFunction \ - --suppress=unmatchedSuppression $FILES - + - name: Run cppcheck + run: | + FILES=$(find . -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \) | tr '\n' ' ') + if [ -z "$FILES" ]; then + echo "No C++ source files found. Skipping cppcheck." + exit 0 + fi + + echo "Running cppcheck on: $FILES" + cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ + --suppress=missingInclude \ + --suppress=unusedFunction \ + --suppress=unmatchedSuppression $FILES From 4056e5f17c8dd576d3397f88641de9043c812a96 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:10:12 -0800 Subject: [PATCH 09/12] fixes lol --- .github/workflows/cpp-linter.yml | 4 ++-- .github/workflows/linter.yml | 17 ----------------- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 72ab960..e947518 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -47,7 +47,7 @@ jobs: git push origin ${{ github.head_ref }} fi - - name: Run cppcheck + - name: Run cppcheck (C++ Mode) run: | FILES=$(find . -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" \) | tr '\n' ' ') if [ -z "$FILES" ]; then @@ -56,7 +56,7 @@ jobs: fi echo "Running cppcheck on: $FILES" - cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet \ + cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet --language=c++ \ --suppress=missingInclude \ --suppress=unusedFunction \ --suppress=unmatchedSuppression $FILES diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml deleted file mode 100644 index fecb72c..0000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: lint-code - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: DoozyX/clang-format-lint-action@v0.18.1 - with: - source: '.' - exclude: './third_party ./external' - extensions: 'h,cpp' - clangFormatVersion: 18 - style: chromium \ No newline at end of file From 9a4876a6e5f9f037ad3521cab897410e0549ea75 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:12:43 -0800 Subject: [PATCH 10/12] suppress more --- .github/workflows/cpp-linter.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index e947518..49dde2e 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -57,6 +57,11 @@ jobs: echo "Running cppcheck on: $FILES" cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet --language=c++ \ - --suppress=missingInclude \ + --suppress=missingIncludeSystem \ + --suppress=unusedStructMember \ + --suppress=noExplicitConstructor \ + --suppress=passedByValue \ + --suppress=useInitializationList \ + --suppress=cstyleCast \ --suppress=unusedFunction \ --suppress=unmatchedSuppression $FILES From 33e4808661665eba95ab90dcdc5dbdaacab0fb94 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:13:52 -0800 Subject: [PATCH 11/12] add one more suppres --- .github/workflows/cpp-linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 49dde2e..49f0d1a 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -65,3 +65,4 @@ jobs: --suppress=cstyleCast \ --suppress=unusedFunction \ --suppress=unmatchedSuppression $FILES + --suppress=missingInclude $FILES From 252b4a3ee5413259ec2955180d1f4584ed98a93f Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:16:27 -0800 Subject: [PATCH 12/12] more --- .github/workflows/cpp-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 49f0d1a..61d01ed 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -57,6 +57,7 @@ jobs: echo "Running cppcheck on: $FILES" cppcheck --enable=all --error-exitcode=1 --inline-suppr --force --quiet --language=c++ \ + --suppress=missingInclude \ --suppress=missingIncludeSystem \ --suppress=unusedStructMember \ --suppress=noExplicitConstructor \ @@ -65,4 +66,3 @@ jobs: --suppress=cstyleCast \ --suppress=unusedFunction \ --suppress=unmatchedSuppression $FILES - --suppress=missingInclude $FILES