Skip to content

Commit

Permalink
Meta: Add pre-commit and clang format (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensElflein authored Jul 24, 2024
1 parent 66aa9ce commit f8fc0d0
Show file tree
Hide file tree
Showing 82 changed files with 5,033 additions and 4,915 deletions.
10 changes: 5 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"name": "ROS Noetic Development Container",
"dockerComposeFile": "../devenv/docker-compose.yaml",
"service": "ros",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"extensions": [
Expand All @@ -13,5 +9,9 @@
]
}
},
"remoteUser": "dev"
"dockerComposeFile": "../devenv/docker-compose.yaml",
"name": "ROS Noetic Development Container",
"remoteUser": "dev",
"service": "ros",
"workspaceFolder": "/workspace"
}
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
web/* linguist-vendored

7 changes: 0 additions & 7 deletions .github/pr-labeler.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
# Get the repository's code
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clear_github_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
cache_id: cache.id,
})
}
console.log("Clear completed")
console.log("Clear completed")
11 changes: 0 additions & 11 deletions .github/workflows/label-prs.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ CATKIN_IGNORE

cmake-build-debug/
.vscode

28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
exclude: '^(config|web)/.+$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: pretty-format-json
args: [--autofix]
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [--style=Google, -i]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,3 @@ the avoidance of doubt, this paragraph does not form part of the
public licenses.

Creative Commons may be contacted at creativecommons.org.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ Copy the settings for **Build directory** and **CMake options**. Everything else
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.

Feel free to use the design in your private/educational projects, but don't try to sell the design or products based on it without getting my consent first. The idea here is to share knowledge, not to enable others to simply sell my work. Thank you for understanding.

2 changes: 1 addition & 1 deletion devenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ A Dockerized version of ros-noetic-desktop-full.

## How to use
- run `./start_devenv.sh` to build and run the ROS container. This will start the container in the background, you can attach to it later.
- run `./attach.sh` to attach to the container. You should be able to do `catkin_make` and also use tools like `rviz`
- run `./attach.sh` to attach to the container. You should be able to do `catkin_make` and also use tools like `rviz`
1 change: 0 additions & 1 deletion devenv/attach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export MY_UID=$(id -u)
export MY_GID=$(id -g)
export MY_USER=${USER}
docker compose exec -it ros /ros_entrypoint.sh bash

1 change: 0 additions & 1 deletion devenv/start_devenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export MY_GID=$(id -g)
export MY_USER=${USER}
docker compose down
docker compose up --build -d --wait

2 changes: 1 addition & 1 deletion docker/assets/mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ allow_anonymous true

listener 9001
protocol websockets
allow_anonymous true
allow_anonymous true
Binary file added pre-commit
Binary file not shown.
169 changes: 75 additions & 94 deletions src/mower_comms/src/COBS.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// Copyright (c) 2011 Christopher Baker <https://christopherbaker.net>
// Copyright (c) 2011 Jacques Fortier <https://github.com/jacquesf/COBS-Consistent-Overhead-Byte-Stuffing>
// Copyright (c) 2011 Jacques Fortier
// <https://github.com/jacquesf/COBS-Consistent-Overhead-Byte-Stuffing>
//
// SPDX-License-Identifier: MIT
//

#ifndef SRC_COBS_H
#define SRC_COBS_H


/// \brief A Consistent Overhead Byte Stuffing (COBS) Encoder.
///
/// Consistent Overhead Byte Stuffing (COBS) is an encoding that removes all 0
Expand All @@ -24,106 +24,87 @@
/// \sa http://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing
/// \sa https://github.com/jacquesf/COBS-Consistent-Overhead-Byte-Stuffing
/// \sa http://www.jacquesf.com/2011/03/consistent-overhead-byte-stuffing
class COBS
{
public:
/// \brief Encode a byte buffer with the COBS encoder.
/// \param buffer A pointer to the unencoded buffer to encode.
/// \param size The number of bytes in the \p buffer.
/// \param encodedBuffer The buffer for the encoded bytes.
/// \returns The number of bytes written to the \p encodedBuffer.
/// \warning The encodedBuffer must have at least getEncodedBufferSize()
/// allocated.
static size_t encode(const uint8_t* buffer,
size_t size,
uint8_t* encodedBuffer)
{
size_t read_index = 0;
size_t write_index = 1;
size_t code_index = 0;
uint8_t code = 1;

while (read_index < size)
{
if (buffer[read_index] == 0)
{
encodedBuffer[code_index] = code;
code = 1;
code_index = write_index++;
read_index++;
}
else
{
encodedBuffer[write_index++] = buffer[read_index++];
code++;

if (code == 0xFF)
{
encodedBuffer[code_index] = code;
code = 1;
code_index = write_index++;
}
}
class COBS {
public:
/// \brief Encode a byte buffer with the COBS encoder.
/// \param buffer A pointer to the unencoded buffer to encode.
/// \param size The number of bytes in the \p buffer.
/// \param encodedBuffer The buffer for the encoded bytes.
/// \returns The number of bytes written to the \p encodedBuffer.
/// \warning The encodedBuffer must have at least getEncodedBufferSize()
/// allocated.
static size_t encode(const uint8_t* buffer, size_t size,
uint8_t* encodedBuffer) {
size_t read_index = 0;
size_t write_index = 1;
size_t code_index = 0;
uint8_t code = 1;

while (read_index < size) {
if (buffer[read_index] == 0) {
encodedBuffer[code_index] = code;
code = 1;
code_index = write_index++;
read_index++;
} else {
encodedBuffer[write_index++] = buffer[read_index++];
code++;

if (code == 0xFF) {
encodedBuffer[code_index] = code;
code = 1;
code_index = write_index++;
}
}
}

encodedBuffer[code_index] = code;
encodedBuffer[code_index] = code;

return write_index;
}
return write_index;
}

/// \brief Decode a COBS-encoded buffer.
/// \param encodedBuffer A pointer to the \p encodedBuffer to decode.
/// \param size The number of bytes in the \p encodedBuffer.
/// \param decodedBuffer The target buffer for the decoded bytes.
/// \returns The number of bytes written to the \p decodedBuffer.
/// \warning decodedBuffer must have a minimum capacity of size.
static size_t decode(const uint8_t* encodedBuffer, size_t size,
uint8_t* decodedBuffer) {
if (size == 0) return 0;

/// \brief Decode a COBS-encoded buffer.
/// \param encodedBuffer A pointer to the \p encodedBuffer to decode.
/// \param size The number of bytes in the \p encodedBuffer.
/// \param decodedBuffer The target buffer for the decoded bytes.
/// \returns The number of bytes written to the \p decodedBuffer.
/// \warning decodedBuffer must have a minimum capacity of size.
static size_t decode(const uint8_t* encodedBuffer,
size_t size,
uint8_t* decodedBuffer)
{
if (size == 0)
return 0;

size_t read_index = 0;
size_t write_index = 0;
uint8_t code = 0;
uint8_t i = 0;

while (read_index < size)
{
code = encodedBuffer[read_index];

if (read_index + code > size && code != 1)
{
return 0;
}

read_index++;

for (i = 1; i < code; i++)
{
decodedBuffer[write_index++] = encodedBuffer[read_index++];
}

if (code != 0xFF && read_index != size)
{
decodedBuffer[write_index++] = '\0';
}
}
size_t read_index = 0;
size_t write_index = 0;
uint8_t code = 0;
uint8_t i = 0;

return write_index;
}
while (read_index < size) {
code = encodedBuffer[read_index];

if (read_index + code > size && code != 1) {
return 0;
}

read_index++;

/// \brief Get the maximum encoded buffer size for an unencoded buffer size.
/// \param unencodedBufferSize The size of the buffer to be encoded.
/// \returns the maximum size of the required encoded buffer.
static size_t getEncodedBufferSize(size_t unencodedBufferSize)
{
return unencodedBufferSize + unencodedBufferSize / 254 + 1;
for (i = 1; i < code; i++) {
decodedBuffer[write_index++] = encodedBuffer[read_index++];
}

if (code != 0xFF && read_index != size) {
decodedBuffer[write_index++] = '\0';
}
}

};
return write_index;
}

/// \brief Get the maximum encoded buffer size for an unencoded buffer size.
/// \param unencodedBufferSize The size of the buffer to be encoded.
/// \returns the maximum size of the required encoded buffer.
static size_t getEncodedBufferSize(size_t unencodedBufferSize) {
return unencodedBufferSize + unencodedBufferSize / 254 + 1;
}
};

#endif
#endif
Loading

0 comments on commit f8fc0d0

Please sign in to comment.