Skip to content

Commit

Permalink
Merge 1e5a796 into ea11da8
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics authored Jan 2, 2023
2 parents ea11da8 + 1e5a796 commit 6e795f7
Show file tree
Hide file tree
Showing 22 changed files with 1,681 additions and 599 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ jobs:
- name: Run Client/Host TCP test
run: |
docker compose -f docker-compose-tcp-test.yaml up --build --exit-code-from micropython-host
- name: Run Client/Host RTU example
run: |
docker compose -f docker-compose-rtu.yaml up --build --exit-code-from micropython-host
- name: Run Client/Host RTU test
run: |
docker compose -f docker-compose-rtu-test.yaml up --build --exit-code-from micropython-host
- name: Build package
run: |
changelog2version \
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.client_rtu
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build image
# $ docker build -t micropython-client-rtu -f Dockerfile.client_rtu .
#
# Run image
# $ docker run -it --rm --name micropython-client-rtu micropython-client-rtu

FROM micropython/unix:v1.18

# use "volumes" in docker-compose file to remove need of rebuilding
# COPY ./ /home
# COPY umodbus /root/.micropython/lib/umodbus

RUN micropython-dev -m upip install micropython-ulogging

CMD [ "micropython-dev", "-m", "examples/rtu_client_example.py" ]
4 changes: 2 additions & 2 deletions Dockerfile.client → Dockerfile.client_tcp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build image
# $ docker build -t micropython-client -f Dockerfile.client .
# $ docker build -t micropython-client-tcp -f Dockerfile.client_tcp .
#
# Run image
# $ docker run -it --rm --name micropython-client micropython-client
# $ docker run -it --rm --name micropython-client-tcp micropython-client-tcp

FROM micropython/unix:v1.18

Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.host_rtu
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build image
# $ docker build -t micropython-host-rtu -f Dockerfile.host_rtu .
#
# Run image
# $ docker run -it --rm --name micropython-host-rtu micropython-host-rtu

FROM micropython/unix:v1.18

# use "volumes" in docker-compose file to remove need of rebuilding
# COPY ./ /home
# COPY umodbus /root/.micropython/lib/umodbus

RUN micropython-dev -m upip install micropython-ulogging

CMD [ "micropython-dev", "-m", "examples/rtu_host_example.py" ]
4 changes: 2 additions & 2 deletions Dockerfile.host → Dockerfile.host_tcp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build image
# $ docker build -t micropython-host -f Dockerfile.host .
# $ docker build -t micropython-host-tcp -f Dockerfile.host_tcp .
#
# Run image
# $ docker run -it --rm --name micropython-host micropython-host
# $ docker run -it --rm --name micropython-host-tcp micropython-host-tcp

FROM micropython/unix:v1.18

Expand Down
File renamed without changes.
32 changes: 31 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- ## [Unreleased] -->

## Released
## [2.2.0] - 2023-01-03
### Added
- [Fake machine module](fakes/machine.py) with UART and Pin class to be used on Unix MicroPython container for RTU tests and examples, see #47
- [RTU host example script](examples/rtu_host_example.py)
- [RTU docker compose file](docker-compose-rtu.yaml) and [RTU docker compose file test](docker-compose-rtu-test.yaml) based in MicroPython 1.18 image
- [RTU client Dockerfile](Dockerfile.client_rtu) and [RTU host Dockerfile](Dockerfile.host_rtu) based on MicroPython 1.18 image
- Initial [RTU examples unittest](tests/test_rtu_example.py)
- RTU example section for Client and Host in USAGE

### Changed
- Outsourced the following common functions of [serial.py](umodbus/serial.py) and [tcp.py](umodbus/tcp.py) into `CommonModbusFunctions` of [common.py](umodbus/common.py):
- `read_coils`
- `read_discrete_inputs`
- `read_holding_registers`
- `read_input_registers`
- `write_single_coil`
- `write_single_register`
- `write_multiple_coils`
- `write_multiple_registers`

- Inherit from `CommonModbusFunctions` in `Serial` of [serial.py](umodbus/serial.py) and in `TCP` of of [tcp.py](umodbus/tcp.py)
- Extended RTU client example for Docker usage to load all registers from example JSON file
- Update internal functions parameter name from `slave_id` to `slave_addr` of TCP's `_create_mbap_hdr` and `_validate_resp_hdr` function to be the same as in Serial
- Update Modbus function documentation from TCP specific to common module in USAGE file
- Renamed docker files:
- `Dockerfile.client` -> `Dockerfile.client_tcp`
- `Dockerfile.host` -> `Dockerfile.host_tcp`
- `Dockerfile.test_tcp_example` -> `Dockerfile.test_examples`

## [2.1.3] - 2022-12-30
### Fixed
- `uart_id` can be specified during init of `ModbusRTU` and `Serial` class and is no longer hardcoded to `1`, but set as `1` by default to ensure backwards compability, see #7 and #43
Expand Down Expand Up @@ -195,8 +224,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus)

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.1.3...develop
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.2.0...develop

[2.2.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.2.0
[2.1.3]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.3
[2.1.2]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.2
[2.1.1]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.1
Expand Down
64 changes: 64 additions & 0 deletions docker-compose-rtu-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# build all non-image containers
# $ docker-compose -f docker-compose-rtu-test.yaml build
# can be combined into one command to also start it afterwards
# $ docker-compose -f docker-compose-rtu-test.yaml up --build
#

version: "3.8"

services:
micropython-client:
build:
context: .
dockerfile: Dockerfile.client_rtu
container_name: micropython-client
volumes:
- ./:/home
- ./registers:/home/registers
- ./umodbus:/root/.micropython/lib/umodbus
- ./fakes:/usr/lib/micropython
expose:
- "65433"
ports:
- "65433:65433" # reach "micropython-client" at 172.25.0.2:65433, see networks
networks:
serial_bridge:
# fix IPv4 address to be known and in the MicroPython scripts
# https://docs.docker.com/compose/compose-file/#ipv4_address
ipv4_address: 172.25.0.2

micropython-host:
build:
context: .
dockerfile: Dockerfile.test_examples
container_name: micropython-host
volumes:
- ./:/home
- ./umodbus:/root/.micropython/lib/umodbus
- ./fakes:/usr/lib/micropython
- ./mpy_unittest.py:/root/.micropython/lib/mpy_unittest.py
depends_on:
- micropython-client
command:
- /bin/bash
- -c
- |
micropython-dev -c "import mpy_unittest as unittest; unittest.main(name='tests.test_rtu_example', fromlist=['TestRtuExample'])"
networks:
serial_bridge:
# fix IPv4 address to be known and in the MicroPython scripts
# https://docs.docker.com/compose/compose-file/#ipv4_address
ipv4_address: 172.25.0.3

networks:
serial_bridge:
# use "external: true" if the network already exists
# check available networks with "docker network ls"
# external: true
driver: bridge
# https://docs.docker.com/compose/compose-file/#ipam
ipam:
config:
- subnet: 172.25.0.0/16
gateway: 172.25.0.1
57 changes: 57 additions & 0 deletions docker-compose-rtu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# build all non-image containers
# $ docker-compose build
# can be combined into one command to also start it afterwards
# $ docker-compose up --build
#

version: "3.8"

services:
micropython-client:
build:
context: .
dockerfile: Dockerfile.client_rtu
container_name: micropython-client
volumes:
- ./:/home
- ./umodbus:/root/.micropython/lib/umodbus
- ./fakes:/usr/lib/micropython
expose:
- "65433"
ports:
- "65433:65433" # reach "micropython-client" at 172.25.0.2:65433, see networks
networks:
serial_bridge:
# fix IPv4 address to be known and in the MicroPython scripts
# https://docs.docker.com/compose/compose-file/#ipv4_address
ipv4_address: 172.25.0.2

micropython-host:
build:
context: .
dockerfile: Dockerfile.host_rtu
container_name: micropython-host
volumes:
- ./:/home
- ./umodbus:/root/.micropython/lib/umodbus
- ./fakes:/usr/lib/micropython
depends_on:
- micropython-client
networks:
serial_bridge:
# fix IPv4 address to be known and in the MicroPython scripts
# https://docs.docker.com/compose/compose-file/#ipv4_address
ipv4_address: 172.25.0.3

networks:
serial_bridge:
# use "external: true" if the network already exists
# check available networks with "docker network ls"
# external: true
driver: bridge
# https://docs.docker.com/compose/compose-file/#ipam
ipam:
config:
- subnet: 172.25.0.0/16
gateway: 172.25.0.1
4 changes: 2 additions & 2 deletions docker-compose-tcp-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
micropython-client:
build:
context: .
dockerfile: Dockerfile.client
dockerfile: Dockerfile.client_tcp
container_name: micropython-client
volumes:
- ./:/home
Expand All @@ -30,7 +30,7 @@ services:
micropython-host:
build:
context: .
dockerfile: Dockerfile.test_tcp_example
dockerfile: Dockerfile.test_examples
container_name: micropython-host
volumes:
- ./:/home
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
micropython-client:
build:
context: .
dockerfile: Dockerfile.client
dockerfile: Dockerfile.client_tcp
container_name: micropython-client
volumes:
- ./:/home
Expand All @@ -29,7 +29,7 @@ services:
micropython-host:
build:
context: .
dockerfile: Dockerfile.host
dockerfile: Dockerfile.host_tcp
container_name: micropython-host
volumes:
- ./:/home
Expand Down
Loading

0 comments on commit 6e795f7

Please sign in to comment.