Skip to content

Commit 19bef52

Browse files
authored
Merge pull request #24 from apl-ocean-engineering/add_pre_commit_hooks
add pre-commit hooks and make related formatting fixes
2 parents ddccfcf + a0437e4 commit 19bef52

37 files changed

+1351
-1295
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ doc/
44
.DS_Store
55
build/
66

7-
.vscode/
7+
.vscode/

.pre-commit-config.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v3.2.0
6+
hooks:
7+
- id: check-added-large-files
8+
- id: check-json
9+
- id: check-merge-conflict
10+
- id: check-xml
11+
- id: check-yaml
12+
- id: end-of-file-fixer
13+
- id: mixed-line-ending
14+
- id: trailing-whitespace
15+
16+
- repo: https://github.com/pre-commit/mirrors-clang-format
17+
rev: v15.0.4
18+
hooks:
19+
- id: clang-format
20+
# Respect .clang-format if it exists, otherwise use Google
21+
args: ["--fallback-style=Google"]
22+
23+
# - repo: https://gitlab.com/daverona/pre-commit/cpp
24+
# rev: 0.8.0
25+
# hooks:
26+
# - id: cpplint
27+
# args: ["--filter=-build/include_order,-readability/todo"]
28+
29+
- repo: https://github.com/psf/black
30+
rev: 22.12.0
31+
hooks:
32+
- id: black
33+
# For now, no configuration. May want "--line-length 80"
34+
- repo: https://github.com/PyCQA/flake8
35+
rev: 6.0.0
36+
hooks:
37+
- id: flake8
38+
# pep8-naming catches camel_case violations
39+
additional_dependencies: [pep8-naming, flake8-bugbear, flake8-comprehensions]
40+
# formatting handles line-length, no reason for linter to also flag.
41+
args: [--ignore, E501]

fips

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import os
44
import sys
55
import subprocess
6+
67
proj_path = os.path.dirname(os.path.abspath(__file__))
7-
fips_path = os.path.dirname(proj_path) + '/fips'
8-
if not os.path.isdir(fips_path) :
8+
fips_path = os.path.dirname(proj_path) + "/fips"
9+
if not os.path.isdir(fips_path):
910
print("\033[93m=== cloning fips build system to '{}':\033[0m".format(fips_path))
10-
subprocess.call(['git', 'clone', 'https://github.com/amarburg/fips.git', fips_path])
11-
sys.path.insert(0,fips_path)
12-
try :
11+
subprocess.call(["git", "clone", "https://github.com/amarburg/fips.git", fips_path])
12+
sys.path.insert(0, fips_path)
13+
try:
1314
from mod import fips
14-
except ImportError :
15-
print("\033[91m[ERROR]\033[0m failed to initialize fips build system in '{}'".format(proj_path))
15+
except ImportError:
16+
print(
17+
"\033[91m[ERROR]\033[0m failed to initialize fips build system in '{}'".format(
18+
proj_path
19+
)
20+
)
1621
sys.exit(10)
1722
fips.run(fips_path, proj_path, sys.argv)

include/liboculus/BearingData.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ namespace liboculus {
3939

4040
class BearingData {
4141
public:
42-
BearingData()
43-
: _data(nullptr), _numBeams(0)
44-
{;}
42+
BearingData() : _data(nullptr), _numBeams(0) { ; }
4543

46-
BearingData(const BearingData &other) = default;
44+
BearingData(const BearingData &other) = default;
4745

4846
BearingData(const int16_t *data, int nBeams)
49-
: _data(data),
50-
_numBeams(nBeams) {}
47+
: _data(data), _numBeams(nBeams) {}
5148

5249
int size() const { return _numBeams; }
5350

@@ -61,17 +58,11 @@ class BearingData {
6158
return _data[i] / 100.0;
6259
}
6360

64-
float at_rad(unsigned int i) const {
65-
return deg2rad(at(i));
66-
}
61+
float at_rad(unsigned int i) const { return deg2rad(at(i)); }
6762

68-
float front() const {
69-
return _data[0] / 100.0;
70-
}
63+
float front() const { return _data[0] / 100.0; }
7164

72-
float back() const {
73-
return _data[_numBeams-1] / 100.0;
74-
}
65+
float back() const { return _data[_numBeams - 1] / 100.0; }
7566

7667
private:
7768
const int16_t *_data;

include/liboculus/Constants.h

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,79 +32,76 @@
3232

3333
#pragma once
3434

35+
#include <cmath>
3536
#include <cstddef> // for size_t
3637
#include <string>
3738
#include <vector>
38-
#include <cmath>
3939

4040
#include "Oculus/Oculus.h"
4141

4242
namespace liboculus {
43-
const uint16_t StatusBroadcastPort = 52102;
44-
const uint16_t DataPort = 52100;
43+
const uint16_t StatusBroadcastPort = 52102;
44+
const uint16_t DataPort = 52100;
4545

46-
const uint8_t PacketHeaderLSB = (OCULUS_CHECK_ID & 0x00FF);
47-
const uint8_t PacketHeaderMSB = (OCULUS_CHECK_ID & 0xFF00) >> 8;
46+
const uint8_t PacketHeaderLSB = (OCULUS_CHECK_ID & 0x00FF);
47+
const uint8_t PacketHeaderMSB = (OCULUS_CHECK_ID & 0xFF00) >> 8;
4848

49-
namespace Oculus_1200MHz {
50-
const float ElevationBeamwidthDeg = 20.0;
51-
const float ElevationBeamwidthRad = 20.0*M_PI/180.0;
49+
namespace Oculus_1200MHz {
50+
const float ElevationBeamwidthDeg = 20.0;
51+
const float ElevationBeamwidthRad = 20.0 * M_PI / 180.0;
5252

53-
const float AzimuthBeamwidthDeg = 0.6;
54-
const float AzimuthBeamwidthRad = 0.6*M_PI/180.0;
53+
const float AzimuthBeamwidthDeg = 0.6;
54+
const float AzimuthBeamwidthRad = 0.6 * M_PI / 180.0;
5555

56-
// NOTE(lindzey): According to the spec sheet, max range is 30 m
57-
// at 1.2 MHz on the M3000d, but 40 m on the M1200d.
58-
const float MaxRange = 40;
59-
};
56+
// NOTE(lindzey): According to the spec sheet, max range is 30 m
57+
// at 1.2 MHz on the M3000d, but 40 m on the M1200d.
58+
const float MaxRange = 40;
59+
}; // namespace Oculus_1200MHz
6060

61-
namespace Oculus_2100MHz {
62-
const float ElevationBeamwidthDeg = 12.0;
63-
const float ElevationBeamwidthRad = 12.0*M_PI/180.0;
61+
namespace Oculus_2100MHz {
62+
const float ElevationBeamwidthDeg = 12.0;
63+
const float ElevationBeamwidthRad = 12.0 * M_PI / 180.0;
6464

65-
const float AzimuthBeamwidthDeg = 0.4;
66-
const float AzimuthBeamwidthRad = 0.4*M_PI/180.0;
65+
const float AzimuthBeamwidthDeg = 0.4;
66+
const float AzimuthBeamwidthRad = 0.4 * M_PI / 180.0;
6767

68-
// \todo These shouldn't be fixed, should read from Oculus.h
69-
// But I don't feel like dealing with their data structure
70-
const float MaxRange = 10; // meters
71-
};
68+
// \todo These shouldn't be fixed, should read from Oculus.h
69+
// But I don't feel like dealing with their data structure
70+
const float MaxRange = 10; // meters
71+
}; // namespace Oculus_2100MHz
7272

73-
namespace Oculus_3000MHz {
74-
const float ElevationBeamwidthDeg = 20.0;
75-
const float ElevationBeamwidthRad = 20.0*M_PI/180.0;
73+
namespace Oculus_3000MHz {
74+
const float ElevationBeamwidthDeg = 20.0;
75+
const float ElevationBeamwidthRad = 20.0 * M_PI / 180.0;
7676

77-
const float AzimuthBeamwidthDeg = 0.4;
78-
const float AzimuthBeamwidthRad = 0.4*M_PI/180.0;
77+
const float AzimuthBeamwidthDeg = 0.4;
78+
const float AzimuthBeamwidthRad = 0.4 * M_PI / 180.0;
7979

80-
// \todo These shouldn't be fixed, should read from Oculus.h
81-
// But I don't feel like dealing with their data structure
82-
const float MaxRange = 5; // meters
83-
};
80+
// \todo These shouldn't be fixed, should read from Oculus.h
81+
// But I don't feel like dealing with their data structure
82+
const float MaxRange = 5; // meters
83+
}; // namespace Oculus_3000MHz
8484

8585
struct FlagBits {
8686
// bit 0: 0 = interpret range as percent, 1 = interpret range as meters
8787
// bit 1: 0 = 8 bit data, 1 = 16 bit data
8888
// bit 2: 0 = wont send gain, 1 = send gain
8989
// bit 3: 0 = send full return message, 1 = send simple return message
9090
// bit 4: "gain assistance"?
91-
// bit 6: use 512 beams (vs 256): email from Blueprint said to set flags |= 0x40
91+
// bit 6: use 512 beams (vs 256): email from Blueprint said to set flags |=
92+
// 0x40
9293

9394
static const uint8_t RangeAsMeters = (0x01) << 0;
94-
static const uint8_t Data16Bits = (0x01) << 1;
95-
static const uint8_t DoSendGain = (0x01) << 2;
96-
static const uint8_t SimpleReturn = (0x01) << 3;
95+
static const uint8_t Data16Bits = (0x01) << 1;
96+
static const uint8_t DoSendGain = (0x01) << 2;
97+
static const uint8_t SimpleReturn = (0x01) << 3;
9798
static const uint8_t GainAssistance = (0x01) << 4;
98-
static const uint8_t Do512Beams = (0x01) << 6;
99+
static const uint8_t Do512Beams = (0x01) << 6;
99100
};
100101

101-
// There doesn't appear to be an enum for the masterMode (like there is
102-
// for pingRate and dataSize), so creating our own to match comments in
103-
// liboculus/thirdparty/Oculus/Oculus.h.
104-
typedef enum {
105-
OCULUS_LOW_FREQ = 1,
106-
OCULUS_HIGH_FREQ = 2
107-
} OculusFreqMode;
108-
102+
// There doesn't appear to be an enum for the masterMode (like there is
103+
// for pingRate and dataSize), so creating our own to match comments in
104+
// liboculus/thirdparty/Oculus/Oculus.h.
105+
typedef enum { OCULUS_LOW_FREQ = 1, OCULUS_HIGH_FREQ = 2 } OculusFreqMode;
109106

110107
} // namespace liboculus

include/liboculus/DataRx.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030

3131
#pragma once
3232

33+
#include <memory>
3334
#include <string>
3435
#include <thread>
3536
#include <vector>
36-
#include <memory>
3737

3838
#include "liboculus/IoServiceThread.h"
39+
#include "liboculus/OculusMessageHandler.h"
3940
#include "liboculus/SimplePingResult.h"
4041
#include "liboculus/SonarConfiguration.h"
41-
#include "liboculus/OculusMessageHandler.h"
4242

4343
namespace liboculus {
4444

@@ -54,7 +54,7 @@ class DataRx : public OculusMessageHandler {
5454
void connect(const boost::asio::ip::address &addr);
5555
void connect(const std::string &strAddr);
5656

57-
typedef std::function< void() > OnConnectCallback;
57+
typedef std::function<void()> OnConnectCallback;
5858
void setOnConnectCallback(OnConnectCallback callback) {
5959
_onConnectCallback = callback;
6060
}
@@ -69,38 +69,36 @@ class DataRx : public OculusMessageHandler {
6969

7070
// Implement data read / data written hooks as virtual functions rather
7171
// rather than callbacks.
72-
virtual void haveWritten(const ByteVector &bytes) {;}
73-
virtual void haveRead(const ByteVector &bytes) {;}
72+
virtual void haveWritten(const ByteVector &bytes) { ; }
73+
virtual void haveRead(const ByteVector &bytes) { ; }
7474

7575
private:
76-
void onConnect(const boost::system::error_code& error);
76+
void onConnect(const boost::system::error_code &error);
7777

7878
// Initiates a network read.
7979
// Note this function reads until the **total number of bytes
8080
// in _buffer == bytes** The actual number of bytes requested
8181
// from the network depends on the size of _buffer at the start
8282
// of the function and is tpically less than bytes.
83-
typedef std::function<void(const boost::system::error_code&, std::size_t)> StateMachineCallback;
84-
void readUpTo(size_t bytes,
85-
StateMachineCallback callback);
83+
typedef std::function<void(const boost::system::error_code &, std::size_t)>
84+
StateMachineCallback;
85+
void readUpTo(size_t bytes, StateMachineCallback callback);
8686

8787
// This function is "reset the receive state machine"
8888
void restartReceiveCycle();
8989

9090
// All rx* functions are states in the receive state machine
91-
void rxFirstByteOculusId(const boost::system::error_code& ec,
92-
std::size_t bytes_transferred);
91+
void rxFirstByteOculusId(const boost::system::error_code &ec,
92+
std::size_t bytes_transferred);
9393

94-
void rxSecondByteOculusId(const boost::system::error_code& ec,
95-
std::size_t bytes_transferred);
96-
97-
void rxHeader(const boost::system::error_code& ec,
98-
std::size_t bytes_transferred);
99-
100-
void rxPacket(const boost::system::error_code& ec,
101-
std::size_t bytes_transferred);
94+
void rxSecondByteOculusId(const boost::system::error_code &ec,
95+
std::size_t bytes_transferred);
10296

97+
void rxHeader(const boost::system::error_code &ec,
98+
std::size_t bytes_transferred);
10399

100+
void rxPacket(const boost::system::error_code &ec,
101+
std::size_t bytes_transferred);
104102

105103
boost::asio::ip::tcp::socket _socket;
106104

@@ -110,7 +108,6 @@ class DataRx : public OculusMessageHandler {
110108

111109
}; // class DataRx
112110

113-
114111
template <typename FireMsg_t = OculusSimpleFireMessage2>
115112
void DataRx::sendSimpleFireMessage(const SonarConfiguration &config) {
116113
if (!isConnected()) {

0 commit comments

Comments
 (0)