Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
snhobbs committed Jul 11, 2024
1 parent 191ab13 commit 7bbd465
Show file tree
Hide file tree
Showing 72 changed files with 2,127 additions and 1,627 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ jobs:
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build

- name: SetupLibs
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: sudo apt-get install googletest && cd /usr/src/googletest && sudo cmake ./ && sudo make && sudo make install

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
Expand All @@ -50,6 +50,6 @@ jobs:
- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
72 changes: 72 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
exclude: '^docs/|/migrations/|devcontainer.json'
default_stages: [commit]

default_language_version:
python: python3.11

fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: detect-private-key

- repo: https://github.com/adamchainz/django-upgrade
rev: '1.16.0'
hooks:
- id: django-upgrade
args: ['--target-version', '4.2']

# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
# Linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
# Formatter
- id: ruff-format

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.34.1
hooks:
- id: djlint-reformat-django
- id: djlint-django

- repo: https://github.com/pre-commit/mirrors-mypy
rev: '' # Use the sha / tag you want to point at
hooks:
- id: mypy

- repo: https://github.com/pocc/pre-commit-hooks
rev: master
hooks:
- id: clang-format
args: [--style=Google, -i] # inline
- id: clang-tidy
args: [--fix, --fix-errors, --format-style=google]
#- id: oclint
#- id: uncrustify
# args: [-c "/home/simon/Argus/MWIRDetector/firmware/uncrustify_google_cpp_allman.cfg"]
- id: cppcheck
args: [--std=c++17, --language=c++]
- id: cpplint
args: [--headers=h]
#- id: include-what-you-use


# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
skip: []
submodules: false
1 change: 0 additions & 1 deletion ModbusBasicConfigVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ else()
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

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

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

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').
Expand Down
50 changes: 25 additions & 25 deletions documents/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ The protocol controller and controllers are fully put in a library.



# Protocol Controller
+ reads, writes passed through accessor
+ wether or not a access is valid is handled by accessor
# Protocol Controller
+ reads, writes passed through accessor
+ wether or not a access is valid is handled by accessor
+ Bytes come in, they should be passed consistantly to the reader, updating the state
+ Packet full, all data read
+ Check crc, reject send error response or continue
+ Find action and field type from packet header, if action is unsupported send error else continue
+ FieldType GetAddressSpaceFromFunction(Command)
+ validate access through accessor, send error or continue
+ Apply action through accessor
+ Calculate crc
+ send packet
+ Data is sent directly to uart, uart buffer should be large enough to handle the largest access
+ ReadStateMachine
+ Knows the type of packets, applies logic to know state
+ Read known header length till packet type
+ Request meta data length
+ read till meta data finished
+ Interfaces? Polymorphic handling
+ request data length
+ Packet full, all data read
+ Check crc, reject send error response or continue
+ Find action and field type from packet header, if action is unsupported send error else continue
+ FieldType GetAddressSpaceFromFunction(Command)
+ validate access through accessor, send error or continue
+ Apply action through accessor
+ Calculate crc
+ send packet
+ Data is sent directly to uart, uart buffer should be large enough to handle the largest access

+ ReadStateMachine
+ Knows the type of packets, applies logic to know state
+ Read known header length till packet type
+ Request meta data length
+ read till meta data finished
+ Interfaces? Polymorphic handling
+ request data length
+ Interface, needs to call something to process the packet.
+ read till data finished
+ dispatch
+ Crc Calculator
+ PacketReader
+ read till data finished
+ dispatch
+ Crc Calculator
+ PacketReader
+ Structure knowlege shared with ReadStateMachine, shared knowledge should be factored out
+ Interface to IO
+ Interface to IO
1 change: 0 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.metadata

87 changes: 48 additions & 39 deletions examples/ConnectedDevice/BasicRegisterMapping.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,75 @@
import copy
from jinja2 import Template, Environment, FileSystemLoader
from modbus_generator import MapEntry, DataType, FunctionType, SetAddresses, Slave, WindLDREntry, MakeWindLDRConfig, MapEntry, ModbusRegister
from modbus_generator import (
DataType,
FunctionType,
SetAddresses,
MapEntry,
ModbusRegister,
)
import modbus_generator
import sys

input_registers = (
ModbusRegister('version', DataType.kString, 64, FunctionType.kInput),
ModbusRegister('firmware_version', DataType.kString, 64, FunctionType.kInput),
ModbusRegister('compile_date', DataType.kString, 64, FunctionType.kInput),
ModbusRegister('compile_time', DataType.kString, 64, FunctionType.kInput),
ModbusRegister('serial_number', DataType.kString, 40, FunctionType.kInput),

ModbusRegister('fault_status', DataType.uint16_t, 1, FunctionType.kInput),

ModbusRegister('p5_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister('p5_reading', DataType.uint32_t, 1, FunctionType.kInput),

ModbusRegister('p23_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister('p23_reading', DataType.uint32_t, 1, FunctionType.kInput),

ModbusRegister('vlo_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister('vlo_reading', DataType.uint32_t, 1, FunctionType.kInput),

ModbusRegister('thermistor_temp_spi', DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister('thermistor_temp_mcu', DataType.int32_t, 1, FunctionType.kInput),

ModbusRegister('data_frequency', DataType.uint32_t, 1, FunctionType.kInput),

ModbusRegister('p3_3_micro_volts', DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister('p3_3_reading', DataType.uint32_t, 1, FunctionType.kInput),
ModbusRegister("version", DataType.kString, 64, FunctionType.kInput),
ModbusRegister("firmware_version", DataType.kString, 64, FunctionType.kInput),
ModbusRegister("compile_date", DataType.kString, 64, FunctionType.kInput),
ModbusRegister("compile_time", DataType.kString, 64, FunctionType.kInput),
ModbusRegister("serial_number", DataType.kString, 40, FunctionType.kInput),
ModbusRegister("fault_status", DataType.uint16_t, 1, FunctionType.kInput),
ModbusRegister("p5_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("p5_reading", DataType.uint32_t, 1, FunctionType.kInput),
ModbusRegister("p23_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("p23_reading", DataType.uint32_t, 1, FunctionType.kInput),
ModbusRegister("vlo_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("vlo_reading", DataType.uint32_t, 1, FunctionType.kInput),
ModbusRegister("thermistor_temp_spi", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("thermistor_temp_mcu", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("data_frequency", DataType.uint32_t, 1, FunctionType.kInput),
ModbusRegister("p3_3_micro_volts", DataType.int32_t, 1, FunctionType.kInput),
ModbusRegister("p3_3_reading", DataType.uint32_t, 1, FunctionType.kInput),
)

holding_registers = (
ModbusRegister('analog_output0', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister('analog_output1', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister('isp_mode', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister('slave_address_unlock', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister('slave_address', DataType.uint16_t, 1, FunctionType.kHolding),
ModbusRegister('clear_faults', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister('start_data_read', DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("analog_output0", DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("analog_output1", DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("isp_mode", DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("slave_address_unlock", DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("slave_address", DataType.uint16_t, 1, FunctionType.kHolding),
ModbusRegister("clear_faults", DataType.uint32_t, 1, FunctionType.kHolding),
ModbusRegister("start_data_read", DataType.uint32_t, 1, FunctionType.kHolding),
)


def GetInputRegisterMapEntries():
InputRegisterMapEntries = [MapEntry(register=pt) for pt in input_registers]
SetAddresses(InputRegisterMapEntries)
return InputRegisterMapEntries


def GetHoldingRegisterMapEntries():
HoldingRegisterMapEntries = [MapEntry(register=pt) for pt in holding_registers]
SetAddresses(HoldingRegisterMapEntries)
return HoldingRegisterMapEntries


if __name__ == "__main__":
modbus_generator.MakeHeader(GetHoldingRegisterMapEntries(), "HoldingRegisterMappedDataStore.h", name="HoldingRegisters")
modbus_generator.MakeHeader(GetInputRegisterMapEntries(), "InputRegisterMappedDataStore.h", name="InputRegisters")
modbus_generator.MakeHeader(
GetHoldingRegisterMapEntries(),
"HoldingRegisterMappedDataStore.h",
name="HoldingRegisters",
)
modbus_generator.MakeHeader(
GetInputRegisterMapEntries(),
"InputRegisterMappedDataStore.h",
name="InputRegisters",
)

modbus_generator.MakeLibModbusTest(
input_registers=GetInputRegisterMapEntries(),
holding_registers=GetHoldingRegisterMapEntries(),
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"])
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"],
)

modbus_generator.MakePyModbusTest(
input_registers=GetInputRegisterMapEntries(),
holding_registers=GetHoldingRegisterMapEntries(),
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"])
includes=["HoldingRegisterMappedDataStore.h", "InputRegisterMappedDataStore.h"],
)
Loading

0 comments on commit 7bbd465

Please sign in to comment.