Skip to content

Commit 7bbd465

Browse files
committed
formatting
1 parent 191ab13 commit 7bbd465

File tree

72 files changed

+2127
-1627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2127
-1627
lines changed

.github/workflows/cmake.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ jobs:
2424
# Some projects don't allow in-source building, so create a separate build directory
2525
# We'll use this as our working directory for all subsequent commands
2626
run: cmake -E make_directory ${{runner.workspace}}/build
27-
27+
2828
- name: SetupLibs
2929
working-directory: ${{runner.workspace}}/build
3030
shell: bash
3131
# Execute the build. You can specify a specific target with "--target <NAME>"
3232
run: sudo apt-get install googletest && cd /usr/src/googletest && sudo cmake ./ && sudo make && sudo make install
33-
33+
3434
- name: Configure CMake
3535
# Use a bash shell so we can use the same syntax for environment variable
3636
# access regardless of the host operating system
3737
shell: bash
3838
working-directory: ${{runner.workspace}}/build
39-
# Note the current convention is to use the -S and -B options here to specify source
40-
# and build directories, but this is only available with CMake 3.13 and higher.
39+
# Note the current convention is to use the -S and -B options here to specify source
40+
# and build directories, but this is only available with CMake 3.13 and higher.
4141
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
4242
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
43-
43+
4444
- name: Build
4545
working-directory: ${{runner.workspace}}/build
4646
shell: bash
@@ -50,6 +50,6 @@ jobs:
5050
- name: Test
5151
working-directory: ${{runner.workspace}}/build
5252
shell: bash
53-
# Execute tests defined by the CMake configuration.
53+
# Execute tests defined by the CMake configuration.
5454
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
5555
run: ctest -C $BUILD_TYPE

.pre-commit-config.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
exclude: '^docs/|/migrations/|devcontainer.json'
2+
default_stages: [commit]
3+
4+
default_language_version:
5+
python: python3.11
6+
7+
fail_fast: false
8+
repos:
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v4.5.0
11+
hooks:
12+
- id: trailing-whitespace
13+
- id: end-of-file-fixer
14+
- id: check-json
15+
- id: check-toml
16+
- id: check-xml
17+
- id: check-yaml
18+
- id: debug-statements
19+
- id: check-builtin-literals
20+
- id: check-case-conflict
21+
- id: check-docstring-first
22+
- id: detect-private-key
23+
24+
- repo: https://github.com/adamchainz/django-upgrade
25+
rev: '1.16.0'
26+
hooks:
27+
- id: django-upgrade
28+
args: ['--target-version', '4.2']
29+
30+
# Run the Ruff linter.
31+
- repo: https://github.com/astral-sh/ruff-pre-commit
32+
rev: v0.3.2
33+
hooks:
34+
# Linter
35+
- id: ruff
36+
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
37+
# Formatter
38+
- id: ruff-format
39+
40+
- repo: https://github.com/Riverside-Healthcare/djLint
41+
rev: v1.34.1
42+
hooks:
43+
- id: djlint-reformat-django
44+
- id: djlint-django
45+
46+
- repo: https://github.com/pre-commit/mirrors-mypy
47+
rev: '' # Use the sha / tag you want to point at
48+
hooks:
49+
- id: mypy
50+
51+
- repo: https://github.com/pocc/pre-commit-hooks
52+
rev: master
53+
hooks:
54+
- id: clang-format
55+
args: [--style=Google, -i] # inline
56+
- id: clang-tidy
57+
args: [--fix, --fix-errors, --format-style=google]
58+
#- id: oclint
59+
#- id: uncrustify
60+
# args: [-c "/home/simon/Argus/MWIRDetector/firmware/uncrustify_google_cpp_allman.cfg"]
61+
- id: cppcheck
62+
args: [--std=c++17, --language=c++]
63+
- id: cpplint
64+
args: [--headers=h]
65+
#- id: include-what-you-use
66+
67+
68+
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
69+
ci:
70+
autoupdate_schedule: weekly
71+
skip: []
72+
submodules: false

ModbusBasicConfigVersion.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ else()
99
set(PACKAGE_VERSION_EXACT TRUE)
1010
endif()
1111
endif()
12-

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ using InputRegisterController =
3737
1. Subclass of ProtocolRtuSlave.
3838
- Timeouts
3939
- When to process packets
40-
- IO device control, this layer puts the recieved characters
40+
- IO device control, this layer puts the recieved characters
4141
into the protocol and transmitting the generated responses
4242
2. Data Stores
43-
- The holding registers, coils, discrete inputs, and input registers are
44-
generalized as data stores. The default store mechanism can be used where
43+
- The holding registers, coils, discrete inputs, and input registers are
44+
generalized as data stores. The default store mechanism can be used where
4545
the data store is literal, i.e. all bits and registers are stored
4646
and accessed directly. Other data stores might define a memory map
4747
that accesses system variables. This will lower memory use and remove the
@@ -53,7 +53,7 @@ using InputRegisterController =
5353
connection. A bidirectional pipe is setup allowing two processes
5454
to see the pipe as if it was an attached serial device.
5555

56-
**Use** :
56+
**Use** :
5757
socat -d -d -d -x PTY,link=/tmp/ptyp0,raw,echo=0,ispeed=b9600 PTY,link=/tmp/ttyp0,raw,echo=0,ospeed=b9600
5858

5959
In this example the pipes are setup at /tmp/ptyp0 and /tmp/ttyp0 running at 9600 baud with some debug info (level set by the number of '-d').

documents/design.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ The protocol controller and controllers are fully put in a library.
6969

7070

7171

72-
# Protocol Controller
73-
+ reads, writes passed through accessor
74-
+ wether or not a access is valid is handled by accessor
72+
# Protocol Controller
73+
+ reads, writes passed through accessor
74+
+ wether or not a access is valid is handled by accessor
7575
+ Bytes come in, they should be passed consistantly to the reader, updating the state
76-
+ Packet full, all data read
77-
+ Check crc, reject send error response or continue
78-
+ Find action and field type from packet header, if action is unsupported send error else continue
79-
+ FieldType GetAddressSpaceFromFunction(Command)
80-
+ validate access through accessor, send error or continue
81-
+ Apply action through accessor
82-
+ Calculate crc
83-
+ send packet
84-
+ Data is sent directly to uart, uart buffer should be large enough to handle the largest access
85-
86-
+ ReadStateMachine
87-
+ Knows the type of packets, applies logic to know state
88-
+ Read known header length till packet type
89-
+ Request meta data length
90-
+ read till meta data finished
91-
+ Interfaces? Polymorphic handling
92-
+ request data length
76+
+ Packet full, all data read
77+
+ Check crc, reject send error response or continue
78+
+ Find action and field type from packet header, if action is unsupported send error else continue
79+
+ FieldType GetAddressSpaceFromFunction(Command)
80+
+ validate access through accessor, send error or continue
81+
+ Apply action through accessor
82+
+ Calculate crc
83+
+ send packet
84+
+ Data is sent directly to uart, uart buffer should be large enough to handle the largest access
85+
86+
+ ReadStateMachine
87+
+ Knows the type of packets, applies logic to know state
88+
+ Read known header length till packet type
89+
+ Request meta data length
90+
+ read till meta data finished
91+
+ Interfaces? Polymorphic handling
92+
+ request data length
9393
+ Interface, needs to call something to process the packet.
94-
+ read till data finished
95-
+ dispatch
96-
+ Crc Calculator
97-
+ PacketReader
94+
+ read till data finished
95+
+ dispatch
96+
+ Crc Calculator
97+
+ PacketReader
9898
+ Structure knowlege shared with ReadStateMachine, shared knowledge should be factored out
99-
+ Interface to IO
99+
+ Interface to IO

examples/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
.metadata
2-
Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,75 @@
1-
import copy
2-
from jinja2 import Template, Environment, FileSystemLoader
3-
from modbus_generator import MapEntry, DataType, FunctionType, SetAddresses, Slave, WindLDREntry, MakeWindLDRConfig, MapEntry, ModbusRegister
1+
from modbus_generator import (
2+
DataType,
3+
FunctionType,
4+
SetAddresses,
5+
MapEntry,
6+
ModbusRegister,
7+
)
48
import modbus_generator
5-
import sys
69

710
input_registers = (
8-
ModbusRegister('version', DataType.kString, 64, FunctionType.kInput),
9-
ModbusRegister('firmware_version', DataType.kString, 64, FunctionType.kInput),
10-
ModbusRegister('compile_date', DataType.kString, 64, FunctionType.kInput),
11-
ModbusRegister('compile_time', DataType.kString, 64, FunctionType.kInput),
12-
ModbusRegister('serial_number', DataType.kString, 40, FunctionType.kInput),
13-
14-
ModbusRegister('fault_status', DataType.uint16_t, 1, FunctionType.kInput),
15-
16-
ModbusRegister('p5_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
17-
ModbusRegister('p5_reading', DataType.uint32_t, 1, FunctionType.kInput),
18-
19-
ModbusRegister('p23_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
20-
ModbusRegister('p23_reading', DataType.uint32_t, 1, FunctionType.kInput),
21-
22-
ModbusRegister('vlo_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
23-
ModbusRegister('vlo_reading', DataType.uint32_t, 1, FunctionType.kInput),
24-
25-
ModbusRegister('thermistor_temp_spi', DataType.int32_t, 1, FunctionType.kInput),
26-
ModbusRegister('thermistor_temp_mcu', DataType.int32_t, 1, FunctionType.kInput),
27-
28-
ModbusRegister('data_frequency', DataType.uint32_t, 1, FunctionType.kInput),
29-
30-
ModbusRegister('p3_3_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
31-
ModbusRegister('p3_3_reading', DataType.uint32_t, 1, FunctionType.kInput),
11+
ModbusRegister("version", DataType.kString, 64, FunctionType.kInput),
12+
ModbusRegister("firmware_version", DataType.kString, 64, FunctionType.kInput),
13+
ModbusRegister("compile_date", DataType.kString, 64, FunctionType.kInput),
14+
ModbusRegister("compile_time", DataType.kString, 64, FunctionType.kInput),
15+
ModbusRegister("serial_number", DataType.kString, 40, FunctionType.kInput),
16+
ModbusRegister("fault_status", DataType.uint16_t, 1, FunctionType.kInput),
17+
ModbusRegister("p5_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
18+
ModbusRegister("p5_reading", DataType.uint32_t, 1, FunctionType.kInput),
19+
ModbusRegister("p23_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
20+
ModbusRegister("p23_reading", DataType.uint32_t, 1, FunctionType.kInput),
21+
ModbusRegister("vlo_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
22+
ModbusRegister("vlo_reading", DataType.uint32_t, 1, FunctionType.kInput),
23+
ModbusRegister("thermistor_temp_spi", DataType.int32_t, 1, FunctionType.kInput),
24+
ModbusRegister("thermistor_temp_mcu", DataType.int32_t, 1, FunctionType.kInput),
25+
ModbusRegister("data_frequency", DataType.uint32_t, 1, FunctionType.kInput),
26+
ModbusRegister("p3_3_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
27+
ModbusRegister("p3_3_reading", DataType.uint32_t, 1, FunctionType.kInput),
3228
)
3329

3430
holding_registers = (
35-
ModbusRegister('analog_output0', DataType.uint32_t, 1, FunctionType.kHolding),
36-
ModbusRegister('analog_output1', DataType.uint32_t, 1, FunctionType.kHolding),
37-
ModbusRegister('isp_mode', DataType.uint32_t, 1, FunctionType.kHolding),
38-
ModbusRegister('slave_address_unlock', DataType.uint32_t, 1, FunctionType.kHolding),
39-
ModbusRegister('slave_address', DataType.uint16_t, 1, FunctionType.kHolding),
40-
ModbusRegister('clear_faults', DataType.uint32_t, 1, FunctionType.kHolding),
41-
ModbusRegister('start_data_read', DataType.uint32_t, 1, FunctionType.kHolding),
31+
ModbusRegister("analog_output0", DataType.uint32_t, 1, FunctionType.kHolding),
32+
ModbusRegister("analog_output1", DataType.uint32_t, 1, FunctionType.kHolding),
33+
ModbusRegister("isp_mode", DataType.uint32_t, 1, FunctionType.kHolding),
34+
ModbusRegister("slave_address_unlock", DataType.uint32_t, 1, FunctionType.kHolding),
35+
ModbusRegister("slave_address", DataType.uint16_t, 1, FunctionType.kHolding),
36+
ModbusRegister("clear_faults", DataType.uint32_t, 1, FunctionType.kHolding),
37+
ModbusRegister("start_data_read", DataType.uint32_t, 1, FunctionType.kHolding),
4238
)
4339

40+
4441
def GetInputRegisterMapEntries():
4542
InputRegisterMapEntries = [MapEntry(register=pt) for pt in input_registers]
4643
SetAddresses(InputRegisterMapEntries)
4744
return InputRegisterMapEntries
4845

46+
4947
def GetHoldingRegisterMapEntries():
5048
HoldingRegisterMapEntries = [MapEntry(register=pt) for pt in holding_registers]
5149
SetAddresses(HoldingRegisterMapEntries)
5250
return HoldingRegisterMapEntries
5351

52+
5453
if __name__ == "__main__":
55-
modbus_generator.MakeHeader(GetHoldingRegisterMapEntries(), "HoldingRegisterMappedDataStore.h", name="HoldingRegisters")
56-
modbus_generator.MakeHeader(GetInputRegisterMapEntries(), "InputRegisterMappedDataStore.h", name="InputRegisters")
54+
modbus_generator.MakeHeader(
55+
GetHoldingRegisterMapEntries(),
56+
"HoldingRegisterMappedDataStore.h",
57+
name="HoldingRegisters",
58+
)
59+
modbus_generator.MakeHeader(
60+
GetInputRegisterMapEntries(),
61+
"InputRegisterMappedDataStore.h",
62+
name="InputRegisters",
63+
)
5764

5865
modbus_generator.MakeLibModbusTest(
5966
input_registers=GetInputRegisterMapEntries(),
6067
holding_registers=GetHoldingRegisterMapEntries(),
61-
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"])
68+
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"],
69+
)
6270

6371
modbus_generator.MakePyModbusTest(
6472
input_registers=GetInputRegisterMapEntries(),
6573
holding_registers=GetHoldingRegisterMapEntries(),
66-
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"])
74+
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"],
75+
)

0 commit comments

Comments
 (0)